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-2023 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://dittlab.tudelft.nl">Wouter Schakel</a>
33   */
34  public final class DefaultsNl extends Defaults implements BiFunction<GtuType, StreamInterface, GtuTemplate>
35  {
36  
37      // TODO: prepend all type id's with "NL."
38  
39      /**
40       * Constructor setting locale nl_NL.
41       */
42      DefaultsNl()
43      {
44          super(new Locale("nl", "NL"));
45      }
46  
47      /***************************************************************************************/
48      /***************************************** GTU *****************************************/
49      /***************************************************************************************/
50  
51      /** This is here only because it is in the file default_gtutypes.xml as a default, i.e the parser needs to find it. */
52      @Deprecated
53      public static final GtuType NONE = new GtuType("NONE");
54  
55      /** Super type for all road users. */
56      public static final GtuType ROAD_USER = new GtuType("ROAD_USER");
57  
58      /** Super type for all water way users. */
59      public static final GtuType WATERWAY_USER = new GtuType("WATERWAY_USER");
60  
61      /** Super type for all rail users. */
62      public static final GtuType RAILWAY_USER = new GtuType("RAILWAY_USER");
63  
64      /** Super type for pedestrians. */
65      public static final GtuType PEDESTRIAN = new GtuType("PEDESTRIAN", ROAD_USER);
66  
67      /** Super type for bicycle. */
68      public static final GtuType BICYCLE = new GtuType("BICYCLE", ROAD_USER);
69  
70      /** Super type for mopeds. */
71      public static final GtuType MOPED = new GtuType("MOPED", BICYCLE);
72  
73      /** Super type for vehicles. */
74      public static final GtuType VEHICLE = new GtuType("VEHICLE", ROAD_USER);
75  
76      /** Super type for emergency vehicles. */
77      public static final GtuType EMERGENCY_VEHICLE = new GtuType("EMERGENCY_VEHICLE", VEHICLE);
78  
79      /** Super type for ships. */
80      public static final GtuType SHIP = new GtuType("SHIP", WATERWAY_USER);
81  
82      /** Super type for trains. */
83      public static final GtuType TRAIN = new GtuType("TRAIN", RAILWAY_USER);
84  
85      /** Super type for cars. */
86      public static final GtuType CAR = new GtuType("CAR", VEHICLE);
87  
88      /** Super type for vans. */
89      public static final GtuType VAN = new GtuType("VAN", VEHICLE);
90  
91      /** Super type for busses. */
92      public static final GtuType BUS = new GtuType("BUS", VEHICLE);
93  
94      /** Super type for trucks. */
95      public static final GtuType TRUCK = new GtuType("TRUCK", VEHICLE);
96  
97      /** Super type for scheduled busses. */
98      public static final GtuType SCHEDULED_BUS = new GtuType("SCHEDULED_BUS", BUS);
99  
100     /** Standard drawing colors for GTU types. */
101     public static final ImmutableMap<GtuType, Color> GTU_TYPE_COLORS;
102 
103     static
104     {
105         LinkedHashMap<GtuType, Color> map = new LinkedHashMap<>();
106         map.put(CAR, Color.BLUE);
107         map.put(TRUCK, Color.RED);
108         map.put(VEHICLE, Color.GRAY);
109         map.put(PEDESTRIAN, Color.YELLOW);
110         map.put(BICYCLE, Color.GREEN);
111         GTU_TYPE_COLORS = new ImmutableLinkedHashMap<>(map, Immutable.WRAP);
112 
113         TRUCK.setMarker(Marker.SQUARE);
114     }
115 
116     /**
117      * Returns a template for the given GTU type. This can be defined at the level of super types, returning {@code null} for
118      * more specific types. There is no need to define a template for all default types defined for a locale, so long as at
119      * least one parent of each type has a template defined.<br>
120      * <br>
121      * Note: implementations should not cache the template per GTU type, as different simulations may request templates for the
122      * same GTU type, while having their separate random streams.
123      * @param gtuType GtuType; GTU type.
124      * @param randomStream StreamInterface; random stream.
125      * @return TemplateGtuType; template, {@code null} if no default is defined.
126      */
127     @Override
128     public GtuTemplate apply(final GtuType gtuType, final StreamInterface randomStream)
129     {
130         GtuTemplate template = null;
131         if (gtuType.equals(CAR))
132         {
133             // from "Maatgevende normen in de Nederlandse richtlijnen voor wegontwerp", R-2014-38, SWOV
134             template = new GtuTemplate(gtuType, new ConstantGenerator<>(Length.instantiateSI(4.19)),
135                     new ConstantGenerator<>(Length.instantiateSI(1.7)),
136                     new ConstantGenerator<>(new Speed(180, SpeedUnit.KM_PER_HOUR)));
137         }
138         else if (gtuType.equals(TRUCK))
139         {
140             // from "Maatgevende normen in de Nederlandse richtlijnen voor wegontwerp", R-2014-38, SWOV
141             template = new GtuTemplate(gtuType, new ConstantGenerator<>(Length.instantiateSI(12.0)),
142                     new ConstantGenerator<>(Length.instantiateSI(2.55)),
143                     new ContinuousDistSpeed(new DistNormal(randomStream, 85.0, 2.5), SpeedUnit.KM_PER_HOUR));
144         }
145         else if (gtuType.equals(BUS))
146         {
147             template = new GtuTemplate(gtuType, new ConstantGenerator<>(Length.instantiateSI(12.0)),
148                     new ConstantGenerator<>(Length.instantiateSI(2.55)),
149                     new ConstantGenerator<>(new Speed(90, SpeedUnit.KM_PER_HOUR)));
150         }
151         else if (gtuType.equals(VAN))
152         {
153             template = new GtuTemplate(gtuType, new ConstantGenerator<>(Length.instantiateSI(5.0)),
154                     new ConstantGenerator<>(Length.instantiateSI(2.4)),
155                     new ConstantGenerator<>(new Speed(180, SpeedUnit.KM_PER_HOUR)));
156         }
157         else if (gtuType.equals(EMERGENCY_VEHICLE))
158         {
159             template = new GtuTemplate(gtuType, new ConstantGenerator<>(Length.instantiateSI(5.0)),
160                     new ConstantGenerator<>(Length.instantiateSI(2.55)),
161                     new ConstantGenerator<>(new Speed(180, SpeedUnit.KM_PER_HOUR)));
162         }
163         return template;
164     };
165 
166     /***************************************************************************************/
167     /**************************************** LINK *****************************************/
168     /***************************************************************************************/
169 
170     /** This is here only because it is in the file default_linktypes.xml as a default, i.e the parser needs to find it. */
171     @Deprecated
172     public static final LinkType NONE_LINK = new LinkType("NONE");
173 
174     /** This is here only because it is in the file default_linktypes.xml as a default, i.e the parser needs to find it. */
175     @Deprecated
176     public static final LinkType CONNECTOR = new LinkType("CONNECTOR");
177 
178     /** Super type for all roads. */
179     public static final LinkType ROAD = new LinkType("ROAD");
180 
181     /** Freeway (snelweg, 130km/h). */
182     public static final LinkType FREEWAY = new LinkType("FREEWAY", ROAD);
183 
184     /** Highway (autoweg, 100km/h). */
185     public static final LinkType HIGHWAY = new LinkType("HIGHWAY", ROAD);
186 
187     /** Provincial (provinciaalse weg / N-weg, 80km/h). */
188     public static final LinkType PROVINCIAL = new LinkType("PROVINCIAL", ROAD);
189 
190     /** Rural (landelijk, 60km/h). */
191     public static final LinkType RURAL = new LinkType("RURAL", ROAD);
192 
193     /** Urban (stedelijk, 50km/h). */
194     public static final LinkType URBAN = new LinkType("URBAN", ROAD);
195 
196     /** Residential (buurtweg, 30km/h). */
197     public static final LinkType RESIDENTIAL = new LinkType("RESIDENTIAL", ROAD);
198 
199     /** Waterway. */
200     public static final LinkType WATERWAY = new LinkType("WATERWAY");
201 
202     /** Railway. */
203     public static final LinkType RAILWAY = new LinkType("RAILWAY");
204 
205     static
206     {
207         ROAD.addCompatibleGtuType(ROAD_USER);
208         FREEWAY.addIncompatibleGtuType(PEDESTRIAN);
209         FREEWAY.addIncompatibleGtuType(BICYCLE);
210         HIGHWAY.addIncompatibleGtuType(PEDESTRIAN);
211         HIGHWAY.addIncompatibleGtuType(BICYCLE);
212         PROVINCIAL.addIncompatibleGtuType(PEDESTRIAN);
213         PROVINCIAL.addIncompatibleGtuType(BICYCLE);
214         WATERWAY.addCompatibleGtuType(WATERWAY_USER);
215         RAILWAY.addCompatibleGtuType(RAILWAY_USER);
216     }
217 
218 }