Skip to content

Commit

Permalink
Updates for Melbourne Network Compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
CorinStaves committed Dec 26, 2023
1 parent 5645a31 commit 9dbff70
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 97 deletions.
13 changes: 7 additions & 6 deletions src/main/java/diary/RunRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,19 @@ public static void main(String[] args) throws IOException, FactoryException {
// // beeline
calc.beeline("beeline", ORIGIN, DESTINATION);

// car (freespeed only)
// 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 (shortest and fastest)
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);
// 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_short", ORIGIN, DESTINATION, bike, networkBike, networkBike, new DistanceDisutility(), ttBikeFast, null,savePath);
calc.network("bike_fast", ORIGIN, DESTINATION, bike, networkBike, networkBike, new OnlyTimeDependentTravelDisutility(ttBikeFast), ttBike, null,savePath);

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);
// 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_short", ORIGIN, DESTINATION, null, networkWalk, networkWalk, new DistanceDisutility(), ttWalk, null,savePath);
calc.network("walk_fast", ORIGIN, DESTINATION, null, networkWalk, networkWalk, new OnlyTimeDependentTravelDisutility(ttWalk), ttWalk, null,savePath);

Expand Down
102 changes: 57 additions & 45 deletions src/main/java/network/CreateMatsimNetworkRoad.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ private static void addLinkToNetwork(int edgeID, SimpleFeature edge, Network net
String linkModes = (String) edge.getAttribute("modes");

if(origNodeId != destNodeId && !linkModes.equals("pt")) {
String roadType = (String) edge.getAttribute("roadtyp");

Node origNode = net.getNodes().get(Id.createNodeId(origNodeId));
Node destNode = net.getNodes().get(Id.createNodeId(destNodeId));

Expand Down Expand Up @@ -147,22 +145,72 @@ private static void addLinkToNetwork(int edgeID, SimpleFeature edge, Network net
l1.getAttributes().putAttribute("urban",urban);
l2.getAttributes().putAttribute("urban",urban);

// CYCLING INFRASTRUCTURE
// Cycle lane
l1.getAttributes().putAttribute("cycleway",Objects.requireNonNullElse(edge.getAttribute("cyclwy_f"),"null"));
l2.getAttributes().putAttribute("cycleway",Objects.requireNonNullElse(edge.getAttribute("cyclwy_b"),"null"));

// OSM Cycle lane type
String cycleosm = (String) edge.getAttribute("cyclesm");
if(cycleosm == null) {
cycleosm = "null";
}
l1.getAttributes().putAttribute("cycleosm",cycleosm);
l2.getAttributes().putAttribute("cycleosm",cycleosm);

// ROAD TYPE
// Type
String highway = (String) edge.getAttribute("highway");
l1.getAttributes().putAttribute("type",edge.getAttribute("highway"));
l2.getAttributes().putAttribute("type",edge.getAttribute("highway"));

// Roadtyp attribute
String roadType = (String) edge.getAttribute("roadtyp");
if(roadType == null) {
roadType = highway;
}

// Is the road a motorway?
boolean motorway = roadType.contains("motorway");
l1.getAttributes().putAttribute("motorway",motorway);
l2.getAttributes().putAttribute("motorway",motorway);

// Is the road a trunk road?
boolean trunk = motorway || roadType.contains("Trunk") || roadType.contains("trunk");
l1.getAttributes().putAttribute("trunk",trunk);
l2.getAttributes().putAttribute("trunk",trunk);

// Is the road a primary road?
boolean primary = trunk || roadType.contains("Main") || roadType.contains("primary");
l1.getAttributes().putAttribute("primary",primary);
l2.getAttributes().putAttribute("primary",primary);

// ALLOWED MODES
Set<String> allowedModesOut = Sets.newHashSet(linkModes.split(","));
l1.setAllowedModes(allowedModesOut);

// If allows walk but not bike, add bike but specify must dismount
boolean walkNotBike = allowedModesOut.contains("walk") && !allowedModesOut.contains("bike");
boolean dismount = walkNotBike || roadType.contains("Cycling Forbidden") || cycleosm.equals("dismount");

l1.getAttributes().putAttribute("dismount",dismount);
l2.getAttributes().putAttribute("dismount",dismount);

// Add back cycling (dismounted) if walking is allowed
if(walkNotBike) allowedModesOut.add("bike");

// Allowed modes return
Set<String> allowedModesRtn = new HashSet<>(allowedModesOut);
String oneWaySummary = (String) edge.getAttribute("onwysmm");
if(oneWaySummary.equals("One Way")) {
allowedModesRtn.remove(bike);
allowedModesRtn.remove(car);
allowedModesRtn.remove(truck);
} else if(oneWaySummary.equals("One Way - Two Way Cycling")) {
} else if(oneWaySummary.equals("One Way - Two Way Cycling")) { // Manchester network only
allowedModesRtn.remove(car);
allowedModesRtn.remove(truck);
} else {
Boolean isOneWay = (Boolean) edge.getAttribute("is_oneway"); // Attribute currently only for Melbourne network
Boolean isOneWay = (Boolean) edge.getAttribute("is_oneway"); // Melbourne network only
if(isOneWay != null) {
if(isOneWay) {
allowedModesRtn.remove(bike);
Expand Down Expand Up @@ -211,59 +259,23 @@ private static void addLinkToNetwork(int edgeID, SimpleFeature edge, Network net
l2.setCapacity(allowsCarRtn ? capacity : 0.);

// Speed limit (miles per hour)
Integer speedLimit = (Integer) edge.getAttribute("maxspeed");
double speedLimit = (double) edge.getAttribute("maxspeed");
l1.getAttributes().putAttribute("speedLimitMPH",speedLimit);
l2.getAttributes().putAttribute("speedLimitMPH",speedLimit);

// Cycle lane
l1.getAttributes().putAttribute("cycleway",edge.getAttribute("cyclwy_f"));
l2.getAttributes().putAttribute("cycleway",edge.getAttribute("cyclwy_b"));

// OSM Cycle lane type
String cycleosm = (String) edge.getAttribute("cyclesm");
if(cycleosm == null) {
cycleosm = "null";
}
l1.getAttributes().putAttribute("cycleosm",cycleosm);
l2.getAttributes().putAttribute("cycleosm",cycleosm);

// Surface
String surface = (String) edge.getAttribute("surface");
if(surface == null) {
surface = "unknown";
surface = "null";
}
l1.getAttributes().putAttribute("surface",surface);
l2.getAttributes().putAttribute("surface",surface);

// Type
l1.getAttributes().putAttribute("type",edge.getAttribute("highway"));
l2.getAttributes().putAttribute("type",edge.getAttribute("highway"));

// Is the road a motorway?
boolean motorway = roadType.contains("motorway");
l1.getAttributes().putAttribute("motorway",motorway);
l2.getAttributes().putAttribute("motorway",motorway);

// Is the road a trunk road?
boolean trunk = motorway || roadType.contains("Trunk");
l1.getAttributes().putAttribute("trunk",trunk);
l2.getAttributes().putAttribute("trunk",trunk);

// Is the road a primary road?
boolean primary = trunk || roadType.contains("Main");
l1.getAttributes().putAttribute("primary",primary);
l2.getAttributes().putAttribute("primary",primary);

// Do cyclists have to dismount?
boolean dismount = roadType.contains("Cycling Forbidden") || cycleosm.equals("dismount");
l1.getAttributes().putAttribute("dismount",dismount);
l2.getAttributes().putAttribute("dismount",dismount);

// Add NDVImean attribute
Double ndvi = (Double) edge.getAttribute("NDVImen");
if(ndvi == null) {
ndvi = 0.;
// log.warn("Null NDVI for edge " + edgeID + ". Set to 0."); todo: uncomment once NDVI is added to Melbourne dataset
// log.warn("Null NDVI for edge " + edgeID + ". Set to 0."); todo: uncomment when/if NDVI is added to Melbourne dataset
}
l1.getAttributes().putAttribute("ndvi",ndvi);
l2.getAttributes().putAttribute("ndvi",ndvi);
Expand Down Expand Up @@ -375,8 +387,8 @@ private static void addCrossingAttributes(Network net) {
.mapToInt(l -> (int) l.getAttributes().getAttribute("aadtFwd"))
.sum();
crossSpeedLimit = crossingLinks.stream()
.mapToInt(l -> (int) l.getAttributes().getAttribute("speedLimitMPH"))
.max().getAsInt();
.mapToDouble(l -> (double) l.getAttributes().getAttribute("speedLimitMPH"))
.max().getAsDouble();
cross85PercSpeed = crossingLinks.stream()
.mapToDouble(l -> (double) l.getAttributes().getAttribute("veh85percSpeedKPH"))
.max().getAsDouble();
Expand Down
46 changes: 24 additions & 22 deletions src/main/java/network/WriteNetworkGpkg.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,15 @@ private static SimpleFeatureType createFeatureType() throws FactoryException {
builder.add("path", LineString.class);
builder.add("edgeID",Integer.class);
builder.add("osmID",Integer.class);
builder.add("name",String.class);
builder.add("linkID",String.class);
builder.add("fwd",Boolean.class);
builder.add("length",Double.class);
builder.add("cycleTime",Double.class);
builder.add("walkTime",Double.class);
builder.add("freespeed",Double.class);
// builder.add("carSpeedLimitMPH",Double.class);
// builder.add("car85PercSpeedKPH",Double.class);
builder.add("carSpeedLimitMPH",Double.class);
builder.add("car85PercSpeedKPH",Double.class);
// builder.add("bikeJibeMarginalDisutilityDay",Double.class);
// builder.add("bikeJibeMarginalDisutilityNight",Double.class);
// builder.add("walkJibeMarginalDisutilityDay",Double.class);
Expand All @@ -116,15 +117,15 @@ private static SimpleFeatureType createFeatureType() throws FactoryException {
// builder.add("disconnected_walk",Boolean.class);
builder.add("gradient",Double.class);
builder.add("bikeProtectionType",String.class);
// builder.add("endsAtJct",Boolean.class);
// builder.add("crossesVehicles",Boolean.class);
// builder.add("crossingTypeBike",String.class);
// builder.add("crossingTypeWalk",String.class);
// builder.add("crossingLanes",Double.class);
// builder.add("crossingWidth",Double.class);
// builder.add("crossingAADT",Double.class);
// builder.add("crossingSpeedLimit",Double.class);
// builder.add("crossing85PercSpeed",Double.class);
builder.add("endsAtJct",Boolean.class);
builder.add("crossesVehicles",Boolean.class);
builder.add("crossingTypeBike",String.class);
builder.add("crossingTypeWalk",String.class);
builder.add("crossingLanes",Double.class);
builder.add("crossingWidth",Double.class);
builder.add("crossingAADT",Double.class);
builder.add("crossingSpeedLimit",Double.class);
builder.add("crossing85PercSpeed",Double.class);
builder.add("vgvi",Double.class);
builder.add("shannon",Double.class);
builder.add("POIs",Double.class);
Expand Down Expand Up @@ -242,14 +243,15 @@ public static void write(Network network, String outputEdgesFilePath) throws IOE
// Other attributes
featureBuilder.add(edgeID);
featureBuilder.add(link.getAttributes().getAttribute("osmID"));
featureBuilder.add(link.getAttributes().getAttribute("name"));
featureBuilder.add(link.getId().toString());
featureBuilder.add(fwd);
featureBuilder.add(length);
featureBuilder.add(cycleTime);
featureBuilder.add(walkTime);
featureBuilder.add(link.getFreespeed());
// featureBuilder.add(link.getAttributes().getAttribute("speedLimitMPH"));
// featureBuilder.add(link.getAttributes().getAttribute("veh85percSpeedKPH"));
featureBuilder.add(link.getAttributes().getAttribute("speedLimitMPH"));
featureBuilder.add(link.getAttributes().getAttribute("veh85percSpeedKPH"));
// featureBuilder.add(bikeMarginalDisutilitiesDay.get(link.getId()));
// featureBuilder.add(bikeMarginalDisutilitiesNight.get(link.getId()));
// featureBuilder.add(walkMarginalDisutilitiesDay.get(link.getId()));
Expand All @@ -271,15 +273,15 @@ public static void write(Network network, String outputEdgesFilePath) throws IOE
// featureBuilder.add(link.getAttributes().getAttribute("disconnected_"+ TransportMode.walk));
featureBuilder.add(Gradient.getGradient(link));
featureBuilder.add((allowsBike || allowsWalk) ? CycleProtection.getType(link).toString() : "null");
// featureBuilder.add(link.getAttributes().getAttribute("endsAtJct"));
// featureBuilder.add(link.getAttributes().getAttribute("crossVehicles"));
// featureBuilder.add(Crossing.getType(link,"bike").toString());
// featureBuilder.add(Crossing.getType(link,"walk").toString());
// featureBuilder.add(link.getAttributes().getAttribute("crossLanes"));
// featureBuilder.add(link.getAttributes().getAttribute("crossWidth"));
// featureBuilder.add(link.getAttributes().getAttribute("crossAadt"));
// featureBuilder.add(link.getAttributes().getAttribute("crossSpeedLimitMPH"));
// featureBuilder.add(link.getAttributes().getAttribute("cross85PercSpeed"));
featureBuilder.add(link.getAttributes().getAttribute("endsAtJct"));
featureBuilder.add(link.getAttributes().getAttribute("crossVehicles"));
featureBuilder.add(Crossing.getType(link,"bike").toString());
featureBuilder.add(Crossing.getType(link,"walk").toString());
featureBuilder.add(link.getAttributes().getAttribute("crossLanes"));
featureBuilder.add(link.getAttributes().getAttribute("crossWidth"));
featureBuilder.add(link.getAttributes().getAttribute("crossAadt"));
featureBuilder.add(link.getAttributes().getAttribute("crossSpeedLimitMPH"));
featureBuilder.add(link.getAttributes().getAttribute("cross85PercSpeed"));
featureBuilder.add(link.getAttributes().getAttribute("vgvi"));
featureBuilder.add(link.getAttributes().getAttribute("shannon"));
featureBuilder.add(link.getAttributes().getAttribute("POIs"));
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/routing/ActiveAttributes.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,20 @@ public static LinkedHashMap<String,TravelAttribute> getJibe3(String mode, Vehicl
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", (l,td,tt) -> LinkAmbience.getShannonFactor(l) * 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("POIs",(l,td,tt) -> LinkAmbience.getPoiFactor(l) * tt.getLinkTravelTime(l,0.,null,veh));
attributes.put("negPOIs",(l,td,tt) -> LinkAmbience.getNegativePoiFactor(l) * tt.getLinkTravelTime(l,0.,null,veh));
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) -> getJibe4StressJct(mode,l,tt,veh));
attributes.put("stressJct",(l,td,tt) -> getJibe3StressJct(mode,l,tt,veh));
return attributes;
}

private static double getJibe4StressJct(String mode, Link l, TravelTime tt, Vehicle veh) {


private static double getJibe3StressJct(String mode, Link l, TravelTime tt, Vehicle veh) {
if((boolean) l.getAttributes().getAttribute("crossVehicles")) {
return JctStress.getStress(l,mode) * tt.getLinkTravelTime(l,0.,null,veh) *
(Math.min((double) l.getAttributes().getAttribute("crossWidth") / l.getLength(), 1.));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.matsim.contrib.bicycle.BicycleUtils;

public enum CycleProtection {
OFFROAD,
KERBED,
PROTECTED,
LANE,
MIXED;
Expand All @@ -17,7 +17,8 @@ public static CycleProtection getType(Link link) {
if (link.getAllowedModes().contains(TransportMode.walk) || link.getAllowedModes().contains(TransportMode.bike)) {
switch (cycleosm) {
case "offroad":
return OFFROAD;
case "kerbed":
return KERBED;
case "protected":
return PROTECTED;
case "painted":
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/routing/disutility/components/JctStress.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public static double getStress(Link link, String mode) {
if(crossingType.equals(UNCONTROLLED)) {
if(crossingSpeed < 60) {
stress = crossingAadt/(300*crossingSpeed + 16500) + crossingSpeed/90 + crossingLanes/3 - 0.5;
if(mode.equals(TransportMode.bike) && link.getAllowedModes().contains(TransportMode.car)) {
stress = Math.max(stress,LinkStress.getStress(link,mode));
}
} else {
stress = 1.;
}
Expand Down
Loading

0 comments on commit 9dbff70

Please sign in to comment.