Skip to content

Commit

Permalink
Updates for mode choice work
Browse files Browse the repository at this point in the history
  • Loading branch information
CorinStaves committed Jan 19, 2024
1 parent 57ea79b commit 04651d9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 18 deletions.
14 changes: 7 additions & 7 deletions src/main/java/diary/RunMultiRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class RunMultiRouter {

private final static Logger logger = Logger.getLogger(RunMultiRouter.class);

private final static int SAMPLES = 1000;
private final static int SAMPLES = 800;

private final static String SEP = ",";

Expand Down Expand Up @@ -85,7 +85,7 @@ public static void main(String[] args) throws IOException, FactoryException {

if(mode.equals(TransportMode.bike)) {
Bicycle bicycle = new Bicycle(null);
tt = bicycle.getTravelTime();
tt = bicycle.getTravelTimeFast(network);
veh = bicycle.getVehicle();
} else if (mode.equals(TransportMode.walk)) {
tt = new WalkTravelTime();
Expand All @@ -102,7 +102,7 @@ public static void main(String[] args) throws IOException, FactoryException {
if(origNode.equals(destNode)) {
it.remove();
logger.warn("HouseholdID " + trip.getHouseholdId() + " Person " + trip.getPersonId() + " Trip " + trip.getTripId() +
" are in different zones bu have the same origin & destination. Removing...");
" are in different zones but have the same origin & destination. Removing...");
} else {
trip.setNodes(origNode,destNode);
}
Expand All @@ -118,10 +118,10 @@ public static void main(String[] args) throws IOException, FactoryException {

// GENERATE RANDOM NUMBERS AND WRITE SAMPLES
logger.info("Randomly sampling " + SAMPLES + " sets of marginal cost values.");
double[] mcGradient = random.doubles(SAMPLES,0,20).toArray();
double[] mcVgvi = random.doubles(SAMPLES,0,10).toArray();
double[] mcStressLink = random.doubles(SAMPLES,0,10).toArray();
double[] mcStressJct = random.doubles(SAMPLES,0,10).toArray();
double[] mcGradient = new double[SAMPLES]; // random.doubles(SAMPLES,0,20).toArray(); // 0-30 for cycling, 0-2 for walking
double[] mcVgvi = random.doubles(SAMPLES,0,3).toArray();
double[] mcStressLink = random.doubles(SAMPLES,0,3).toArray();
double[] mcStressJct = random.doubles(SAMPLES,0,25).toArray();
int[] newPathCount = new int[SAMPLES];

// ESTIMATE PATHS
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/diary/RunRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static void main(String[] args) throws IOException, FactoryException {

// Travel time
// FreespeedTravelTimeAndDisutility freeSpeed = new FreespeedTravelTimeAndDisutility(config.planCalcScore());
TravelTime ttBikeFast = bicycle.getTravelTimeFast(networkBike,bike);
TravelTime ttBikeFast = bicycle.getTravelTimeFast(networkBike);
TravelTime ttWalk = new WalkTravelTime();

// // Car freespeed & congested travel time
Expand All @@ -123,12 +123,14 @@ public static void main(String[] args) throws IOException, FactoryException {
// calc.network("car_congested", ORIGIN, DESTINATION, null, networkCar, carXy2l, congestedDisutility, congestedTime, null,savePath);

// bike
calc.network("bike_jibe", ORIGIN, DESTINATION, bike, networkBike, networkBike, new JibeDisutility3Fast(networkBike,bike,TransportMode.bike,ttBikeFast,null), ttBikeFast, ActiveAttributes.getJibeTime(TransportMode.bike,bike),savePath);
calc.network("bike_jibe_day", ORIGIN, DESTINATION, bike, networkBike, networkBike, new JibeDisutility3Fast(networkBike,bike,TransportMode.bike,ttBikeFast,true), ttBikeFast, ActiveAttributes.getJibeTime(TransportMode.bike,bike),savePath);
calc.network("bike_jibe_night", ORIGIN, DESTINATION, bike, networkBike, networkBike, new JibeDisutility3Fast(networkBike,bike,TransportMode.bike,ttBikeFast,false), ttBikeFast, ActiveAttributes.getJibeTime(TransportMode.bike,bike),savePath);
calc.network("bike_short", ORIGIN, DESTINATION, bike, networkBike, networkBike, new DistanceDisutility(), ttBikeFast, ActiveAttributes.getJibeDist(TransportMode.bike),savePath);
calc.network("bike_fast", ORIGIN, DESTINATION, bike, networkBike, networkBike, new OnlyTimeDependentTravelDisutility(ttBikeFast), ttBikeFast, ActiveAttributes.getJibeTime(TransportMode.bike,bike),savePath);

// walk
calc.network("walk_jibe", ORIGIN, DESTINATION, null, networkWalk, networkWalk, new JibeDisutility3Fast(networkWalk,null,TransportMode.walk,ttWalk,null), ttWalk, ActiveAttributes.getJibeTime(TransportMode.walk,null), savePath);
calc.network("walk_jibe_day", ORIGIN, DESTINATION, null, networkWalk, networkWalk, new JibeDisutility3Fast(networkWalk,null,TransportMode.walk,ttWalk,true), ttWalk, ActiveAttributes.getJibeTime(TransportMode.walk,null), savePath);
calc.network("walk_jibe_night", ORIGIN, DESTINATION, null, networkWalk, networkWalk, new JibeDisutility3Fast(networkWalk,null,TransportMode.walk,ttWalk,false), ttWalk, ActiveAttributes.getJibeTime(TransportMode.walk,null), savePath);
calc.network("walk_short", ORIGIN, DESTINATION, null, networkWalk, networkWalk, new DistanceDisutility(), ttWalk, ActiveAttributes.getJibeDist(TransportMode.walk),savePath);
Expand Down
41 changes: 33 additions & 8 deletions src/main/java/network/WriteLinksPerZone.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
import io.ioUtils;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.IdSet;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
import org.matsim.core.router.util.TravelTime;
import org.matsim.vehicles.Vehicle;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.referencing.FactoryException;
import resources.Resources;
import routing.Bicycle;
import routing.Gradient;
import routing.disutility.components.JctStress;
import routing.disutility.components.LinkAmbience;
import routing.disutility.components.LinkStress;
import routing.travelTime.WalkTravelTime;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -48,26 +53,46 @@ public static void main(String[] args) throws IOException, FactoryException {
// Get links per zone
Map<SimpleFeature, IdSet<Link>> linksPerZone = GisUtils.calculateLinksIntersectingZones(features,network);

// Travel time and vehicle
TravelTime tt;
Vehicle veh;

if(mode.equals(TransportMode.bike)) {
Bicycle bicycle = new Bicycle(null);
tt = bicycle.getTravelTime();
veh = bicycle.getVehicle();
} else if (mode.equals(TransportMode.walk)) {
tt = new WalkTravelTime();
veh = null;
} else throw new RuntimeException("Modes other than walk and bike are not supported!");

// Create CSV
PrintWriter out = ioUtils.openFileForSequentialWriting(new File(outputCsv), false);
assert out != null;

// Write header
out.println(idAttribute + SEP + "linkID" + SEP + "length" + SEP + "gradient" + SEP +
"vgvi" + SEP + "darkness" + SEP + "mStressLink" + SEP + "mStressJct");
out.println(idAttribute + SEP + "linkID" + SEP + "length" + SEP + "time" + SEP +
"gradient" + SEP + "vgvi" + SEP + "stressLink" + SEP + "stressJct");

// Write rows
for (Map.Entry<SimpleFeature, IdSet<Link>> entry : linksPerZone.entrySet()) {
String zoneId = (String) entry.getKey().getAttribute(idAttribute);
for(Id<Link> linkId : entry.getValue()) {
Link link = network.getLinks().get(linkId);
out.println(zoneId + SEP + linkId.toString() + SEP +
link.getLength() + SEP +
Math.max(Gradient.getGradient(link),0.) + SEP +
LinkAmbience.getVgviFactor(link) + SEP +
LinkAmbience.getDarknessFactor(link) + SEP +
double linkLength = link.getLength();
double linkTime = tt.getLinkTravelTime(link,0.,null,veh);

double stressJct = 0.;
if((boolean) link.getAttributes().getAttribute("crossVehicles")) {
double junctionWidth = Math.min(linkLength,(double) link.getAttributes().getAttribute("crossWidth"));
stressJct = (junctionWidth / linkLength) * JctStress.getStress(link,mode);
}

out.println(zoneId + SEP + linkId.toString() + SEP + linkLength + SEP + linkTime + SEP +
Math.max(Math.min(Gradient.getGradient(link),0.5),0.) + SEP +
Math.max(0.,0.81 - LinkAmbience.getVgviFactor(link)) + SEP +
LinkStress.getStress(link,mode) + SEP +
JctStress.getStress(link,mode));
stressJct);
}
}
out.close();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/routing/Bicycle.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public TravelTime getTravelTime() {
return this.travelTime;
}

public TravelTime getTravelTimeFast(Network network, Vehicle vehicle) {
return new BicycleTravelTimeFast(linkSpeedCalculator, network, vehicle);
public TravelTime getTravelTimeFast(Network network) {
return new BicycleTravelTimeFast(this.linkSpeedCalculator, network, this.vehicle);
}

}

0 comments on commit 04651d9

Please sign in to comment.