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