![JAR search and dependency download from the Maven repository](/logo.png)
org.opentrafficsim.kpi.sampling.indicator.MeanTripLength Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ots-kpi Show documentation
Show all versions of ots-kpi Show documentation
OpenTrafficSim KPI Module without dependencies to ots-road or ots-core
package org.opentrafficsim.kpi.sampling.indicator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.djunits.value.vdouble.scalar.Length;
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 lengths divided by number of GTU's.
*
* Copyright (c) 2013-2023 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
*/
public class MeanTripLength extends AbstractIndicator
{
/** {@inheritDoc} */
@Override
// @docs/07-output/indicators.md
protected Length calculate(final Query query, final Time startTime, final Time endTime,
final List> trajectoryGroups)
{
Length sum = Length.ZERO;
Set gtuIds = new LinkedHashSet<>();
for (TrajectoryGroup> trajectoryGroup : trajectoryGroups)
{
for (Trajectory> trajectory : trajectoryGroup.getTrajectories())
{
sum = sum.plus(trajectory.getTotalLength());
gtuIds.add(trajectory.getGtuId());
}
}
return sum.divide(gtuIds.size());
}
/** {@inheritDoc} */
@Override
@SuppressWarnings("checkstyle:designforextension")
public String toString()
{
return "MeanTripLength []";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy