Skip to content

Commit

Permalink
Updates to junction stress
Browse files Browse the repository at this point in the history
  • Loading branch information
CorinStaves committed Dec 23, 2023
1 parent d14d1ad commit 5645a31
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 67 deletions.
12 changes: 8 additions & 4 deletions src/main/java/routing/disutility/components/Crossing.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@

public enum Crossing {
UNCONTROLLED,
PARALLEL,
SIGNAL;
ZEBRA,
SIGNAL_MIXED,
SIGNAL_ACTIVE;

public static Crossing getType(Link link, String mode) {
String name = (String) link.getToNode().getAttributes().getAttribute(mode + "Crossing");
switch (name) {
case "null":
return UNCONTROLLED;
case "Parallel crossing point":
return PARALLEL;
case "crossing point":
return ZEBRA;
case "Car signal":
return SIGNAL_MIXED;
default:
return SIGNAL;
return SIGNAL_ACTIVE;
}
}
}
37 changes: 20 additions & 17 deletions src/main/java/routing/disutility/components/JctStress.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package routing.disutility.components;

import org.matsim.api.core.v01.TransportMode;
import org.matsim.api.core.v01.network.Link;
import static routing.disutility.components.Crossing.*;

Expand All @@ -8,9 +9,12 @@ public class JctStress {

public static double getStress(Link link, String mode) {

if((boolean) link.getAttributes().getAttribute("crossVehicles")) {
if(!mode.equals("walk") && !mode.equals("bike")) {
throw new RuntimeException("unknown mode " + mode);
} else if(!link.getAllowedModes().contains(mode)) {
return Double.NaN;
} else if((boolean) link.getAttributes().getAttribute("crossVehicles")) {
double stress = 0;

Double crossingAadt = (Double) link.getAttributes().getAttribute("crossAadt") * 0.865;
double crossingLanes = (double) link.getAttributes().getAttribute("crossLanes");
double crossingSpeed = (double) link.getAttributes().getAttribute("crossSpeedLimitMPH");
Expand All @@ -26,16 +30,25 @@ 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.;
}
} else if(crossingType.equals(PARALLEL)) {
} else if(crossingType.equals(ZEBRA)) {
if(crossingSpeed <= 30) {
stress = crossingAadt/24000 + crossingLanes/3 - 2./3;
} else {
stress = crossingSpeed/90 + 1./3;
}
} else if(crossingType.equals(SIGNAL)) {
} else if(crossingType.equals(SIGNAL_MIXED)) {
if(crossingSpeed < 60) {
stress = LinkStress.getStress(link,mode);
} else {
stress = 1.;
}
} else if(crossingType.equals(SIGNAL_ACTIVE)) {
if(crossingSpeed < 60) {
stress = 0;
} else {
Expand All @@ -44,20 +57,10 @@ public static double getStress(Link link, String mode) {
}

// Ensure between 0 and 1
if(stress < 0.) {
stress = 0;
} else if (stress > 1.) {
stress = 1;
}

// Compare to link stress (and take the highest)
double linkStress = LinkStress.getStress(link,mode);
if(stress < linkStress) {
return linkStress;
}
if (stress < 0.) stress = 0;
if (stress > 1.) stress = 1;

return stress;
}
return 0;
} else return 0;
}
}
89 changes: 43 additions & 46 deletions src/main/java/routing/disutility/components/LinkStress.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,61 +9,58 @@ public class LinkStress {

public static double getStress(Link link, String mode) {

if(!mode.equals("walk") && !mode.equals("bike")) {
if (!mode.equals("walk") && !mode.equals("bike")) {
throw new RuntimeException("unknown mode " + mode);
} else if(!link.getAllowedModes().contains(mode)) {
} else if (!link.getAllowedModes().contains(mode)) {
return Double.NaN;
} else {
double stress = 0;
if((boolean) link.getAttributes().getAttribute("allowsCar")) {
String junction = (String) link.getAttributes().getAttribute("junction");
if (mode.equals("bike") && (junction.equals("roundabout") || junction.equals("circular"))) {
stress = 1.;
} else {
double speedLimit = ((Integer) link.getAttributes().getAttribute("speedLimitMPH")).doubleValue();
double speed85perc = (double) link.getAttributes().getAttribute("veh85percSpeedKPH") * 0.621371;
double aadt = ((int) link.getAttributes().getAttribute("aadt")) * 0.865;
CycleProtection protection = CycleProtection.getType(link);
} else if ((boolean) link.getAttributes().getAttribute("allowsCar")) {
String junction = (String) link.getAttributes().getAttribute("junction");
if (mode.equals("bike") && (junction.equals("roundabout") || junction.equals("circular"))) {
return 1;
} else {
double stress;
double speedLimit = ((Integer) link.getAttributes().getAttribute("speedLimitMPH")).doubleValue();
double speed85perc = (double) link.getAttributes().getAttribute("veh85percSpeedKPH") * 0.621371;
double aadt = ((int) link.getAttributes().getAttribute("aadt")) * 0.865;
CycleProtection protection = CycleProtection.getType(link);

if (speed85perc >= speedLimit * 1.1) {
speedLimit = speed85perc;
}

if(speed85perc >= speedLimit*1.1) {
speedLimit = speed85perc;
}
double intercept;
double speedFactor;
double aadtFactor;

double intercept;
double speedFactor;
double aadtFactor;
if (protection.equals(OFFROAD)) {
intercept = 0;
speedFactor = 0;
aadtFactor = 0;
} else if (mode.equals("walk") || protection.equals(PROTECTED)) {
intercept = -1.5;
speedFactor = 0.05;
aadtFactor = 0;
} else if (protection.equals(LANE)) {
intercept = -1.625;
speedFactor = 0.0625;
aadtFactor = 0.000125;
} else {
intercept = -1.25;
speedFactor = 0.0583;
aadtFactor = 0.000167;
}

if(protection.equals(OFFROAD)) {
intercept = 0;
speedFactor = 0;
aadtFactor = 0;
} else if(mode.equals("walk") || protection.equals(PROTECTED)) {
intercept = -1.5;
speedFactor = 0.05;
aadtFactor = 0;
} else if (protection.equals(LANE)) {
intercept = -1.625;
speedFactor = 0.0625;
aadtFactor = 0.000125;
} else {
intercept = -1.25;
speedFactor = 0.0583;
aadtFactor = 0.000167;
}
double freightPoiFactor = getFreightPoiFactor(link);

double freightPoiFactor = getFreightPoiFactor(link);
stress = intercept + speedFactor * speedLimit + aadtFactor * aadt + 0.2 * freightPoiFactor;

stress = intercept + speedFactor * speedLimit + aadtFactor * aadt + 0.2 * freightPoiFactor;
// Ensure between 0 and 1
if (stress < 0.) stress = 0;
if (stress > 1.) stress = 1;

if(stress < 0.) {
stress = 0;
} else if (stress > 1.) {
stress = 1;
}
}
return stress;
}
return stress;
}
} else return 0;
}

public static double getFreightPoiFactor (Link link){
Expand Down

0 comments on commit 5645a31

Please sign in to comment.