Skip to content

Commit

Permalink
Updates for manchetser / melbourne compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
CorinStaves committed Jan 2, 2024
1 parent 0709538 commit be735c3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
41 changes: 21 additions & 20 deletions src/main/java/diary/RunRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import routing.ActiveAttributes;
import routing.Bicycle;
import routing.disutility.DistanceDisutility;
import routing.disutility.JibeDisutility3Fast;
import routing.travelTime.WalkTravelTime;
import diary.calculate.RouteIndicatorCalculator;
import io.TripCsvWriter;
Expand Down Expand Up @@ -97,39 +98,39 @@ public static void main(String[] args) throws IOException, FactoryException {
// String transitNetworkFilePath = Resources.instance.getString(Properties.MATSIM_TRANSIT_NETWORK);

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

// Car freespeed & congested travel time
String tfgmDemandEvents = Resources.instance.getString(Properties.MATSIM_DEMAND_OUTPUT_EVENTS);
TravelTimeCalculator.Builder builder = new TravelTimeCalculator.Builder(networkCar);
TravelTimeCalculator congested = builder.build();
EventsManager events = EventsUtils.createEventsManager();
events.addHandler(congested);
(new MatsimEventsReader(events)).readFile(tfgmDemandEvents);
TravelTime congestedTime = congested.getLinkTravelTimes();
TravelDisutility congestedDisutility = new OnlyTimeDependentTravelDisutility(congested.getLinkTravelTimes());
// // Car freespeed & congested travel time
// String tfgmDemandEvents = Resources.instance.getString(Properties.MATSIM_DEMAND_OUTPUT_EVENTS);
// TravelTimeCalculator.Builder builder = new TravelTimeCalculator.Builder(networkCar);
// TravelTimeCalculator congested = builder.build();
// EventsManager events = EventsUtils.createEventsManager();
// events.addHandler(congested);
// (new MatsimEventsReader(events)).readFile(tfgmDemandEvents);
// TravelTime congestedTime = congested.getLinkTravelTimes();
// TravelDisutility congestedDisutility = new OnlyTimeDependentTravelDisutility(congested.getLinkTravelTimes());

// CALCULATOR
RouteIndicatorCalculator calc = new RouteIndicatorCalculator(trips);

// beeline
calc.beeline("beeline", ORIGIN, DESTINATION);

// car
calc.network("car_freespeed", ORIGIN, DESTINATION, null, networkCar, carXy2l, freeSpeed, freeSpeed, null,savePath);
calc.network("car_congested", ORIGIN, DESTINATION, null, networkCar, carXy2l, congestedDisutility, congestedTime, null,savePath);
// // beeline
// calc.beeline("beeline", ORIGIN, DESTINATION);
//
// // car
// calc.network("car_freespeed", ORIGIN, DESTINATION, null, networkCar, carXy2l, freeSpeed, freeSpeed, null,savePath);
// calc.network("car_congested", ORIGIN, DESTINATION, null, networkCar, carXy2l, congestedDisutility, congestedTime, null,savePath);

// bike
// calc.network("bike_jibe_day", ORIGIN, DESTINATION, bike, networkBike, networkBike, new JibeDisutility3Fast(networkBike,bike,TransportMode.bike,ttBikeFast,true), ttBike, null,savePath);
// calc.network("bike_jibe_night", ORIGIN, DESTINATION, bike, networkBike, networkBike, new JibeDisutility3Fast(networkBike,bike,TransportMode.bike,ttBikeFast,false), ttBike, null,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_day", ORIGIN, DESTINATION, null, networkWalk, networkWalk, new JibeDisutility3Fast(networkWalk,null,TransportMode.walk,ttWalk,true), ttWalk, null, savePath);
// calc.network("walk_jibe_night", ORIGIN, DESTINATION, null, networkWalk, networkWalk, new JibeDisutility3Fast(networkWalk,null,TransportMode.walk,ttWalk,false), ttWalk, 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);
calc.network("walk_fast", ORIGIN, DESTINATION, null, networkWalk, networkWalk, new OnlyTimeDependentTravelDisutility(ttWalk), ttWalk, ActiveAttributes.getJibeTime(TransportMode.walk,null),savePath);

Expand Down
11 changes: 10 additions & 1 deletion src/main/java/network/CreateMatsimNetworkRoad.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,16 @@ private static void addLinkToNetwork(int edgeID, SimpleFeature edge, Network net
l2.setCapacity(allowsCarRtn ? capacity : 0.);

// Speed limit (miles per hour)
double speedLimit = (double) edge.getAttribute("maxspeed");
Object speedLimitObj = edge.getAttribute("maxspeed");
double speedLimit;
if(speedLimitObj instanceof Double) {
speedLimit = (double) speedLimitObj;
} else if (speedLimitObj instanceof Integer) {
speedLimit = ((Integer) speedLimitObj).doubleValue();
} else {
throw new RuntimeException("maxspeed attribute must be stored as integer or double!");
}

l1.getAttributes().putAttribute("speedLimitMPH",speedLimit);
l2.getAttributes().putAttribute("speedLimitMPH",speedLimit);

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/routing/ActiveAttributes.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ public static LinkedHashMap<String,TravelAttribute> getJibeTime(String mode, Veh
attributes.put("gradient",(l,td,tt) -> Math.max(Math.min(Gradient.getGradient(l),0.5),0.) * tt.getLinkTravelTime(l,0.,null,veh));
attributes.put("comfort",(l,td,tt) -> LinkComfort.getComfortFactor(l) * tt.getLinkTravelTime(l,0.,null,veh));
attributes.put("vgvi",(l,td,tt) -> LinkAmbience.getVgviFactor(l) * tt.getLinkTravelTime(l,0.,null,veh));
// attributes.put("lighting",(l,td,tt) -> LinkAmbience.getLightingFactor(l) * tt.getLinkTravelTime(l,0.,null,veh));
attributes.put("lighting",(l,td,tt) -> LinkAmbience.getLightingFactor(l) * tt.getLinkTravelTime(l,0.,null,veh));
attributes.put("shannon_adj", (l,td,tt) -> LinkAmbience.getShannonFactor(l) * tt.getLinkTravelTime(l,0.,null,veh));
attributes.put("shannon_sum", (l,td,tt) -> (double) l.getAttributes().getAttribute("shannon") * tt.getLinkTravelTime(l,0.,null,veh));
// attributes.put("crime", (l,td,tt) -> LinkAmbience.getCrimeFactor(l) * tt.getLinkTravelTime(l,0.,null,veh));
attributes.put("crime", (l,td,tt) -> LinkAmbience.getCrimeFactor(l) * tt.getLinkTravelTime(l,0.,null,veh));
attributes.put("POI_adj",(l,td,tt) -> LinkAmbience.getPoiFactor(l) * tt.getLinkTravelTime(l,0.,null,veh));
attributes.put("POI_count",(l,td,tt) -> ((Integer) l.getAttributes().getAttribute("POIs")).doubleValue());
attributes.put("negPOI_adj",(l,td,tt) -> LinkAmbience.getNegativePoiFactor(l) * tt.getLinkTravelTime(l,0.,null,veh));
attributes.put("negPOI_count",(l,td,tt) -> ((Integer) l.getAttributes().getAttribute("negPOIs")).doubleValue());
// attributes.put("ambience", (l,td,tt) -> LinkAmbience.getDayAmbience(l) * tt.getLinkTravelTime(l,0.,null,veh));
attributes.put("ambience", (l,td,tt) -> LinkAmbience.getDayAmbience(l) * tt.getLinkTravelTime(l,0.,null,veh));
attributes.put("stressLink",(l,td,tt) -> LinkStress.getStress(l,mode) * tt.getLinkTravelTime(l,0.,null,veh));
attributes.put("stressJct",(l,td,tt) -> getJibe3StressJctTime(mode,l,tt,veh));
return attributes;
Expand All @@ -64,15 +64,15 @@ public static LinkedHashMap<String,TravelAttribute> getJibeDist(String mode) {
attributes.put("gradient",(l,td,tt) -> Math.max(Math.min(Gradient.getGradient(l),0.5),0.) * l.getLength());
attributes.put("comfort",(l,td,tt) -> LinkComfort.getComfortFactor(l) * l.getLength());
attributes.put("vgvi",(l,td,tt) -> LinkAmbience.getVgviFactor(l) * l.getLength());
// attributes.put("lighting",(l,td,tt) -> LinkAmbience.getLightingFactor(l) * l.getLength());
attributes.put("lighting",(l,td,tt) -> LinkAmbience.getLightingFactor(l) * l.getLength());
attributes.put("shannon_adj", (l,td,tt) -> LinkAmbience.getShannonFactor(l) * l.getLength());
attributes.put("shannon_sum", (l,td,tt) -> (double) l.getAttributes().getAttribute("shannon") * l.getLength());
// attributes.put("crime", (l,td,tt) -> LinkAmbience.getCrimeFactor(l) * l.getLength());
attributes.put("crime", (l,td,tt) -> LinkAmbience.getCrimeFactor(l) * l.getLength());
attributes.put("POI_adj",(l,td,tt) -> LinkAmbience.getPoiFactor(l) * l.getLength());
attributes.put("POI_count",(l,td,tt) -> ((Integer) l.getAttributes().getAttribute("POIs")).doubleValue());
attributes.put("negPOI_adj",(l,td,tt) -> LinkAmbience.getNegativePoiFactor(l) * l.getLength());
attributes.put("negPOI_count",(l,td,tt) -> ((Integer) l.getAttributes().getAttribute("negPOIs")).doubleValue());
// attributes.put("ambience", (l,td,tt) -> LinkAmbience.getDayAmbience(l) * l.getLength());
attributes.put("ambience", (l,td,tt) -> LinkAmbience.getDayAmbience(l) * l.getLength());
attributes.put("stressLink",(l,td,tt) -> LinkStress.getStress(l,mode) * l.getLength());
attributes.put("stressJct",(l,td,tt) -> getJibe3StressJctDist(mode,l));
return attributes;
Expand Down

0 comments on commit be735c3

Please sign in to comment.