DefaultDistraction.java

  1. package org.opentrafficsim.road.gtu.lane.perception.mental.sdm;

  2. import org.djunits.value.vdouble.scalar.Duration;
  3. import org.djunits.value.vdouble.scalar.Frequency;

  4. /**
  5.  * Set of default distractions as derived by the research of Manuel Lindorfer. These only describe the statistics. Actual
  6.  * {@code Distraction}s are linked to the simulation. {@code DistractionFactory} can be used to create those.
  7.  * <p>
  8.  * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  9.  * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
  10.  * <p>
  11.  * @version $Revision$, $LastChangedDate$, by $Author$, initial version 29 jun. 2018 <br>
  12.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  13.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  14.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  15.  */
  16. public enum DefaultDistraction
  17. {
  18.     /** Talking on cell phone. */
  19.     TALKING_CELL_PHONE("1", "Talking on cell phone", freq(100, 0.329), 0.329, dur(92.65), dur(176.29)),

  20.     /** Answering cell phone. */
  21.     ANSWERING_CELL_PHONE("2", "Answering cell phone", freq(15, 0.157), 0.157, dur(7.86), dur(4.24)),

  22.     /** Dialing cell phone. */
  23.     DIALING_CELL_PHONE("3", "Dialing cell phone", freq(122, 0.357), 0.357, dur(12.85), dur(13.41)),

  24.     /** Drinking. */
  25.     DRINKING("4", "Drinking", freq(1028, 0.729), 0.729, dur(5.23), dur(7.4)),

  26.     /** Manipulating audio controls. */
  27.     MANIPULATING_AUDIO_CONTROLS("5", "Manipulating audio controls", freq(1539, 0.943), 0.943, dur(5.46), dur(8.63)),

  28.     /** Smoking. */
  29.     SMOKING("6", "Smoking", freq(45, 0.071), 0.071, dur(245.81), dur(162.95)),

  30.     /** Reading or writing. */
  31.     READING_WRITING("7", "Reading or writing", freq(303, 0.643), 0.643, dur(18.43), dur(29.7)),

  32.     /** Grooming. */
  33.     GROOMING("8", "Grooming", freq(229, 0.571), 0.571, dur(11.82), dur(29.77)),

  34.     /** Baby distracting. */
  35.     BABY_DISTRACTING("9", "Baby distracting", freq(114, 0.086), 0.086, dur(23.49), dur(28.39)),

  36.     /** Child distracting. */
  37.     CHILD_DISTRACTING("10", "Child distracting", freq(81, 0.143), 0.143, dur(25.76), dur(124.72)),

  38.     /** Adult distracting. */
  39.     ADULT_DISTRACTING("11", "Adult distracting", freq(48, 0.257), 0.257, dur(46.32), dur(108.49)),

  40.     /** Conversing. */
  41.     CONVERSING("12", "Conversing", freq(1558, 0.8), 0.8, dur(74.04), dur(234.5)),

  42.     /** Reaching. */
  43.     REACHING("13", "Reaching", freq(2246, 1.0), 1.0, dur(7.58), dur(36.7)),

  44.     /** Manipulating vehicle controls. */
  45.     MANIPULATING_VEHICLE_CONTROLS("14", "Manipulating vehicle controls", freq(2095, 1.0), 1.0, dur(4.82), dur(11.53)),

  46.     /** Internal distraction. */
  47.     INTERNAL_DISTRACTION("15", "Internal distraction", freq(481, 0.814), 0.814, dur(21.55), dur(46.38)),

  48.     /** External distraction. */
  49.     EXTERNAL_DISTRACTION("16", "External distraction", freq(659, 0.9), 0.9, dur(26.55), dur(58.78)),

  50.     /** Preparing to eat / drink. */
  51.     PREPARING_EAT_DRINK("17", "Preparing to eat / drink", freq(1503, 0.614), 0.614, dur(15.4), dur(34.7));

  52.     /** Total time of data with which frequencies are determined. */
  53.     private static final double BASELINE_DURATION_SECONDS = 207.14 * 3600.0;

  54.     /** Id. */
  55.     private final String id;

  56.     /** Description. */
  57.     private final String description;

  58.     /** Frequency. */
  59.     private final Frequency frequency;

  60.     /** Exposure (value in range [0...1]). */
  61.     private final double exposure;

  62.     /** Average duration. */
  63.     private final Duration averageDuration;

  64.     /** Standard deviation of duration. */
  65.     private final Duration stdDuration;

  66.     /**
  67.      * Constructor.
  68.      * @param id String; id
  69.      * @param description String; description
  70.      * @param frequency Frequency; frequency per exposed driver
  71.      * @param exposure double; exposure (value in range [0...1])
  72.      * @param averageDuration Duration; average duration
  73.      * @param stdDuration Duration; standard deviation of duration
  74.      */
  75.     DefaultDistraction(final String id, final String description, final Frequency frequency, final double exposure,
  76.             final Duration averageDuration, final Duration stdDuration)
  77.     {
  78.         this.id = id;
  79.         this.description = description;
  80.         this.frequency = frequency;
  81.         this.exposure = exposure;
  82.         this.averageDuration = averageDuration;
  83.         this.stdDuration = stdDuration;
  84.     }

  85.     /**
  86.      * Helper method to return a {@code Frequency} with little code.
  87.      * @param occurrences int; number of occurrences in data
  88.      * @param exposure double; exposure
  89.      * @return Frequency; frequency
  90.      */
  91.     private static Frequency freq(final int occurrences, final double exposure)
  92.     {
  93.         return Frequency.createSI(occurrences / (BASELINE_DURATION_SECONDS * exposure));
  94.     }

  95.     /**
  96.      * Helper method to return a {@code Duration} with little code.
  97.      * @param duration double; SI value of duration
  98.      * @return Duration; duration
  99.      */
  100.     private static Duration dur(final double duration)
  101.     {
  102.         return Duration.createSI(duration);
  103.     }

  104.     /**
  105.      * Returns the id.
  106.      * @return String; id
  107.      */
  108.     public String getId()
  109.     {
  110.         return this.id;
  111.     }

  112.     /**
  113.      * Returns the description.
  114.      * @return String; description
  115.      */
  116.     public String getDescription()
  117.     {
  118.         return this.description;
  119.     }

  120.     /**
  121.      * Returns the frequency per exposed driver.
  122.      * @return Frequency; frequency per exposed driver
  123.      */
  124.     public Frequency getFrequency()
  125.     {
  126.         return this.frequency;
  127.     }

  128.     /**
  129.      * Returns the exposure.
  130.      * @return double; exposure
  131.      */
  132.     public double getExposure()
  133.     {
  134.         return this.exposure;
  135.     }

  136.     /**
  137.      * Returns the average duration.
  138.      * @return Duration; average duration
  139.      */
  140.     public Duration getAverageDuration()
  141.     {
  142.         return this.averageDuration;
  143.     }

  144.     /**
  145.      * Returns the standard deviation of duration.
  146.      * @return Duration; standard deviation of duration
  147.      */
  148.     public Duration getStdDuration()
  149.     {
  150.         return this.stdDuration;
  151.     }

  152.     /**
  153.      * Returns a default distraction from the id.
  154.      * @param id String; id
  155.      * @return DefaultDistraction; default distraction from id
  156.      */
  157.     public static DefaultDistraction getFromId(final String id)
  158.     {
  159.         return values()[Integer.parseInt(id) - 1];
  160.     }

  161. }