package org.opentrafficsim.kpi.sampling; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; import org.djunits.unit.AccelerationUnit; import org.djunits.unit.DurationUnit; import org.djunits.unit.LengthUnit; import org.djunits.unit.SpeedUnit; import org.djunits.unit.TimeUnit; import org.djunits.value.ValueRuntimeException; import org.djunits.value.storage.StorageType; import org.djunits.value.vdouble.scalar.Acceleration; 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.djunits.value.vfloat.vector.FloatAccelerationVector; import org.djunits.value.vfloat.vector.FloatLengthVector; import org.djunits.value.vfloat.vector.FloatSpeedVector; import org.djunits.value.vfloat.vector.FloatTimeVector; import org.djunits.value.vfloat.vector.base.FloatVector; import org.djutils.exceptions.Throw; import org.opentrafficsim.kpi.interfaces.GtuDataInterface; import org.opentrafficsim.kpi.sampling.data.ExtendedDataType; import org.opentrafficsim.kpi.sampling.meta.FilterDataType; import org.opentrafficsim.kpi.sampling.meta.MetaData; /** * Contains position, speed, acceleration and time data of a GTU, over some section. Position is relative to the start of the * lane in the direction of travel, also when trajectories have been truncated at a position x > 0. Note that this regards * internal data and output. Input position always refers to the design line of the lane. This class internally flips input * positions and boundaries. *
* Copyright (c) 2013-2021 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License.
*
* Copyright (c) 2013-2021 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 15 okt. 2018
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
*/
public class Boundary
{
/** Rounded-down index. */
@SuppressWarnings("checkstyle:visibilitymodifier")
public final int index;
/** Fraction. */
@SuppressWarnings("checkstyle:visibilitymodifier")
public final double fraction;
/**
* @param index int; rounded down index
* @param fraction double; fraction
*/
Boundary(final int index, final double fraction)
{
this.index = index;
this.fraction = fraction;
}
/** {@inheritDoc} */
@Override
public final String toString()
{
return "Boundary [index=" + this.index + ", fraction=" + this.fraction + "]";
}
/**
* Returns the value at the boundary in the array.
* @param array float[]; float[] array
* @return double; value at the boundary in the array
*/
public double getValue(final float[] array)
{
if (this.fraction == 0.0)
{
return array[this.index];
}
if (this.fraction == 1.0)
{
return array[this.index + 1];
}
return (1 - this.fraction) * array[this.index] + this.fraction * array[this.index + 1];
}
}
/**
*
* Copyright (c) 2013-2021 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 12 okt. 2016
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
*/
private class Boundaries
{
/** Rounded-down from-index. */
@SuppressWarnings("checkstyle:visibilitymodifier")
public final int from;
/** Fraction of to-index. */
@SuppressWarnings("checkstyle:visibilitymodifier")
public final double fFrom;
/** Rounded-down to-index. */
@SuppressWarnings("checkstyle:visibilitymodifier")
public final int to;
/** Fraction of to-index. */
@SuppressWarnings("checkstyle:visibilitymodifier")
public final double fTo;
/**
* @param from int; from index, rounded down
* @param fFrom double; from index, fraction
* @param to int; to index, rounded down
* @param fTo double; to index, fraction
*/
Boundaries(final int from, final double fFrom, final int to, final double fTo)
{
Throw.when(from < 0 || from > Trajectory.this.size() - 1, IllegalArgumentException.class,
"Argument from (%d) is out of bounds.", from);
Throw.when(fFrom < 0 || fFrom > 1, IllegalArgumentException.class, "Argument fFrom (%f) is out of bounds.", fFrom);
Throw.when(from == Trajectory.this.size() && fFrom > 0, IllegalArgumentException.class,
"Arguments from (%d) and fFrom (%f) are out of bounds.", from, fFrom);
Throw.when(to < 0 || to >= Trajectory.this.size(), IllegalArgumentException.class,
"Argument to (%d) is out of bounds.", to);
Throw.when(fTo < 0 || fTo > 1, IllegalArgumentException.class, "Argument fTo (%f) is out of bounds.", fTo);
Throw.when(to == Trajectory.this.size() && fTo > 0, IllegalArgumentException.class,
"Arguments to (%d) and fTo (%f) are out of bounds.", to, fTo);
this.from = from;
this.fFrom = fFrom;
this.to = to;
this.fTo = fTo;
}
/**
* @param boundaries Boundaries; boundaries
* @return intersection of both boundaries
*/
public Boundaries intersect(final Boundaries boundaries)
{
if (this.to < boundaries.from || boundaries.to < this.from
|| this.to == boundaries.from && this.fTo < boundaries.fFrom
|| boundaries.to == this.from && boundaries.fTo < this.fFrom)
{
return new Boundaries(0, 0.0, 0, 0.0); // no overlap
}
int newFrom;
double newFFrom;
if (this.from > boundaries.from || this.from == boundaries.from && this.fFrom > boundaries.fFrom)
{
newFrom = this.from;
newFFrom = this.fFrom;
}
else
{
newFrom = boundaries.from;
newFFrom = boundaries.fFrom;
}
int newTo;
double newFTo;
if (this.to < boundaries.to || this.to == boundaries.to && this.fTo < boundaries.fTo)
{
newTo = this.to;
newFTo = this.fTo;
}
else
{
newTo = boundaries.to;
newFTo = boundaries.fTo;
}
return new Boundaries(newFrom, newFFrom, newTo, newFTo);
}
/** {@inheritDoc} */
@Override
public final String toString()
{
return "Boundaries [from=" + this.from + ", fFrom=" + this.fFrom + ", to=" + this.to + ", fTo=" + this.fTo + "]";
}
}
/**
* Space-time view of a trajectory. This supplies distance and time (and mean speed) in a space-time box.
*
* Copyright (c) 2013-2021 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
*/
public static class SpaceTimeView
{
/** Distance. */
final Length distance;
/** Time. */
final Duration time;
/**
* Constructor.
* @param distance Length; distance
* @param time Duration; time
*/
private SpaceTimeView(final Length distance, final Duration time)
{
this.distance = distance;
this.time = time;
}
/**
* Returns the distance.
* @return Length; distance
*/
public final Length getDistance()
{
return this.distance;
}
/**
* Returns the time.
* @return Duration; time
*/
public final Duration getTime()
{
return this.time;
}
/** {@inheritDoc} */
@Override
public String toString()
{
return "SpaceTimeView [distance=" + this.distance + ", time=" + this.time + "]";
}
}
}