package org.opentrafficsim.draw.graphs; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; import org.djunits.unit.SpeedUnit; import org.djunits.value.vdouble.scalar.Duration; import org.djunits.value.vdouble.scalar.Length; import org.djunits.value.vdouble.scalar.Speed; import org.djunits.value.vdouble.scalar.Time; import org.djutils.exceptions.Throw; import org.djutils.logger.CategoryLogger; import org.opentrafficsim.core.egtf.Converter; import org.opentrafficsim.core.egtf.DataSource; import org.opentrafficsim.core.egtf.DataStream; import org.opentrafficsim.core.egtf.EGTF; import org.opentrafficsim.core.egtf.EgtfEvent; import org.opentrafficsim.core.egtf.EgtfListener; import org.opentrafficsim.core.egtf.Filter; import org.opentrafficsim.core.egtf.Quantity; import org.opentrafficsim.core.egtf.typed.TypedQuantity; import org.opentrafficsim.draw.graphs.GraphPath.Section; import org.opentrafficsim.kpi.interfaces.GtuDataInterface; import org.opentrafficsim.kpi.sampling.KpiLaneDirection; import org.opentrafficsim.kpi.sampling.SamplerData; import org.opentrafficsim.kpi.sampling.Trajectory; import org.opentrafficsim.kpi.sampling.Trajectory.SpaceTimeView; import org.opentrafficsim.kpi.sampling.TrajectoryGroup; /** * Class that contains data for contour plots. One data source can be shared between contour plots, in which case the * granularity, path, sampler, update interval, and whether the data is smoothed (EGTF) are equal between the plots. *

* By default the source contains traveled time and traveled distance per cell. *

* Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License. *

* @version $Revision$, $LastChangedDate$, by $Author$, initial version 5 okt. 2018
* @author Alexander Verbraeck * @author Peter Knoppers * @author Wouter Schakel * @param gtu type data */ public class ContourDataSource { // ************************* // *** GLOBAL PROPERTIES *** // ************************* /** Space granularity values. */ protected static final double[] DEFAULT_SPACE_GRANULARITIES = {10, 20, 50, 100, 200, 500, 1000}; /** Index of the initial space granularity. */ protected static final int DEFAULT_SPACE_GRANULARITY_INDEX = 3; /** Time granularity values. */ protected static final double[] DEFAULT_TIME_GRANULARITIES = {1, 2, 5, 10, 20, 30, 60, 120, 300, 600}; /** Index of the initial time granularity. */ protected static final int DEFAULT_TIME_GRANULARITY_INDEX = 3; /** Initial lower bound for the time scale. */ protected static final Time DEFAULT_LOWER_TIME_BOUND = Time.ZERO; /** * Total kernel size relative to sigma and tau. This factor is determined through -log(1 - p) with p ~= 99%. This means that * the cumulative exponential distribution has 99% at 5 times sigma or tau. Note that due to a coordinate change in the * Adaptive Smoothing Method, the actual cumulative distribution is slightly different. Hence, this is just a heuristic. */ private static final int KERNEL_FACTOR = 5; /** Spatial kernel size. Larger value may be used when using a large granularity. */ private static final Length SIGMA = Length.instantiateSI(300); /** Temporal kernel size. Larger value may be used when using a large granularity. */ private static final Duration TAU = Duration.instantiateSI(30); /** Maximum free flow propagation speed. */ private static final Speed MAX_C_FREE = new Speed(80.0, SpeedUnit.KM_PER_HOUR); /** Factor on speed limit to determine vc, the flip over speed between congestion and free flow. */ private static final double VC_FACRTOR = 0.8; /** Congestion propagation speed. */ private static final Speed C_CONG = new Speed(-18.0, SpeedUnit.KM_PER_HOUR); /** Delta v, speed transition region around threshold. */ private static final Speed DELTA_V = new Speed(10.0, SpeedUnit.KM_PER_HOUR); // ***************************** // *** CONTEXTUAL PROPERTIES *** // ***************************** /** Sampler data. */ private final SamplerData samplerData; /** Update interval. */ private final Duration updateInterval; /** Delay so critical future events have occurred, e.g. GTU's next move's to extend trajectories. */ private final Duration delay; /** Path. */ private final GraphPath path; /** Space axis. */ final Axis spaceAxis; /** Time axis. */ final Axis timeAxis; /** Registered plots. */ private Set> plots = new LinkedHashSet<>(); // ***************** // *** PLOT DATA *** // ***************** /** Total distance traveled per cell. */ private float[][] distance; /** Total time traveled per cell. */ private float[][] time; /** Data of other types. */ private final Map, float[][]> additionalData = new LinkedHashMap<>(); // **************************** // *** SMOOTHING PROPERTIES *** // **************************** /** Free flow propagation speed. */ private Speed cFree; /** Flip-over speed between congestion and free flow. */ private Speed vc; /** Smoothing filter. */ private EGTF egtf; /** Data stream for speed. */ private DataStream speedStream; /** Data stream for travel time. */ private DataStream travelTimeStream; /** Data stream for travel distance. */ private DataStream travelDistanceStream; /** Quantity for travel time. */ private final Quantity travelTimeQuantity = new Quantity<>("travel time", Converter.SI); /** Quantity for travel distance. */ private final Quantity travelDistanceQuantity = new Quantity<>("travel distance", Converter.SI); /** Data streams for any additional data. */ private Map, DataStream> additionalStreams = new LinkedHashMap<>(); // ***************************** // *** CONTINUITY PROPERTIES *** // ***************************** /** Updater for update times. */ private final GraphUpdater