Skip to content

Commit

Permalink
stress thresholds
Browse files Browse the repository at this point in the history
  • Loading branch information
CorinStaves committed May 25, 2024
1 parent d7d3491 commit 271123b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class AccessibilityProperties {

public static final String MODE = "mode";
public static final String IMPEDANCE = "disutility";
public static final String CYCLE_STRESS_THRESHOLD = "stress.limit";
public static final String END_LOCATIONS = "end.coords";
public static final String END_DESCRIPTION = "end.description";
public static final String END_ALPHA = "end.alpha";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import routing.Bicycle;
import routing.disutility.DistanceDisutility;
import routing.disutility.JibeDisutility3;
import routing.travelTime.BicycleTravelTime;
import routing.travelTime.WalkTravelTime;
import trip.Purpose;

Expand Down Expand Up @@ -58,6 +59,10 @@ public static void initializeResources(String propertiesFile) {
Bicycle bicycle = new Bicycle(instance.config);
instance.veh = bicycle.getVehicle();
instance.tt = bicycle.getTravelTime();
String stressThreshold = properties.getProperty(AccessibilityProperties.CYCLE_STRESS_THRESHOLD);
if(stressThreshold != null) {
((BicycleTravelTime) instance.tt).setLinkStressThreshold(stressThreshold);
}
instance.setActiveDisutility();
break;
case TransportMode.walk:
Expand Down
25 changes: 23 additions & 2 deletions src/main/java/routing/travelTime/BicycleTravelTime.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,54 @@
package routing.travelTime;

import com.google.inject.Inject;
import org.apache.log4j.Logger;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.population.Person;
import org.matsim.contrib.bicycle.BicycleLinkSpeedCalculator;
import org.matsim.core.router.util.TravelTime;
import org.matsim.vehicles.Vehicle;
import routing.disutility.components.LinkStressDiscrete;

import static routing.disutility.components.LinkStressDiscrete.*;

/**
* @author dziemke
*/
public class BicycleTravelTime implements TravelTime {

@Inject
private BicycleLinkSpeedCalculator linkSpeedCalculator;
private WalkTravelTime dismountTravelTime = new WalkTravelTime();
private static final Logger logger = Logger.getLogger(BicycleTravelTime.class);
private final BicycleLinkSpeedCalculator linkSpeedCalculator;
private final WalkTravelTime dismountTravelTime = new WalkTravelTime();
private LinkStressDiscrete stressThreshold = null;

@Inject
public BicycleTravelTime(BicycleLinkSpeedCalculator calculator) {
this.linkSpeedCalculator = calculator;
}

public void setLinkStressThreshold(String threshold) {
this.stressThreshold = LinkStressDiscrete.valueOf(threshold.toUpperCase());
logger.info("Set bicycle stress threshold to " + this.stressThreshold);
}

@Override
public double getLinkTravelTime(Link link, double time, Person person, Vehicle vehicle) {

if((boolean) link.getAttributes().getAttribute("dismount")) {
return dismountTravelTime.getLinkTravelTime(link,time,person,vehicle);
}

if(stressThreshold != null) {
LinkStressDiscrete stress = LinkStressDiscrete.getCycleStress(link);
assert stress != null;
if((AMBER.equals(stressThreshold) && stress.equals(RED)) ||
(GREEN.equals(stressThreshold) && stress.equals(RED)) ||
(GREEN.equals(stressThreshold) && stress.equals(AMBER))) {
return dismountTravelTime.getLinkTravelTime(link,time,person,vehicle);
}
}

return link.getLength() / linkSpeedCalculator.getMaximumVelocityForLink(link, vehicle);
}
}

0 comments on commit 271123b

Please sign in to comment.