All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentrafficsim.kpi.sampling.indicator.MeanTripLength Maven / Gradle / Ivy

There is a newer version: 1.7.5
Show newest version
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