Composite traffic model: Difference between revisions

From Opasnet
Jump to navigation Jump to search
mNo edit summary
(→‎R model: vehicle kilometers and a part of costs added to model)
Line 173: Line 173:


ggplot(test, aes(x = Time, y = Result, fill = Type)) + geom_area()
ggplot(test, aes(x = Time, y = Result, fill = Type)) + geom_area()
# Vehicle kilometers
d8 <- tapply(trips.out$d8, trips.out[,c("From","To")], sum)
d4 <- tapply(trips.out$d4, trips.out[,c("From","To")], sum)
d3 <- tapply(trips.out$d3, trips.out[,c("From","To")], sum)
d2 <- tapply(trips.out$d2, trips.out[,c("From","To")], sum)
d1 <- tapply(trips.out$d1, trips.out[,c("From","To")], sum)
c8 <- tapply(trips.out$c8, trips.out[,c("From","To")], sum)
c4 <- tapply(trips.out$c4, trips.out[,c("From","To")], sum)
c3 <- tapply(trips.out$c3, trips.out[,c("From","To")], sum)
c2 <- tapply(trips.out$c2, trips.out[,c("From","To")], sum)
c1 <- tapply(trips.out$c1, trips.out[,c("From","To")], sum)
n.full.8.cars <- as.data.frame(as.table((d8 + c8) / 8))
n.full.4.cars <- as.data.frame(as.table((d4 + c4) / 4))
n.4.cars.3.pas <- as.data.frame(as.table((d3 + c3) / 3))
n.4.cars.2.pas <- as.data.frame(as.table((d2 + c2) / 2))
n.4.cars.1.pas <- as.data.frame(as.table(d1 + c1))
colnames(n.full.8.cars)[3] <- "n.full.8.cars"
colnames(n.full.4.cars)[3] <- "n.full.4.cars"
colnames(n.4.cars.3.pas)[3] <- "n.4.cars.3.pas"
colnames(n.4.cars.2.pas)[3] <- "n.4.cars.2.pas"
colnames(n.4.cars.1.pas)[3] <- "n.4.cars.1.pas"
test2 <- merge(n.full.8.cars, n.full.4.cars)
test2 <- merge(test2, n.4.cars.3.pas)
test2 <- merge(test2, n.4.cars.2.pas)
test2 <- merge(test2, n.4.cars.1.pas)
library(reshape)
test2 <- melt(test2, id.vars = c("From","To"), variable_name = "Type")
test2 <- merge(test2, distance[,c("From", "To", "Result")])
colnames(test2)[5] <- "Distance"
test2$vehicle.kilometers <- test2$value * test2$Distance
# Costs
test3 <- as.data.frame(as.table(tapply(test2$vehicle.kilometers, test2$Type, sum)))
colnames(test3) <- c("Type", "vehicle.kilometers")
fuel.cons.emis.CO2 <- data.frame(Type = c("n.full.8.cars", "n.full.4.cars", "n.4.cars.3.pas", "n.4.cars.2.pas", "n.4.cars.1.pas"),
Consumption = c(8.7, 5.7, 5.7, 5.7, 5.7), Emis.factor.CO2 = c(232, 153, 153, 153, 153))
emis.factor.PM <- 0.1 # gkm^-1
fuel.price <- 1.374 # 4.8. average cost of a liter of diesel fuel in Finland
maint.price <- 0.0582 # €km^-1
driver.salary <- 2313 / 160 * 1.35 # €h^-1
test3 <- merge(test3, fuel.cons.emis.CO2)
test3$Fuel.cost <- test3$vehicle.kilometers * test3$Consumption * fuel.price
test3$Maint.cost <- test3$vehicle.kilometers * maint.price
test3$Emis.CO2 <- test3$vehicle.kilometers * test3$Emis.factor.CO2
test3$Emis.PM <- test3$vehicle.kilometers * emis.factor.PM
test3$Driver.cost <- test3$vehicle.kilometers / speed * driver.salary
emis.cost.PM <- 201.879 # €kg^-1
test3


</rcode>
</rcode>
Line 179: Line 248:


{{comment|# |Takes below 10 minutes to run. Neat!|--[[User:Teemu R|Teemu R]] 14:08, 2 August 2011 (EEST)}}
{{comment|# |Takes below 10 minutes to run. Neat!|--[[User:Teemu R|Teemu R]] 14:08, 2 August 2011 (EEST)}}
:{{comment|# |Though not on the serverside R...|--[[User:Teemu R|Teemu R]] 14:26, 2 August 2011 (EEST)}}
:{{comment|# |Though much slower on the serverside R...|--[[User:Teemu R|Teemu R]] 14:26, 2 August 2011 (EEST)}}

Revision as of 12:42, 5 August 2011



This page is about a composite traffic model that is an updated version of File:Composite traffic.ANA. The new version is coded with R.

Definition

Variables

R model

  • Trip aggregator
    • Optimization rules:
  1. No second transfer -> prioritize "secondary" passengers
  2. Fill as many 8-person-vehicles as possible
  3. Fill as many 4-person-vehicles as possible
  4. Special rule: for trips with no possible transfer-point -> direct trip
  5. Transfer the rest (will always be 4-person-vehicles)
  6. Re-check vehicle configurations, when exact numbers of primary and secondary passengers as well as transferees are known

+ Show code

TODO: {{#todo:Ruvetaan keräämään tälle sivulle matskua mallin uudesta versiosta.|Smxb|}}


----#: . Takes below 10 minutes to run. Neat! --Teemu R 14:08, 2 August 2011 (EEST) (type: truth; paradigms: science: comment)

----#: . Though much slower on the serverside R... --Teemu R 14:26, 2 August 2011 (EEST) (type: truth; paradigms: science: comment)