From 04651d923e63f765820c6fca530f683106c21089 Mon Sep 17 00:00:00 2001 From: Corin Staves Date: Fri, 19 Jan 2024 13:23:37 +0100 Subject: [PATCH] Updates for mode choice work --- src/main/java/diary/RunMultiRouter.java | 14 +++---- src/main/java/diary/RunRouter.java | 4 +- src/main/java/network/WriteLinksPerZone.java | 41 ++++++++++++++++---- src/main/java/routing/Bicycle.java | 4 +- 4 files changed, 45 insertions(+), 18 deletions(-) diff --git a/src/main/java/diary/RunMultiRouter.java b/src/main/java/diary/RunMultiRouter.java index f315832..e9c1bd5 100644 --- a/src/main/java/diary/RunMultiRouter.java +++ b/src/main/java/diary/RunMultiRouter.java @@ -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 = ","; @@ -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(); @@ -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); } @@ -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 diff --git a/src/main/java/diary/RunRouter.java b/src/main/java/diary/RunRouter.java index c53ad80..b9fc9a1 100644 --- a/src/main/java/diary/RunRouter.java +++ b/src/main/java/diary/RunRouter.java @@ -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 @@ -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); diff --git a/src/main/java/network/WriteLinksPerZone.java b/src/main/java/network/WriteLinksPerZone.java index 3a0d0ab..2b6f240 100644 --- a/src/main/java/network/WriteLinksPerZone.java +++ b/src/main/java/network/WriteLinksPerZone.java @@ -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; @@ -48,26 +53,46 @@ public static void main(String[] args) throws IOException, FactoryException { // Get links per zone Map> 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> entry : linksPerZone.entrySet()) { String zoneId = (String) entry.getKey().getAttribute(idAttribute); for(Id 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(); diff --git a/src/main/java/routing/Bicycle.java b/src/main/java/routing/Bicycle.java index f2a0ad2..f13dcbc 100644 --- a/src/main/java/routing/Bicycle.java +++ b/src/main/java/routing/Bicycle.java @@ -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); } }