21 package org.matsim.core.router.costcalculators;
30 import java.util.Random;
35 final class RandomizingTimeDistanceTravelDisutility
implements TravelDisutility {
37 private final TravelTime timeCalculator;
38 private final double marginalCostOfTime;
39 private final double marginalCostOfDistance;
41 private final double normalization ;
42 private final double sigma ;
44 private final Random random;
47 private double logNormalRnd;
48 private Person prevPerson;
50 RandomizingTimeDistanceTravelDisutility(
51 final TravelTime timeCalculator,
52 final double marginalCostOfTime_s,
53 final double marginalCostOfDistance_m,
54 final double normalization,
56 this.timeCalculator = timeCalculator;
57 this.marginalCostOfTime = marginalCostOfTime_s;
58 this.marginalCostOfDistance = marginalCostOfDistance_m;
59 this.normalization = normalization;
61 this.random = sigma != 0 ? MatsimRandom.getLocalInstance() : null;
65 public double getLinkTravelDisutility(
final Link link,
final double time,
final Person person,
final Vehicle vehicle) {
69 throw new RuntimeException(
"you cannot use the randomzing travel disutility without person. If you need this without a person, set" 70 +
" sigma to zero. If you are loading a scenario from a config, set the routingRandomness in the plansCalcRoute config group to zero.") ;
72 if ( person != prevPerson ) {
75 logNormalRnd = Math.exp( sigma * random.nextGaussian() ) ;
76 logNormalRnd *= normalization ;
90 person.getCustomAttributes().put(
"logNormalRnd", logNormalRnd ) ;
97 double travelTime = this.timeCalculator.getLinkTravelTime(link, time, person, vehicle);
98 return this.marginalCostOfTime * travelTime + logNormalRnd * this.marginalCostOfDistance * link.getLength();
102 public double getLinkMinimumTravelDisutility(
final Link link) {
103 return (link.getLength() / link.getFreespeed()) * this.marginalCostOfTime + this.marginalCostOfDistance * link.getLength();