* Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License.
*
* $LastChangedDate: 2016-10-28 16:34:11 +0200 (Fri, 28 Oct 2016) $, @version $Revision: 2429 $, by $Author: pknoppers $,
* initial version 12 nov. 2014
* @author Peter Knoppers
*/
public class CrossingTrafficLights extends AbstractWrappableAnimation implements UNITS
{
/** */
private static final long serialVersionUID = 1L;
/** The model. */
private CrossingTrafficLightstModel model;
/** Fixed green time. */
protected static final Duration TGREEN = new Duration(39.0, DurationUnit.SI);
/** Fixed yellow time. */
protected static final Duration TYELLOW = new Duration(6.0, DurationUnit.SI);
/** Fixed red time. */
protected static final Duration TRED = new Duration(45.0, DurationUnit.SI);
/**
* Create a CrossingTrafficLights simulation.
* @throws PropertyException when a property is not handled
*/
public CrossingTrafficLights() throws PropertyException
{
this.properties.add(new SelectionProperty("LaneChanging", "Lane changing",
"The lane change strategies vary in politeness. "
+ "Two types are implemented:
Egoistic (looks only at personal gain).
"
+ "
Altruistic (assigns effect on new and current follower the same weight as "
+ "the personal gain).",
new String[] { "Egoistic", "Altruistic" }, 0, false, 500));
this.properties.add(new SelectionProperty("TacticalPlanner", "Tactical planner",
"The tactical planner determines if a lane change is desired and possible.",
new String[] { "IDM", "MOBIL/IDM", "DIRECTED/IDM", "LMRS", "Toledo" }, 0, false, 600));
}
/** {@inheritDoc} */
@Override
public final void stopTimersThreads()
{
super.stopTimersThreads();
this.model = null;
}
/**
* Main program.
* @param args String[]; the command line arguments (not used)
* @throws SimRuntimeException when simulation cannot be created with given parameters
*/
public static void main(final String[] args) throws SimRuntimeException
{
SwingUtilities.invokeLater(new Runnable()
{
@SuppressWarnings("synthetic-access")
@Override
public void run()
{
try
{
CrossingTrafficLights crossingTrafficLights = new CrossingTrafficLights();
List> localProperties = crossingTrafficLights.getProperties();
try
{
localProperties.add(new ProbabilityDistributionProperty("TrafficComposition", "Traffic composition",
"Mix of passenger cars and trucks", new String[] { "passenger car", "truck" },
new Double[] { 0.8, 0.2 }, false, 10));
}
catch (PropertyException exception)
{
exception.printStackTrace();
}
localProperties.add(new SelectionProperty("CarFollowingModel", "Car following model",
"The car following model determines "
+ "the acceleration that a vehicle will make taking into account "
+ "nearby vehicles, infrastructural restrictions (e.g. speed limit, "
+ "curvature of the road) capabilities of the vehicle and personality "
+ "of the driver.",
new String[] { "IDM", "IDM+" }, 1, false, 1));
localProperties.add(IDMPropertySet.makeIDMPropertySet("IDMCar", "Car",
new Acceleration(1.0, METER_PER_SECOND_2), new Acceleration(1.5, METER_PER_SECOND_2),
new Length(2.0, METER), new Duration(1.0, SECOND), 2));
localProperties.add(IDMPropertySet.makeIDMPropertySet("IDMTruck", "Truck",
new Acceleration(0.5, METER_PER_SECOND_2), new Acceleration(1.25, METER_PER_SECOND_2),
new Length(2.0, METER), new Duration(1.0, SECOND), 3));
crossingTrafficLights.buildAnimator(Time.ZERO, Duration.ZERO, new Duration(3600.0, SECOND), localProperties,
null, true);
crossingTrafficLights.panel.getTabbedPane().addTab("info", crossingTrafficLights.makeInfoPane());
}
catch (SimRuntimeException | NamingException | OTSSimulationException | PropertyException exception)
{
exception.printStackTrace();
}
}
});
}
/** {@inheritDoc} */
@Override
protected final void addAnimationToggles()
{
AnimationToggles.setTextAnimationTogglesStandard(this);
}
/** {@inheritDoc} */
@Override
protected final Rectangle2D makeAnimationRectangle()
{
return new Rectangle2D.Double(-50, -50, 100, 100);
}
/** {@inheritDoc} */
@Override
protected final OTSModelInterface makeModel()
{
this.model = new CrossingTrafficLightstModel(this.savedUserModifiedProperties);
return this.model;
}
/**
* @return an info pane to be added to the tabbed pane.
*/
protected final JComponent makeInfoPane()
{
// Make the info tab
String helpSource = "/" + CrossingTrafficLightstModel.class.getPackage().getName().replace('.', '/') + "/IDMPlus.html";
URL page = CrossingTrafficLightstModel.class.getResource(helpSource);
if (page != null)
{
try
{
HTMLPanel htmlPanel = new HTMLPanel(page);
return new JScrollPane(htmlPanel);
}
catch (IOException exception)
{
exception.printStackTrace();
}
}
return new JPanel();
}
/** {@inheritDoc} */
@Override
public final String shortName()
{
return "Crossing with Traffic Lights";
}
/** {@inheritDoc} */
@Override
public final String description()
{
return "
Simulation of a crossing with traffic lights
"
+ "Simulation of four double lane roads with a crossing in the middle.";
}
/**
* Simulate four double lane roads with a crossing in the middle.
*
* Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
*
* BSD-style license. See OpenTrafficSim License.
*
* $LastChangedDate: 2016-10-28 16:34:11 +0200 (Fri, 28 Oct 2016) $, @version $Revision: 2429 $, by $Author: pknoppers $,
* initial version ug 1, 2014
* @author Peter Knoppers
*/
class CrossingTrafficLightstModel implements OTSModelInterface, UNITS
{
/** */
private static final long serialVersionUID = 20140815L;
/** The simulator. */
private DEVSSimulatorInterface.TimeDoubleUnit simulator;
/** The network. */
private final OTSNetwork network = new OTSNetwork("network");
/** the random stream for this demo. */
private StreamInterface stream = new MersenneTwister(555);
/** The headway (inter-vehicle time) distribution. */
private ContinuousDistDoubleScalar.Rel headwayDistribution =
new ContinuousDistDoubleScalar.Rel<>(new DistTriangular(this.stream, 7, 9, 15), DurationUnit.SECOND);
/** The speed distribution. */
private ContinuousDistDoubleScalar.Rel speedDistribution =
new ContinuousDistDoubleScalar.Rel<>(new DistTriangular(this.stream, 50, 60, 70), SpeedUnit.KM_PER_HOUR);
/** Number of cars created. */
private int carsCreated = 0;
/** Type of all GTUs. */
private GTUType gtuType = CAR;
/** The car following model, e.g. IDM Plus for cars. */
private GTUFollowingModelOld carFollowingModel;
/** The lane change model, e.g. Egoistic for cars. */
private LaneChangeModel laneChangeModel;
/** User settable properties. */
private List> properties = null;
/** the tactical planner factory for this model. */
private LaneBasedStrategicalPlannerFactory strategicalPlannerFactory;
/** The speed limit on all Lanes. */
private Speed speedLimit = new Speed(80, KM_PER_HOUR);
/**
* @param properties the user settable properties
*/
CrossingTrafficLightstModel(final List> properties)
{
this.properties = properties;
}
/** {@inheritDoc} */
@Override
public final void constructModel(final SimulatorInterface