package org.opentrafficsim.road.car; import static org.junit.Assert.assertEquals; import java.util.LinkedHashSet; import java.util.Set; import javax.naming.NamingException; import nl.tudelft.simulation.dsol.SimRuntimeException; import nl.tudelft.simulation.dsol.experiment.Experiment; import nl.tudelft.simulation.dsol.experiment.Replication; import nl.tudelft.simulation.dsol.experiment.ReplicationMode; import nl.tudelft.simulation.dsol.experiment.Treatment; import nl.tudelft.simulation.dsol.simulators.SimulatorInterface; import org.djunits.unit.TimeUnit; import org.djunits.unit.UNITS; import org.djunits.value.vdouble.scalar.Acceleration; import org.djunits.value.vdouble.scalar.DoubleScalar; import org.djunits.value.vdouble.scalar.Length; import org.djunits.value.vdouble.scalar.Speed; import org.djunits.value.vdouble.scalar.Time; import org.junit.Test; import org.opentrafficsim.core.dsol.OTSDEVSSimulator; import org.opentrafficsim.core.dsol.OTSModelInterface; import org.opentrafficsim.core.dsol.OTSSimTimeDouble; import org.opentrafficsim.core.geometry.OTSGeometryException; import org.opentrafficsim.core.geometry.OTSLine3D; import org.opentrafficsim.core.geometry.OTSPoint3D; import org.opentrafficsim.core.gtu.GTUDirectionality; import org.opentrafficsim.core.gtu.GTUException; import org.opentrafficsim.core.gtu.GTUType; import org.opentrafficsim.core.network.LinkType; import org.opentrafficsim.core.network.LongitudinalDirectionality; import org.opentrafficsim.core.network.NetworkException; import org.opentrafficsim.core.network.OTSNetwork; import org.opentrafficsim.core.network.OTSNode; import org.opentrafficsim.road.gtu.lane.driver.LaneBasedDrivingCharacteristics; import org.opentrafficsim.road.gtu.lane.perception.LanePerceptionFull; import org.opentrafficsim.road.gtu.lane.tactical.LaneBasedCFLCTacticalPlanner; import org.opentrafficsim.road.gtu.lane.tactical.following.FixedAccelerationModel; import org.opentrafficsim.road.gtu.lane.tactical.following.GTUFollowingModel; import org.opentrafficsim.road.gtu.lane.tactical.lanechangemobil.Egoistic; import org.opentrafficsim.road.gtu.lane.tactical.lanechangemobil.LaneChangeModel; import org.opentrafficsim.road.gtu.strategical.LaneBasedStrategicalPlanner; import org.opentrafficsim.road.gtu.strategical.route.LaneBasedStrategicalRoutePlanner; import org.opentrafficsim.road.network.lane.CrossSectionLink; import org.opentrafficsim.road.network.lane.DirectedLanePosition; import org.opentrafficsim.road.network.lane.Lane; import org.opentrafficsim.road.network.lane.LaneType; import org.opentrafficsim.road.network.lane.changing.LaneKeepingPolicy; import org.opentrafficsim.road.network.lane.changing.OvertakingConditions; /** *
* Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License.
*
* $LastChangedDate: 2015-09-16 19:20:07 +0200 (Wed, 16 Sep 2015) $, @version $Revision: 1405 $, by $Author: averbraeck $,
* initial version Jul 11, 2014
* @author Peter Knoppers
*/
public class CarTest implements UNITS
{
/**
* Test some basics of the Car class.
* @throws NetworkException on ???
* @throws SimRuntimeException on ???
* @throws NamingException on ???
* @throws GTUException on ???
* @throws OTSGeometryException when center line or contour of a link or lane cannot be generated
*/
@SuppressWarnings("static-method")
@Test
public final void carTest() throws NetworkException, SimRuntimeException, NamingException, GTUException,
OTSGeometryException
{
Time.Abs initialTime = new Time.Abs(0, SECOND);
GTUType gtuType = GTUType.makeGTUType("Car");
LaneType laneType = new LaneType("CarLane");
laneType.addCompatibility(gtuType);
OTSNetwork network = new OTSNetwork("network");
Lane lane = makeLane(laneType);
Length.Rel initialPosition = new Length.Rel(12, METER);
Speed initialSpeed = new Speed(34, KM_PER_HOUR);
OTSDEVSSimulator simulator = makeSimulator();
GTUFollowingModel gtuFollowingModel =
new FixedAccelerationModel(new Acceleration(0, METER_PER_SECOND_2), new Time.Rel(10, SECOND));
LaneChangeModel laneChangeModel = new Egoistic();
LaneBasedIndividualCar referenceCar =
makeReferenceCar("12345", gtuType, lane, initialPosition, initialSpeed, simulator, gtuFollowingModel,
laneChangeModel, network);
assertEquals("The car should store it's ID", "12345", referenceCar.getId());
assertEquals("At t=initialTime the car should be at it's initial position", initialPosition.getSI(),
referenceCar.position(lane, referenceCar.getReference(), initialTime).getSI(), 0.0001);
assertEquals("The car should store it's initial speed", initialSpeed.getSI(),
referenceCar.getVelocity(initialTime).getSI(), 0.00001);
assertEquals("The car should have an initial acceleration equal to 0", 0,
referenceCar.getAcceleration(initialTime).getSI(), 0.0001);
assertEquals("The gtu following model should be " + gtuFollowingModel, gtuFollowingModel, referenceCar
.getDrivingCharacteristics().getGTUFollowingModel());
// There is (currently) no way to retrieve the lane change model of a GTU.
}
/**
* Create the simplest possible simulator.
* @return OTSDEVSSimulator
* @throws SimRuntimeException on ???
* @throws NamingException on ???
*/
public static OTSDEVSSimulator makeSimulator() throws SimRuntimeException, NamingException
{
OTSDEVSSimulator simulator = new OTSDEVSSimulator();
Model model = new Model();
Experiment