
org.opentrafficsim.kpi.sampling.indicator.TotalDelay Maven / Gradle / Ivy
package org.opentrafficsim.kpi.sampling.indicator;
import java.util.List;
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.opentrafficsim.kpi.interfaces.GtuData;
import org.opentrafficsim.kpi.sampling.Query;
import org.opentrafficsim.kpi.sampling.Trajectory;
import org.opentrafficsim.kpi.sampling.TrajectoryGroup;
/**
* Sum of trajectory durations minus the sum of trajectory lengths divided by a reference speed.
*
* Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License.
*
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
*/
// TODO something better than a global reference speed defined at the indicator
public class TotalDelay extends AbstractIndicator
{
/** Reference speed for delay. */
private final Speed referenceSpeed;
/**
* @param referenceSpeed Speed; reference speed for delay
*/
public TotalDelay(final Speed referenceSpeed)
{
this.referenceSpeed = referenceSpeed;
}
/** {@inheritDoc} */
@Override
protected Duration calculate(final Query query, final Time startTime, final Time endTime,
final List> trajectoryGroups)
{
Duration sumTime = Duration.ZERO;
Length sumDist = Length.ZERO;
for (TrajectoryGroup> trajectoryGroup : trajectoryGroups)
{
// TODO: use data points and limit speed per interval
for (Trajectory> trajectory : trajectoryGroup.getTrajectories())
{
sumTime = sumTime.plus(trajectory.getTotalDuration());
sumDist = sumDist.plus(trajectory.getTotalLength());
}
}
return sumTime.minus(sumDist.divide(this.referenceSpeed));
}
/** {@inheritDoc} */
@Override
@SuppressWarnings("checkstyle:designforextension")
public String toString()
{
return "TotalDelay [referenceSpeed=" + this.referenceSpeed + "]";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy