View Javadoc
1   package org.opentrafficsim.core.definitions;
2   
3   import java.util.Locale;
4   import java.util.Optional;
5   import java.util.function.BiFunction;
6   
7   import org.djunits.unit.SpeedUnit;
8   import org.djunits.value.vdouble.scalar.Length;
9   import org.djunits.value.vdouble.scalar.Speed;
10  import org.opentrafficsim.core.distributions.ConstantSupplier;
11  import org.opentrafficsim.core.gtu.GtuTemplate;
12  import org.opentrafficsim.core.gtu.GtuType;
13  import org.opentrafficsim.core.network.LinkType;
14  import org.opentrafficsim.core.object.DetectorType;
15  import org.opentrafficsim.core.units.distributions.ContinuousDistSpeed;
16  
17  import nl.tudelft.simulation.jstats.distributions.DistNormal;
18  import nl.tudelft.simulation.jstats.streams.StreamInterface;
19  
20  /**
21   * Defaults for locale nl_NL.
22   * <p>
23   * Copyright (c) 2022-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
24   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
25   * </p>
26   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
27   * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
28   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
29   */
30  public final class DefaultsNl extends Defaults implements BiFunction<GtuType, StreamInterface, Optional<GtuTemplate>>
31  {
32  
33      /**
34       * Constructor setting locale nl_NL.
35       */
36      DefaultsNl()
37      {
38          super(new Locale("nl", "NL"));
39      }
40  
41      /***************************************************************************************/
42      /***************************************** GTU *****************************************/
43      /***************************************************************************************/
44  
45      /** Super type for all road users. */
46      public static final GtuType ROAD_USER = new GtuType("NL.ROAD_USER");
47  
48      /** Super type for pedestrians. */
49      public static final GtuType PEDESTRIAN = new GtuType("NL.PEDESTRIAN", ROAD_USER);
50  
51      /** Super type for bicycle. */
52      public static final GtuType BICYCLE = new GtuType("NL.BICYCLE", ROAD_USER);
53  
54      /** Super type for mopeds. */
55      public static final GtuType MOPED = new GtuType("NL.MOPED", BICYCLE);
56  
57      /** Super type for vehicles. */
58      public static final GtuType VEHICLE = new GtuType("NL.VEHICLE", ROAD_USER);
59  
60      /** Super type for emergency vehicles. */
61      public static final GtuType EMERGENCY_VEHICLE = new GtuType("NL.EMERGENCY_VEHICLE", VEHICLE);
62  
63      /** Super type for cars. */
64      public static final GtuType CAR = new GtuType("NL.CAR", VEHICLE);
65  
66      /** Super type for motorcycles. */
67      public static final GtuType MOTORCYCLE = new GtuType("NL.MOTORCYCLE", VEHICLE);
68  
69      /** Super type for vans. */
70      public static final GtuType VAN = new GtuType("NL.VAN", VEHICLE);
71  
72      /** Super type for busses. */
73      public static final GtuType BUS = new GtuType("NL.BUS", VEHICLE);
74  
75      /** Super type for trucks. */
76      public static final GtuType TRUCK = new GtuType("NL.TRUCK", VEHICLE);
77  
78      /** Super type for scheduled busses. */
79      public static final GtuType SCHEDULED_BUS = new GtuType("NL.SCHEDULED_BUS", BUS);
80  
81      /**
82       * Returns a template for the given GTU type. This can be defined at the level of super types, returning {@code null} for
83       * more specific types. There is no need to define a template for all default types defined for a locale, so long as at
84       * least one parent of each type has a template defined.<br>
85       * <br>
86       * Note: implementations should not cache the template per GTU type, as different simulations may request templates for the
87       * same GTU type, while having their separate random streams.
88       * @param gtuType GTU type
89       * @param randomStream random stream
90       * @return template, empty if no default is defined
91       */
92      @Override
93      public Optional<GtuTemplate> apply(final GtuType gtuType, final StreamInterface randomStream)
94      {
95          return Optional.ofNullable(apply(gtuType, gtuType, randomStream));
96      }
97  
98      /**
99       * Local implementation that will loop the parent types until a known type is encountered.
100      * @param gtuType (parent) GTU type
101      * @param originalGtuType original request GTU type (will be part of the characteristics)
102      * @param randomStream random stream
103      * @return template, {@code null} if no default is defined
104      */
105     private GtuTemplate apply(final GtuType gtuType, final GtuType originalGtuType, final StreamInterface randomStream)
106     {
107         if (gtuType.equals(CAR))
108         {
109             // from "Maatgevende normen in de Nederlandse richtlijnen voor wegontwerp", R-2014-38, SWOV
110             return new GtuTemplate(originalGtuType, new ConstantSupplier<>(Length.ofSI(4.19)),
111                     new ConstantSupplier<>(Length.ofSI(1.7)), new ConstantSupplier<>(new Speed(180, SpeedUnit.KM_PER_HOUR)));
112         }
113         else if (gtuType.equals(TRUCK))
114         {
115             // from "Maatgevende normen in de Nederlandse richtlijnen voor wegontwerp", R-2014-38, SWOV
116             return new GtuTemplate(originalGtuType, new ConstantSupplier<>(Length.ofSI(12.0)),
117                     new ConstantSupplier<>(Length.ofSI(2.55)),
118                     new ContinuousDistSpeed(new DistNormal(randomStream, 85.0, 2.5), SpeedUnit.KM_PER_HOUR));
119         }
120         else if (gtuType.equals(BUS))
121         {
122             return new GtuTemplate(originalGtuType, new ConstantSupplier<>(Length.ofSI(12.0)),
123                     new ConstantSupplier<>(Length.ofSI(2.55)), new ConstantSupplier<>(new Speed(90, SpeedUnit.KM_PER_HOUR)));
124         }
125         else if (gtuType.equals(VAN))
126         {
127             return new GtuTemplate(originalGtuType, new ConstantSupplier<>(Length.ofSI(5.0)),
128                     new ConstantSupplier<>(Length.ofSI(2.4)), new ConstantSupplier<>(new Speed(180, SpeedUnit.KM_PER_HOUR)));
129         }
130         else if (gtuType.equals(EMERGENCY_VEHICLE))
131         {
132             return new GtuTemplate(originalGtuType, new ConstantSupplier<>(Length.ofSI(5.0)),
133                     new ConstantSupplier<>(Length.ofSI(2.55)), new ConstantSupplier<>(new Speed(180, SpeedUnit.KM_PER_HOUR)));
134         }
135         else if (gtuType.equals(MOTORCYCLE))
136         {
137             // Yamaha R7 2022
138             return new GtuTemplate(originalGtuType, new ConstantSupplier<>(Length.ofSI(2.1)),
139                     new ConstantSupplier<>(Length.ofSI(0.7)), new ConstantSupplier<>(new Speed(180, SpeedUnit.KM_PER_HOUR)));
140         }
141         else if (gtuType.equals(BICYCLE))
142         {
143             // length/width: https://www.verderfietsen.nl/fiets-afmetingen/
144             // width: https://www.fietsberaad.nl/CROWFietsberaad/media/Kennis/Bestanden/document000172.pdf?ext=.pdf
145             return new GtuTemplate(originalGtuType, new ConstantSupplier<>(Length.ofSI(1.9)),
146                     new ConstantSupplier<>(Length.ofSI(0.6)), new ConstantSupplier<>(new Speed(35, SpeedUnit.KM_PER_HOUR)));
147         }
148         else if (gtuType.getParent().isPresent())
149         {
150             return apply(gtuType.getParent().get(), originalGtuType, randomStream);
151         }
152         return null;
153     }
154 
155     /***************************************************************************************/
156     /**************************************** LINK *****************************************/
157     /***************************************************************************************/
158 
159     /** Connector type. */
160     public static final LinkType CONNECTOR = new LinkType("NL.CONNECTOR");
161 
162     /** Super type for all roads. */
163     public static final LinkType ROAD = new LinkType("NL.ROAD");
164 
165     /** Freeway (snelweg, 130km/h). */
166     public static final LinkType FREEWAY = new LinkType("NL.FREEWAY", ROAD);
167 
168     /** Highway (autoweg, 100km/h). */
169     public static final LinkType HIGHWAY = new LinkType("NL.HIGHWAY", ROAD);
170 
171     /** Provincial (provinciaalse weg / N-weg, 80km/h). */
172     public static final LinkType PROVINCIAL = new LinkType("NL.PROVINCIAL", ROAD);
173 
174     /** Rural (landelijk, 60km/h). */
175     public static final LinkType RURAL = new LinkType("NL.RURAL", ROAD);
176 
177     /** Urban (stedelijk, 50km/h). */
178     public static final LinkType URBAN = new LinkType("NL.URBAN", ROAD);
179 
180     /** Residential (buurtweg, 30km/h). */
181     public static final LinkType RESIDENTIAL = new LinkType("NL.RESIDENTIAL", ROAD);
182 
183     static
184     {
185         CONNECTOR.addCompatibleGtuType(ROAD_USER);
186         ROAD.addCompatibleGtuType(ROAD_USER);
187         FREEWAY.addIncompatibleGtuType(PEDESTRIAN);
188         FREEWAY.addIncompatibleGtuType(BICYCLE);
189         HIGHWAY.addIncompatibleGtuType(PEDESTRIAN);
190         HIGHWAY.addIncompatibleGtuType(BICYCLE);
191         PROVINCIAL.addIncompatibleGtuType(PEDESTRIAN);
192         PROVINCIAL.addIncompatibleGtuType(BICYCLE);
193     }
194 
195     /***************************************************************************************/
196     /************************************** DETECTOR ***************************************/
197     /***************************************************************************************/
198 
199     /** Makes a Detector compatible with all road users, e.g. for SinkDetector. */
200     public static final DetectorType ROAD_USERS = new DetectorType("NL.ROAD_USERS");
201 
202     /** Makes a Detector compatible with all vehicles, e.g. for loop detectors. */
203     public static final DetectorType VEHICLES = new DetectorType("NL.VEHICLES");
204 
205     /** Loop detector type. */
206     public static final DetectorType LOOP_DETECTOR = new DetectorType("NL.LOOP_DETECTOR", VEHICLES);
207 
208     /** Traffic light detector type. */
209     public static final DetectorType TRAFFIC_LIGHT = new DetectorType("NL.TRAFFIC_LIGHT", LOOP_DETECTOR);
210 
211     static
212     {
213         ROAD_USERS.addCompatibleGtuType(DefaultsNl.ROAD_USER);
214         VEHICLES.addCompatibleGtuType(DefaultsNl.VEHICLE);
215         TRAFFIC_LIGHT.addCompatibleGtuType(DefaultsNl.BICYCLE);
216     }
217 
218 }