DefaultsNl.java

  1. package org.opentrafficsim.core.definitions;

  2. import java.awt.Color;
  3. import java.util.LinkedHashMap;
  4. import java.util.Locale;
  5. import java.util.function.BiFunction;

  6. import org.djunits.unit.SpeedUnit;
  7. import org.djunits.value.vdouble.scalar.Length;
  8. import org.djunits.value.vdouble.scalar.Speed;
  9. import org.djutils.immutablecollections.Immutable;
  10. import org.djutils.immutablecollections.ImmutableLinkedHashMap;
  11. import org.djutils.immutablecollections.ImmutableMap;
  12. import org.opentrafficsim.core.distributions.ConstantGenerator;
  13. import org.opentrafficsim.core.gtu.GtuType;
  14. import org.opentrafficsim.core.gtu.GtuType.Marker;
  15. import org.opentrafficsim.core.gtu.GtuTemplate;
  16. import org.opentrafficsim.core.network.LinkType;
  17. import org.opentrafficsim.core.units.distributions.ContinuousDistSpeed;

  18. import nl.tudelft.simulation.jstats.distributions.DistNormal;
  19. import nl.tudelft.simulation.jstats.streams.StreamInterface;

  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://tudelft.nl/staff/p.knoppers-1">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, GtuTemplate>
  31. {

  32.     /**
  33.      * Constructor setting locale nl_NL.
  34.      */
  35.     DefaultsNl()
  36.     {
  37.         super(new Locale("nl", "NL"));
  38.     }

  39.     /***************************************************************************************/
  40.     /***************************************** GTU *****************************************/
  41.     /***************************************************************************************/

  42.     /** Super type for all road users. */
  43.     public static final GtuType ROAD_USER = new GtuType("NL.ROAD_USER");

  44.     /** Super type for all water way users. */
  45.     public static final GtuType WATERWAY_USER = new GtuType("NL.WATERWAY_USER");

  46.     /** Super type for all rail users. */
  47.     public static final GtuType RAILWAY_USER = new GtuType("NL.RAILWAY_USER");

  48.     /** Super type for pedestrians. */
  49.     public static final GtuType PEDESTRIAN = new GtuType("NL.PEDESTRIAN", ROAD_USER);

  50.     /** Super type for bicycle. */
  51.     public static final GtuType BICYCLE = new GtuType("NL.BICYCLE", ROAD_USER);

  52.     /** Super type for mopeds. */
  53.     public static final GtuType MOPED = new GtuType("NL.MOPED", BICYCLE);

  54.     /** Super type for vehicles. */
  55.     public static final GtuType VEHICLE = new GtuType("NL.VEHICLE", ROAD_USER);

  56.     /** Super type for emergency vehicles. */
  57.     public static final GtuType EMERGENCY_VEHICLE = new GtuType("NL.EMERGENCY_VEHICLE", VEHICLE);

  58.     /** Super type for ships. */
  59.     public static final GtuType SHIP = new GtuType("NL.SHIP", WATERWAY_USER);

  60.     /** Super type for trains. */
  61.     public static final GtuType TRAIN = new GtuType("NL.TRAIN", RAILWAY_USER);

  62.     /** Super type for cars. */
  63.     public static final GtuType CAR = new GtuType("NL.CAR", VEHICLE);

  64.     /** Super type for motorcycles. */
  65.     public static final GtuType MOTORCYCLE = new GtuType("NL.MOTORCYCLE", VEHICLE);
  66.    
  67.     /** Super type for vans. */
  68.     public static final GtuType VAN = new GtuType("NL.VAN", VEHICLE);

  69.     /** Super type for busses. */
  70.     public static final GtuType BUS = new GtuType("NL.BUS", VEHICLE);

  71.     /** Super type for trucks. */
  72.     public static final GtuType TRUCK = new GtuType("NL.TRUCK", VEHICLE);

  73.     /** Super type for scheduled busses. */
  74.     public static final GtuType SCHEDULED_BUS = new GtuType("NL.SCHEDULED_BUS", BUS);

  75.     /** Standard drawing colors for GTU types. */
  76.     public static final ImmutableMap<GtuType, Color> GTU_TYPE_COLORS;

  77.     static
  78.     {
  79.         LinkedHashMap<GtuType, Color> map = new LinkedHashMap<>();
  80.         map.put(CAR, Color.BLUE);
  81.         map.put(TRUCK, Color.RED);
  82.         map.put(VEHICLE, Color.GRAY);
  83.         map.put(PEDESTRIAN, Color.YELLOW);
  84.         map.put(MOTORCYCLE, Color.PINK);
  85.         map.put(BICYCLE, Color.GREEN);
  86.         GTU_TYPE_COLORS = new ImmutableLinkedHashMap<>(map, Immutable.WRAP);

  87.         TRUCK.setMarker(Marker.SQUARE);
  88.     }

  89.     /**
  90.      * Returns a template for the given GTU type. This can be defined at the level of super types, returning {@code null} for
  91.      * more specific types. There is no need to define a template for all default types defined for a locale, so long as at
  92.      * least one parent of each type has a template defined.<br>
  93.      * <br>
  94.      * Note: implementations should not cache the template per GTU type, as different simulations may request templates for the
  95.      * same GTU type, while having their separate random streams.
  96.      * @param gtuType GtuType; GTU type.
  97.      * @param randomStream StreamInterface; random stream.
  98.      * @return TemplateGtuType; template, {@code null} if no default is defined.
  99.      */
  100.     @Override
  101.     public GtuTemplate apply(final GtuType gtuType, final StreamInterface randomStream)
  102.     {
  103.         GtuTemplate template = null;
  104.         if (gtuType.equals(CAR))
  105.         {
  106.             // from "Maatgevende normen in de Nederlandse richtlijnen voor wegontwerp", R-2014-38, SWOV
  107.             template = new GtuTemplate(gtuType, new ConstantGenerator<>(Length.instantiateSI(4.19)),
  108.                     new ConstantGenerator<>(Length.instantiateSI(1.7)),
  109.                     new ConstantGenerator<>(new Speed(180, SpeedUnit.KM_PER_HOUR)));
  110.         }
  111.         else if (gtuType.equals(TRUCK))
  112.         {
  113.             // from "Maatgevende normen in de Nederlandse richtlijnen voor wegontwerp", R-2014-38, SWOV
  114.             template = new GtuTemplate(gtuType, new ConstantGenerator<>(Length.instantiateSI(12.0)),
  115.                     new ConstantGenerator<>(Length.instantiateSI(2.55)),
  116.                     new ContinuousDistSpeed(new DistNormal(randomStream, 85.0, 2.5), SpeedUnit.KM_PER_HOUR));
  117.         }
  118.         else if (gtuType.equals(BUS))
  119.         {
  120.             template = new GtuTemplate(gtuType, new ConstantGenerator<>(Length.instantiateSI(12.0)),
  121.                     new ConstantGenerator<>(Length.instantiateSI(2.55)),
  122.                     new ConstantGenerator<>(new Speed(90, SpeedUnit.KM_PER_HOUR)));
  123.         }
  124.         else if (gtuType.equals(VAN))
  125.         {
  126.             template = new GtuTemplate(gtuType, new ConstantGenerator<>(Length.instantiateSI(5.0)),
  127.                     new ConstantGenerator<>(Length.instantiateSI(2.4)),
  128.                     new ConstantGenerator<>(new Speed(180, SpeedUnit.KM_PER_HOUR)));
  129.         }
  130.         else if (gtuType.equals(EMERGENCY_VEHICLE))
  131.         {
  132.             template = new GtuTemplate(gtuType, new ConstantGenerator<>(Length.instantiateSI(5.0)),
  133.                     new ConstantGenerator<>(Length.instantiateSI(2.55)),
  134.                     new ConstantGenerator<>(new Speed(180, SpeedUnit.KM_PER_HOUR)));
  135.         }
  136.         else if (gtuType.equals(MOTORCYCLE))
  137.         {
  138.             // Yamaha R7 2022
  139.             template = new GtuTemplate(gtuType, new ConstantGenerator<>(Length.instantiateSI(2.1)),
  140.                     new ConstantGenerator<>(Length.instantiateSI(0.7)),
  141.                     new ConstantGenerator<>(new Speed(180, SpeedUnit.KM_PER_HOUR)));
  142.         }
  143.         else if (gtuType.equals(BICYCLE))
  144.         {
  145.             // length/width: https://www.verderfietsen.nl/fiets-afmetingen/
  146.             // width: https://www.fietsberaad.nl/CROWFietsberaad/media/Kennis/Bestanden/document000172.pdf?ext=.pdf
  147.             template = new GtuTemplate(gtuType, new ConstantGenerator<>(Length.instantiateSI(1.9)),
  148.                     new ConstantGenerator<>(Length.instantiateSI(0.6)),
  149.                     new ConstantGenerator<>(new Speed(35, SpeedUnit.KM_PER_HOUR)));
  150.         }
  151.         return template;
  152.     };

  153.     /***************************************************************************************/
  154.     /**************************************** LINK *****************************************/
  155.     /***************************************************************************************/

  156.     /** Connector type. */
  157.     public static final LinkType CONNECTOR = new LinkType("NL.CONNECTOR");
  158.    
  159.     /** Super type for all roads. */
  160.     public static final LinkType ROAD = new LinkType("NL.ROAD");

  161.     /** Freeway (snelweg, 130km/h). */
  162.     public static final LinkType FREEWAY = new LinkType("NL.FREEWAY", ROAD);

  163.     /** Highway (autoweg, 100km/h). */
  164.     public static final LinkType HIGHWAY = new LinkType("NL.HIGHWAY", ROAD);

  165.     /** Provincial (provinciaalse weg / N-weg, 80km/h). */
  166.     public static final LinkType PROVINCIAL = new LinkType("NL.PROVINCIAL", ROAD);

  167.     /** Rural (landelijk, 60km/h). */
  168.     public static final LinkType RURAL = new LinkType("NL.RURAL", ROAD);

  169.     /** Urban (stedelijk, 50km/h). */
  170.     public static final LinkType URBAN = new LinkType("NL.URBAN", ROAD);

  171.     /** Residential (buurtweg, 30km/h). */
  172.     public static final LinkType RESIDENTIAL = new LinkType("NL.RESIDENTIAL", ROAD);

  173.     /** Waterway. */
  174.     public static final LinkType WATERWAY = new LinkType("NL.WATERWAY");

  175.     /** Railway. */
  176.     public static final LinkType RAILWAY = new LinkType("NL.RAILWAY");

  177.     static
  178.     {
  179.         CONNECTOR.addCompatibleGtuType(ROAD_USER);
  180.         CONNECTOR.addCompatibleGtuType(WATERWAY_USER);
  181.         CONNECTOR.addCompatibleGtuType(RAILWAY_USER);
  182.         ROAD.addCompatibleGtuType(ROAD_USER);
  183.         FREEWAY.addIncompatibleGtuType(PEDESTRIAN);
  184.         FREEWAY.addIncompatibleGtuType(BICYCLE);
  185.         HIGHWAY.addIncompatibleGtuType(PEDESTRIAN);
  186.         HIGHWAY.addIncompatibleGtuType(BICYCLE);
  187.         PROVINCIAL.addIncompatibleGtuType(PEDESTRIAN);
  188.         PROVINCIAL.addIncompatibleGtuType(BICYCLE);
  189.         WATERWAY.addCompatibleGtuType(WATERWAY_USER);
  190.         RAILWAY.addCompatibleGtuType(RAILWAY_USER);
  191.     }

  192. }