1 package org.opentrafficsim.demo.timing;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import javax.naming.NamingException;
7
8 import org.djunits.unit.UNITS;
9 import org.djunits.value.vdouble.scalar.Acceleration;
10 import org.djunits.value.vdouble.scalar.Duration;
11 import org.djunits.value.vdouble.scalar.Length;
12 import org.djunits.value.vdouble.scalar.Time;
13 import org.opentrafficsim.base.modelproperties.CompoundProperty;
14 import org.opentrafficsim.base.modelproperties.ProbabilityDistributionProperty;
15 import org.opentrafficsim.base.modelproperties.Property;
16 import org.opentrafficsim.base.modelproperties.PropertyException;
17 import org.opentrafficsim.base.modelproperties.SelectionProperty;
18 import org.opentrafficsim.core.gtu.AbstractGTU;
19 import org.opentrafficsim.core.network.NetworkException;
20 import org.opentrafficsim.demo.carFollowing.CircularRoad;
21 import org.opentrafficsim.road.gtu.lane.AbstractLaneBasedGTU;
22 import org.opentrafficsim.road.modelproperties.IDMPropertySet;
23 import org.opentrafficsim.simulationengine.OTSSimulationException;
24 import org.opentrafficsim.simulationengine.SimpleAnimator;
25 import org.opentrafficsim.simulationengine.WrappableAnimation;
26
27 import nl.tudelft.simulation.dsol.SimRuntimeException;
28
29
30
31
32
33
34
35
36
37
38
39
40 public class TimeCircularRoadAnimation implements UNITS
41 {
42
43 public TimeCircularRoadAnimation()
44 {
45 try
46 {
47 WrappableAnimation simulation = new CircularRoad();
48 List<Property<?>> activeProperties = new ArrayList<>();
49 activeProperties.addAll(simulation.getProperties());
50 for (Property<?> ap : activeProperties)
51 {
52 if (ap instanceof SelectionProperty)
53 {
54 SelectionProperty sp = (SelectionProperty) ap;
55 if ("TacticalPlanner".equals(sp.getKey()))
56 {
57 sp.setValue("DIRECTED/IDM");
58 }
59 }
60 }
61 activeProperties.add(new ProbabilityDistributionProperty("TrafficComposition", "Traffic composition",
62 "<html>Mix of passenger cars and trucks</html>", new String[] { "passenger car", "truck" },
63 new Double[] { 0.8, 0.2 }, false, 5));
64 CompoundProperty modelSelection =
65 new CompoundProperty("ModelSelection", "Model selection", "Modeling specific settings", null, false, 300);
66 modelSelection.add(new SelectionProperty("SimulationScale", "Simulation scale", "Level of detail of the simulation",
67 new String[] { "Micro", "Macro", "Meta" }, 0, true, 0));
68 modelSelection.add(new SelectionProperty("CarFollowingModel", "Car following model", "",
69 new String[] { "IDM", "IDM+" }, 1, false, 1));
70 modelSelection.add(IDMPropertySet.makeIDMPropertySet("IDMCar", "Car", new Acceleration(1.56, METER_PER_SECOND_2),
71 new Acceleration(2.09, METER_PER_SECOND_2), new Length(3.0, METER), new Duration(1.2, SECOND), 2));
72 modelSelection
73 .add(IDMPropertySet.makeIDMPropertySet("IDMTruck", "Truck", new Acceleration(0.75, METER_PER_SECOND_2),
74 new Acceleration(1.25, METER_PER_SECOND_2), new Length(3.0, METER), new Duration(1.2, SECOND), 3));
75 activeProperties.add(modelSelection);
76 SimpleAnimator sim = (SimpleAnimator) simulation.buildAnimator(Time.ZERO, Duration.ZERO,
77 new Duration(3600.0, SECOND), activeProperties, null, false);
78
79 sim.setSpeedFactor(1.0E9);
80
81 Thread.sleep(5000);
82
83 sim.scheduleEventRel(new Duration(59.999, MINUTE), this, this, "stop", new Object[] { System.currentTimeMillis() });
84 sim.start();
85 }
86 catch (SimRuntimeException | PropertyException | NetworkException | NamingException | OTSSimulationException
87 | InterruptedException exception)
88 {
89 exception.printStackTrace();
90 }
91 }
92
93
94
95
96
97 protected void stop(final long startTime)
98 {
99 System.out.println("Time of animation was : " + (System.currentTimeMillis() - startTime) / 1000 + " seconds");
100 System.out.println("Aligned GTU moves = " + AbstractGTU.ALIGN_COUNT);
101 System.out.println("Cached positions = " + AbstractLaneBasedGTU.CACHED_POSITION);
102 System.out.println("Non-cached positions = " + AbstractLaneBasedGTU.NON_CACHED_POSITION);
103 System.exit(0);
104 }
105
106
107
108
109 public static void main(final String[] args)
110 {
111 AbstractGTU.ALIGNED = true;
112 AbstractLaneBasedGTU.CACHING = true;
113
114 new TimeCircularRoadAnimation();
115 }
116
117 }