package org.opentrafficsim.demo.ntm; import java.awt.geom.Point2D; import java.util.ArrayList; import org.djunits.unit.FrequencyUnit; import org.djunits.unit.LengthUnit; import org.djunits.unit.LinearDensityUnit; import org.djunits.unit.SpeedUnit; import org.djunits.value.vdouble.scalar.Duration; import org.djunits.value.vdouble.scalar.Frequency; import org.djunits.value.vdouble.scalar.Length; import org.djunits.value.vdouble.scalar.LinearDensity; import org.djunits.value.vdouble.scalar.Speed; import org.opentrafficsim.demo.ntm.fundamentaldiagrams.FundamentalDiagram; /** *
* Copyright (c) 2013-2017 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License.
*
* $LastChangedDate$, @version $Revision$, by $Author$,
* initial version 26 Sep 2014
* @author Alexander Verbraeck
* @author Hans van Lint
* @author Peter Knoppers
* @author Guus Tamminga
* @author Yufei Yuan
*/
public class CellBehaviourNTM extends CellBehaviour
{
/** */
private static final long serialVersionUID = 20140903L;
/** CurrentSpeed: average current speed of Cars in this CELL. */
private Speed freeSpeed;
/** CurrentSpeed: average current speed of Cars in this CELL. */
private Speed currentSpeed;
/** CurrentSpeed: average current speed of Cars in this CELL. */
private Duration currentTravelTime;
/** */
private Frequency maxCapacityNTMArea;
/**
* parametersNTM are: - id ID - accCritical1 low param - accCritical2 high param - accJam jam param - freeSpeed -
* uncongested speed - roadLength length of all roads.
*/
private ParametersNTM parametersNTM;
/** */
private Area area;
/**
* @param parametersNTM ParametersNTM; contains a set of params
* @param area Area; that contains this behaviour
*/
public CellBehaviourNTM(final Area area, final ParametersNTM parametersNTM)
{
this.parametersNTM = parametersNTM;
// double maxCap = parametersNTM.getAccCritical().get(0) *
// parametersNTM.getFreeSpeed().getInUnit(SpeedUnit.KM_PER_HOUR)
// * parametersNTM.getRoadLength().getInUnit(LengthUnit.KILOMETER);
double maxCap = parametersNTM.getCapacity().getInUnit(FrequencyUnit.PER_HOUR)
* parametersNTM.getRoadLength().getInUnit(LengthUnit.KILOMETER);
this.maxCapacityNTMArea = new Frequency(maxCap, FrequencyUnit.PER_HOUR);
this.area = area;
}
/**
* @param accumulatedCars double;
* @return actualSpeed.
*/
public Speed retrieveCurrentSpeed(final double accumulatedCars, final Length roadLength)
{
double densityPerUnitDouble = this.getAccumulatedCars() / roadLength.getInUnit(LengthUnit.KILOMETER);
double speedDouble;
if (densityPerUnitDouble > this.getParametersNTM().getAccCritical().get(0))
{
LinearDensity densityPerUnit = new LinearDensity(densityPerUnitDouble, LinearDensityUnit.PER_KILOMETER);
Frequency capacityPerUnit = retrieveSupplyPerLengthUnit(accumulatedCars, roadLength, this.getParametersNTM());
speedDouble = capacityPerUnit.getInUnit(FrequencyUnit.PER_HOUR)
/ densityPerUnit.getInUnit(LinearDensityUnit.PER_KILOMETER);
}
else
{
speedDouble = this.getParametersNTM().getFreeSpeed().getInUnit(SpeedUnit.KM_PER_HOUR);
}
return this.setCurrentSpeed(new Speed(speedDouble, SpeedUnit.KM_PER_HOUR));
}
/**
* {@inheritDoc}
* @param accumulatedCars
* @param roadLength
* @param parametersNTM
* @return
*/
// @Override
public Frequency retrieveSupplyPerLengthUnit(final Double accumulatedCars, final Length roadLength,
final ParametersNTM parametersNTM)
{
Frequency supply = parametersNTM.getCapacity();
double densityPerUnitDouble = this.getAccumulatedCars() / roadLength.getInUnit(LengthUnit.KILOMETER);
if (densityPerUnitDouble > this.getParametersNTM().getAccCritical().get(1))
{
supply = retrieveDemandPerLengthUnit(accumulatedCars, roadLength, parametersNTM);
}
return supply;
}
/**
* Retrieves car production from network fundamental diagram.
* @param accumulatedCars double; number of cars in Cell
* @param maximumCapacityArea based on area information
* @param parametersNTM ParametersNTM;
* @return carProduction
*/
public final Frequency retrieveDemandPerLengthUnit(final double accumulatedCars, final Length roadLength,
final ParametersNTM parametersNTM)
{
double densityPerUnitDouble = this.getAccumulatedCars() / roadLength.getInUnit(LengthUnit.KILOMETER);
ArrayList