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.LengthUnit;
10  import org.djunits.unit.SpeedUnit;
11  import org.djunits.unit.TimeUnit;
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-2016 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 = new ParameterTypeSpeed("C_DS", "Constant in desired speed.", new Speed(
40          17.636, SpeedUnit.SI), POSITIVE);
41  
42      /** */
43      public static final ParameterTypeSpeed BETADS = new ParameterTypeSpeed("BETA_DS",
44          "Reduction of desired speed for trucks.", new Speed(-1.458, SpeedUnit.SI), NEGATIVE);
45  
46      /** */
47      public static final ParameterTypeSpeed ALPHADS = new ParameterTypeSpeed("ALPHA_DS",
48          "Factor on error term of desired speed.", new Speed(-0.105, SpeedUnit.SI));
49  
50      /** */
51      public static final ParameterTypeDuration HSTAR = new ParameterTypeDuration("h*", "Desired time headway.", new Duration(
52          2.579, TimeUnit.SI));
53  
54      /** */
55      public static final ParameterTypeDouble LAMBDAFF = new ParameterTypeDouble("Lambda_ff",
56          "Free flow acceleration sensitivity.", 0.0881, POSITIVE);
57  
58      /** */
59      public static final ParameterTypeDouble SIGMAFF = new ParameterTypeDouble("Sigma_ff",
60          "Free flow acceleration standard deviation.", Math.exp(0.169));
61  
62      /** */
63      public static final ParameterTypeDouble CCFACC = new ParameterTypeDouble("C_CF_ACC",
64          "Constant for car following acceleration.", 0.0355, POSITIVE);
65  
66      /** */
67      public static final ParameterTypeDouble BETAACC = new ParameterTypeDouble("BETA_ACC",
68          "Power on speed for acceleration.", 0.291, POSITIVE);
69  
70      /** */
71      public static final ParameterTypeDouble GAMMAACC = new ParameterTypeDouble("GAMMA_ACC",
72          "Power on distance headway for acceleration.", -0.166, NEGATIVE);
73  
74      /** */
75      public static final ParameterTypeDouble RHOACC = new ParameterTypeDouble("RHO_ACC",
76          "Power on density for acceleration.", 0.550, POSITIVE);
77  
78      /** */
79      public static final ParameterTypeDouble LAMBDAACC = new ParameterTypeDouble("LAMBDA_ACC",
80          "Power on speed difference for acceleration.", 0.520, POSITIVE);
81  
82      /** */
83      public static final ParameterTypeDouble SIGMAACC = new ParameterTypeDouble("Sigma_acc",
84          "Car-following acceleration standard deviation.", Math.exp(0.126));
85  
86      /** */
87      public static final ParameterTypeDouble CCFDEC = new ParameterTypeDouble("C_CF_DEC",
88          "Constant for car following deceleration.", -0.860, NEGATIVE);
89  
90      /** */
91      public static final ParameterTypeDouble GAMMADEC = new ParameterTypeDouble("GAMMA_DEC",
92          "Power on distance headway for deceleration.", -0.565, NEGATIVE);
93  
94      /** */
95      public static final ParameterTypeDouble RHODEC = new ParameterTypeDouble("RHO_DEC",
96          "Power on density for deceleration.", 0.143, POSITIVE);
97  
98      /** */
99      public static final ParameterTypeDouble LAMBDADEC = new ParameterTypeDouble("LAMBDA_DEC",
100         "Power on speed difference for deceleration.", 0.834, POSITIVE);
101 
102     /** */
103     public static final ParameterTypeDouble SIGMADEC = new ParameterTypeDouble("Sigma_DEC",
104         "Car-following deceleration standard deviation.", Math.exp(0.156));
105 
106     /** {@inheritDoc} */
107     @Override
108     public final Speed
109         desiredSpeed(final BehavioralCharacteristics behavioralCharacteristics, final SpeedLimitInfo speedInfo)
110             throws ParameterException
111     {
112         return behavioralCharacteristics.getParameter(CDS).plus(behavioralCharacteristics.getParameter(BETADS)).plus(
113             behavioralCharacteristics.getParameter(ALPHADS).multiplyBy(
114                 behavioralCharacteristics.getParameter(ToledoLaneChangeParameters.ERROR_TERM)));
115     }
116 
117     /** {@inheritDoc} */
118     @Override
119     public final Length desiredHeadway(final BehavioralCharacteristics behavioralCharacteristics, final Speed speed)
120         throws ParameterException
121     {
122         return behavioralCharacteristics.getParameter(HSTAR).multiplyBy(speed);
123     }
124 
125     /** {@inheritDoc} */
126     @Override
127     protected final Acceleration followingAcceleration(final BehavioralCharacteristics behavioralCharacteristics,
128         final Speed speed, final Speed desiredSpeed, final Length desiredHeadway, final SortedMap<Length, Speed> leaders)
129         throws ParameterException
130     {
131         if (leaders.isEmpty() || leaders.firstKey().gt(desiredHeadway))
132         {
133             // free
134             double eff =
135                 Toledo.RANDOM.nextGaussian() * behavioralCharacteristics.getParameter(SIGMAFF)
136                     * behavioralCharacteristics.getParameter(SIGMAFF);
137             return new Acceleration(behavioralCharacteristics.getParameter(LAMBDAFF) * (desiredSpeed.si - speed.si) + eff,
138                 AccelerationUnit.SI);
139         }
140         // TODO speed difference with reaction time
141         if (leaders.get(leaders.firstKey()).ge(speed))
142         {
143             // accelerate
144             double eCfAcc =
145                 Toledo.RANDOM.nextGaussian() * behavioralCharacteristics.getParameter(SIGMAACC)
146                     * behavioralCharacteristics.getParameter(SIGMAACC);
147             // {@formatter:off}
148             return new Acceleration(
149                 behavioralCharacteristics.getParameter(CCFACC) 
150                     * Math.pow(speed.si, behavioralCharacteristics.getParameter(BETAACC))
151                     * Math.pow(leaders.firstKey().si, behavioralCharacteristics.getParameter(GAMMAACC))
152                     * Math.pow(getDensity(leaders), behavioralCharacteristics.getParameter(RHOACC))
153                     * Math.pow(leaders.get(leaders.firstKey()).si - speed.si, behavioralCharacteristics.getParameter(LAMBDAACC))
154                     + eCfAcc,
155                 AccelerationUnit.SI);
156             // {@formatter:on}
157         }
158         // decelerate
159         double eCfDec =
160             Toledo.RANDOM.nextGaussian() * behavioralCharacteristics.getParameter(SIGMADEC)
161                 * behavioralCharacteristics.getParameter(SIGMADEC);
162         // {@formatter:off}
163         return new Acceleration(
164             behavioralCharacteristics.getParameter(CCFDEC) 
165                 * Math.pow(leaders.firstKey().si, behavioralCharacteristics.getParameter(GAMMADEC))
166                 * Math.pow(getDensity(leaders), behavioralCharacteristics.getParameter(RHODEC))
167                 * Math.pow(speed.si - leaders.get(leaders.firstKey()).si, behavioralCharacteristics.getParameter(LAMBDADEC))
168                 + eCfDec,
169             AccelerationUnit.SI);
170         // {@formatter:on}
171     }
172 
173     /** {@inheritDoc} */
174     @Override
175     public final String getName()
176     {
177         return "ToledoCFM";
178     }
179 
180     /** {@inheritDoc} */
181     @Override
182     public final String getLongName()
183     {
184         return "Toledo car-following model";
185     }
186 
187     /**
188      * Returns the density based on the leaders in veh/km.
189      * @param leaders leading vehicles
190      * @return density based on the leaders in veh/km
191      */
192     private double getDensity(final SortedMap<Length, Speed> leaders)
193     {
194         if (leaders.isEmpty())
195         {
196             return 0;
197         }
198         return leaders.lastKey().getInUnit(LengthUnit.KILOMETER) / leaders.size();
199     }
200 
201 }