Skip to content

Commit

Permalink
update counts opt for multi mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Dec 23, 2023
1 parent 792b06d commit ff32cff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,15 @@ eval-opt: $p/berlin-initial-$V-25pct.experienced_plans.xml.gz
--output $p/berlin-$V-25pct.plans_$(ERROR_METRIC).xml.gz

$(sc) run --mode "routeChoice" --iterations 20 --all-car --output "output/eval-$(ERROR_METRIC)" --25pct --population "berlin-$V-25pct.plans_$(ERROR_METRIC).xml.gz"\
--config $p/berlin-$V-base-calib.config.xml
--config $p/berlin-$V.config.xml


# TODO: these needs to be renamed to plans-initial, because they are uncalibrated at this stage
# These depend on the output of optimization runs
$p/berlin-$V-25pct.plans.xml.gz: $p/berlin-$V-facilities.xml.gz $p/berlin-$V-network.xml.gz $p/berlin-goodsTraffic-$V-25pct.plans.xml.gz $p/berlin-longHaulFreight-$V-25pct.plans.xml.gz
$p/berlin-$V-25pct.plans.xml.gz: $p/berlin-$V-facilities.xml.gz $p/berlin-$V-network.xml.gz $p/berlin-longHaulFreight-$V-25pct.plans.xml.gz
$(sc) prepare filter-relevant-agents\
--input $p/berlin-$V-25pct.plans_log_error.xml.gz --output $@\
--shp input/v6.0/area/area.shp\
--shp input/$V/area/area.shp\
--facilities $<\
--network $(word 2,$^)

Expand All @@ -271,7 +271,7 @@ $p/berlin-$V-25pct.plans.xml.gz: $p/berlin-$V-facilities.xml.gz $p/berlin-$V-net

$(sc) prepare fix-subtour-modes --input $@ --output $@ --coord-dist 100

$(sc) prepare merge-populations $@ $(word 3,$^) $(word 4,$^)\
$(sc) prepare merge-populations $@ $(word 3,$^)\
--output $@

$(sc) prepare downsample-population $@\
Expand Down
19 changes: 14 additions & 5 deletions src/main/java/org/matsim/prepare/opt/RunCountOptimization.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,24 @@ private List<PlanPerson> processPopulation(Path input, Network network, Counts<L
for (PlanElement el : plan.getPlanElements()) {
if (el instanceof Leg leg) {

// TODO: other leg modes
if (!leg.getMode().equals(TransportMode.car))
Object networkMode = leg.getAttributes().getAttribute("networkMode");
if (!Objects.equals(networkMode, this.networkMode))
continue;

// TODO: scale travel time with factor from the leg

if (leg.getRoute() instanceof NetworkRoute route) {
double travelTime = leg.getTravelTime().orElseThrow(() -> new IllegalStateException("No travel time for leg"));
double freeTravelTime = route.getLinkIds().stream()
.map(id -> network.getLinks().get(id))
// Use ceil because traversal over links is always whole seconds during simulation
.mapToDouble(l -> Math.ceil(l.getLength() / l.getFreespeed()))
.sum();

boolean relevant = route.getLinkIds().stream().anyMatch(links::contains);

// The actual travel time per link is not known
// The overall deviation is applied to all links equally
double factor = travelTime / freeTravelTime;

double time = leg.getDepartureTime().seconds();

if (relevant) {
Expand All @@ -196,7 +205,7 @@ private List<PlanPerson> processPopulation(Path input, Network network, Counts<L
Link link = network.getLinks().get(linkId);

// Assume free speed travel time
time += link.getLength() / link.getFreespeed() + 1;
time += Math.ceil(link.getLength() / link.getFreespeed()) * factor;

if (linkMapping.containsKey(linkId)) {
int idx = linkMapping.getInt(linkId);
Expand Down

0 comments on commit ff32cff

Please sign in to comment.