MATSIM
FreespeedTravelTimeAndDisutility.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * FreespeedTravelTimeCost.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2007 by the members listed in the COPYING, *
8  * LICENSE and WARRANTY file. *
9  * email : info at matsim dot org *
10  * *
11  * *********************************************************************** *
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * See also COPYING, LICENSE and WARRANTY file *
18  * *
19  * *********************************************************************** */
20 
21 package org.matsim.core.router.costcalculators;
22 
23 import org.apache.logging.log4j.LogManager;
24 import org.apache.logging.log4j.Logger;
29 import org.matsim.core.gbl.Gbl;
33 import org.matsim.vehicles.Vehicle;
34 
49 
50  private static final Logger log = LogManager.getLogger(FreespeedTravelTimeAndDisutility.class);
51 
52  private final double travelCostFactor;
53  private final double marginalUtlOfDistance;
54  private static int wrnCnt = 0 ;
61  public FreespeedTravelTimeAndDisutility(double scaledMarginalUtilityOfTraveling, double scaledMarginalUtilityOfPerforming,
62  double scaledMarginalUtilityOfDistance){
63  // usually, the travel-utility should be negative (it's a disutility)
64  // but for the cost, the cost should be positive.
65  this.travelCostFactor = -scaledMarginalUtilityOfTraveling + scaledMarginalUtilityOfPerforming;
66 
67  if ( wrnCnt < 1 ) {
68  wrnCnt++ ;
69  if (this.travelCostFactor <= 0) {
70  log.warn("The travel cost in " + this.getClass().getName() + " under normal circumstances should be > 0. " +
71  "Currently, it is " + this.travelCostFactor + "." +
72  "That is the sum of the costs for traveling and the opportunity costs." +
73  " Please adjust the parameters" +
74  "'traveling' and 'performing' in the module 'planCalcScore' in your config file to be" +
75  " lower or equal than 0 when added.");
76  log.warn(Gbl.ONLYONCE) ;
77  }
78  }
79 
80  this.marginalUtlOfDistance = scaledMarginalUtilityOfDistance;
81  }
82 
84  this(cnScoringGroup.getModes().get(TransportMode.car).getMarginalUtilityOfTraveling() / 3600.0, cnScoringGroup.getPerforming_utils_hr() / 3600.0,
85 // cnScoringGroup.getMarginalUtlOfDistanceCar());
86  cnScoringGroup.getModes().get(TransportMode.car).getMonetaryDistanceRate() *cnScoringGroup.getMarginalUtilityOfMoney());
87  }
88 
89  @Override
90  public double getLinkTravelDisutility(final Link link, final double time, final Person person, final Vehicle vehicle) {
91  if (this.marginalUtlOfDistance == 0.0) {
92  return (link.getLength() / link.getFreespeed(time)) * this.travelCostFactor;
93  }
94  return (link.getLength() / link.getFreespeed(time)) * this.travelCostFactor - this.marginalUtlOfDistance * link.getLength();
95  }
96 
97  @Override
98  public double getLinkMinimumTravelDisutility(Link link) {
99  if (this.marginalUtlOfDistance == 0.0) {
100  return (link.getLength() / link.getFreespeed()) * this.travelCostFactor;
101  }
102  return (link.getLength() / link.getFreespeed()) * this.travelCostFactor
103  - this.marginalUtlOfDistance * link.getLength();
104  }
105 
106  @Override
107  public double getLinkTravelTime(Link link, double time, Person person, Vehicle vehicle) {
108  return link.getLength() / link.getFreespeed(time);
109  }
110 
114  @Override
115  public double getLinkToLinkTravelTime(Link fromLink, Link toLink, double time, Person person, Vehicle vehicle) {
116  return this.getLinkTravelTime(fromLink, time, null, null);
117  }
118 
119 }
FreespeedTravelTimeAndDisutility(double scaledMarginalUtilityOfTraveling, double scaledMarginalUtilityOfPerforming, double scaledMarginalUtilityOfDistance)
static final String ONLYONCE
Definition: Gbl.java:42
double getLinkToLinkTravelTime(Link fromLink, Link toLink, double time, Person person, Vehicle vehicle)
double getLinkTravelDisutility(final Link link, final double time, final Person person, final Vehicle vehicle)
double getLinkTravelTime(Link link, double time, Person person, Vehicle vehicle)