View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical.toledo;
2   
3   import static org.opentrafficsim.core.gtu.behavioralcharacteristics.AbstractParameterType.Check.NEGATIVE;
4   import static org.opentrafficsim.core.gtu.behavioralcharacteristics.AbstractParameterType.Check.POSITIVE;
5   
6   import java.util.SortedMap;
7   
8   import org.djunits.unit.AccelerationUnit;
9   import org.djunits.unit.DurationUnit;
10  import org.djunits.unit.LengthUnit;
11  import org.djunits.unit.SpeedUnit;
12  import org.djunits.value.vdouble.scalar.Acceleration;
13  import org.djunits.value.vdouble.scalar.Duration;
14  import org.djunits.value.vdouble.scalar.Length;
15  import org.djunits.value.vdouble.scalar.Speed;
16  import org.opentrafficsim.core.gtu.behavioralcharacteristics.BehavioralCharacteristics;
17  import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterException;
18  import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterTypeDouble;
19  import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterTypeDuration;
20  import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterTypeSpeed;
21  import org.opentrafficsim.road.gtu.lane.tactical.following.AbstractCarFollowingModel;
22  import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
23  
24  /**
25   * <p>
26   * Copyright (c) 2013-2017 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
27   * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
28   * <p>
29   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Jul 7, 2016 <br>
30   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
31   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
32   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
33   */
34  
35  public class ToledoCarFollowing extends AbstractCarFollowingModel
36  {
37  
38      /** */
39      public static final ParameterTypeSpeed CDS =
40              new ParameterTypeSpeed("C_DS", "Constant in desired speed.", new Speed(17.636, SpeedUnit.SI), POSITIVE);
41  
42      /** */
43      public static final ParameterTypeSpeed BETADS = new ParameterTypeSpeed("BETA_DS", "Reduction of desired speed for trucks.",
44              new Speed(-1.458, SpeedUnit.SI), NEGATIVE);
45  
46      /** */
47      public static final ParameterTypeSpeed ALPHADS =
48              new ParameterTypeSpeed("ALPHA_DS", "Factor on error term of desired speed.", new Speed(-0.105, SpeedUnit.SI));
49  
50      /** */
51      public static final ParameterTypeDuration HSTAR =
52              new ParameterTypeDuration("h*", "Desired time headway.", new Duration(2.579, DurationUnit.SI));
53  
54      /** */
55      public static final ParameterTypeDouble LAMBDAFF =
56              new ParameterTypeDouble("Lambda_ff", "Free flow acceleration sensitivity.", 0.0881, POSITIVE);
57  
58      /** */
59      public static final ParameterTypeDouble SIGMAFF =
60              new ParameterTypeDouble("Sigma_ff", "Free flow acceleration standard deviation.", Math.exp(0.169));
61  
62      /** */
63      public static final ParameterTypeDouble CCFACC =
64              new ParameterTypeDouble("C_CF_ACC", "Constant for car following acceleration.", 0.0355, POSITIVE);
65  
66      /** */
67      public static final ParameterTypeDouble BETAACC =
68              new ParameterTypeDouble("BETA_ACC", "Power on speed for acceleration.", 0.291, POSITIVE);
69  
70      /** */
71      public static final ParameterTypeDouble GAMMAACC =
72              new ParameterTypeDouble("GAMMA_ACC", "Power on distance headway for acceleration.", -0.166, NEGATIVE);
73  
74      /** */
75      public static final ParameterTypeDouble RHOACC =
76              new ParameterTypeDouble("RHO_ACC", "Power on density for acceleration.", 0.550, POSITIVE);
77  
78      /** */
79      public static final ParameterTypeDouble LAMBDAACC =
80              new ParameterTypeDouble("LAMBDA_ACC", "Power on speed difference for acceleration.", 0.520, POSITIVE);
81  
82      /** */
83      public static final ParameterTypeDouble SIGMAACC =
84              new ParameterTypeDouble("Sigma_acc", "Car-following acceleration standard deviation.", Math.exp(0.126));
85  
86      /** */
87      public static final ParameterTypeDouble CCFDEC =
88              new ParameterTypeDouble("C_CF_DEC", "Constant for car following deceleration.", -0.860, NEGATIVE);
89  
90      /** */
91      public static final ParameterTypeDouble GAMMADEC =
92              new ParameterTypeDouble("GAMMA_DEC", "Power on distance headway for deceleration.", -0.565, NEGATIVE);
93  
94      /** */
95      public static final ParameterTypeDouble RHODEC =
96              new ParameterTypeDouble("RHO_DEC", "Power on density for deceleration.", 0.143, POSITIVE);
97  
98      /** */
99      public static final ParameterTypeDouble LAMBDADEC =
100             new ParameterTypeDouble("LAMBDA_DEC", "Power on speed difference for deceleration.", 0.834, POSITIVE);
101 
102     /** */
103     public static final ParameterTypeDouble SIGMADEC =
104             new ParameterTypeDouble("Sigma_DEC", "Car-following deceleration standard deviation.", Math.exp(0.156));
105 
106     /** {@inheritDoc} */
107     @Override
108     public final Speed desiredSpeed(final BehavioralCharacteristics behavioralCharacteristics, final SpeedLimitInfo speedInfo)
109             throws ParameterException
110     {
111         return behavioralCharacteristics.getParameter(CDS).plus(behavioralCharacteristics.getParameter(BETADS))
112                 .plus(behavioralCharacteristics.getParameter(ALPHADS)
113                         .multiplyBy(behavioralCharacteristics.getParameter(ToledoLaneChangeParameters.ERROR_TERM)));
114     }
115 
116     /** {@inheritDoc} */
117     @Override
118     public final Length desiredHeadway(final BehavioralCharacteristics behavioralCharacteristics, final Speed speed)
119             throws ParameterException
120     {
121         return behavioralCharacteristics.getParameter(HSTAR).multiplyBy(speed);
122     }
123 
124     /** {@inheritDoc} */
125     @Override
126     protected final Acceleration followingAcceleration(final BehavioralCharacteristics behavioralCharacteristics,
127             final Speed speed, final Speed desiredSpeed, final Length desiredHeadway, final SortedMap<Length, Speed> leaders)
128             throws ParameterException
129     {
130         if (leaders.isEmpty() || leaders.firstKey().gt(desiredHeadway))
131         {
132             // free
133             double eff = Toledo.RANDOM.nextGaussian() * behavioralCharacteristics.getParameter(SIGMAFF)
134                     * behavioralCharacteristics.getParameter(SIGMAFF);
135             return new Acceleration(behavioralCharacteristics.getParameter(LAMBDAFF) * (desiredSpeed.si - speed.si) + eff,
136                     AccelerationUnit.SI);
137         }
138         // TODO speed difference with reaction time
139         if (leaders.get(leaders.firstKey()).ge(speed))
140         {
141             // accelerate
142             double eCfAcc = Toledo.RANDOM.nextGaussian() * behavioralCharacteristics.getParameter(SIGMAACC)
143                     * behavioralCharacteristics.getParameter(SIGMAACC);
144             // {@formatter:off}
145             return new Acceleration(
146                 behavioralCharacteristics.getParameter(CCFACC) 
147                     * Math.pow(speed.si, behavioralCharacteristics.getParameter(BETAACC))
148                     * Math.pow(leaders.firstKey().si, behavioralCharacteristics.getParameter(GAMMAACC))
149                     * Math.pow(getDensity(leaders), behavioralCharacteristics.getParameter(RHOACC))
150                     * Math.pow(leaders.get(leaders.firstKey()).si - speed.si, behavioralCharacteristics.getParameter(LAMBDAACC))
151                     + eCfAcc,
152                 AccelerationUnit.SI);
153             // {@formatter:on}
154         }
155         // decelerate
156         double eCfDec = Toledo.RANDOM.nextGaussian() * behavioralCharacteristics.getParameter(SIGMADEC)
157                 * behavioralCharacteristics.getParameter(SIGMADEC);
158         // {@formatter:off}
159         return new Acceleration(
160             behavioralCharacteristics.getParameter(CCFDEC) 
161                 * Math.pow(leaders.firstKey().si, behavioralCharacteristics.getParameter(GAMMADEC))
162                 * Math.pow(getDensity(leaders), behavioralCharacteristics.getParameter(RHODEC))
163                 * Math.pow(speed.si - leaders.get(leaders.firstKey()).si, behavioralCharacteristics.getParameter(LAMBDADEC))
164                 + eCfDec,
165             AccelerationUnit.SI);
166         // {@formatter:on}
167     }
168 
169     /** {@inheritDoc} */
170     @Override
171     public final String getName()
172     {
173         return "ToledoCFM";
174     }
175 
176     /** {@inheritDoc} */
177     @Override
178     public final String getLongName()
179     {
180         return "Toledo car-following model";
181     }
182 
183     /**
184      * Returns the density based on the leaders in veh/km.
185      * @param leaders leading vehicles
186      * @return density based on the leaders in veh/km
187      */
188     private double getDensity(final SortedMap<Length, Speed> leaders)
189     {
190         if (leaders.isEmpty())
191         {
192             return 0;
193         }
194         return leaders.lastKey().getInUnit(LengthUnit.KILOMETER) / leaders.size();
195     }
196 
197 }