1 package org.opentrafficsim.demo;
2
3 import java.awt.Dimension;
4 import java.rmi.RemoteException;
5
6 import javax.naming.NamingException;
7
8 import org.djunits.unit.util.UNITS;
9 import org.djunits.value.vdouble.scalar.Duration;
10 import org.djunits.value.vdouble.scalar.Time;
11 import org.opentrafficsim.core.dsol.OTSAnimator;
12 import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
13 import org.opentrafficsim.core.gtu.GTUDirectionality;
14 import org.opentrafficsim.core.network.NetworkException;
15 import org.opentrafficsim.draw.core.OTSDrawingException;
16 import org.opentrafficsim.draw.graphs.ContourDataSource;
17 import org.opentrafficsim.draw.graphs.ContourPlotAcceleration;
18 import org.opentrafficsim.draw.graphs.ContourPlotDensity;
19 import org.opentrafficsim.draw.graphs.ContourPlotFlow;
20 import org.opentrafficsim.draw.graphs.ContourPlotSpeed;
21 import org.opentrafficsim.draw.graphs.GraphPath;
22 import org.opentrafficsim.draw.graphs.TrajectoryPlot;
23 import org.opentrafficsim.draw.graphs.road.GraphLaneUtil;
24 import org.opentrafficsim.kpi.sampling.KpiLaneDirection;
25 import org.opentrafficsim.road.network.OTSRoadNetwork;
26 import org.opentrafficsim.road.network.lane.LaneDirection;
27 import org.opentrafficsim.road.network.sampling.RoadSampler;
28 import org.opentrafficsim.swing.graphs.SwingContourPlot;
29 import org.opentrafficsim.swing.graphs.SwingPlot;
30 import org.opentrafficsim.swing.graphs.SwingTrajectoryPlot;
31 import org.opentrafficsim.swing.gui.OTSAnimationPanel;
32 import org.opentrafficsim.swing.gui.OTSSimulationApplication;
33
34 import nl.tudelft.simulation.dsol.SimRuntimeException;
35 import nl.tudelft.simulation.dsol.swing.gui.TablePanel;
36 import nl.tudelft.simulation.dsol.swing.gui.inputparameters.TabbedParameterDialog;
37 import nl.tudelft.simulation.language.DSOLException;
38
39
40
41
42
43
44
45
46
47
48
49 public class StraightSwing extends OTSSimulationApplication<StraightModel> implements UNITS
50 {
51
52 private static final long serialVersionUID = 1L;
53
54
55
56
57
58
59
60
61 public StraightSwing(final String title, final OTSAnimationPanel panel, final StraightModel model)
62 throws OTSDrawingException
63 {
64 super(model, panel);
65 OTSRoadNetwork network = model.getNetwork();
66 System.out.println(network.getLinkMap());
67 }
68
69
70 @Override
71 protected void addTabs()
72 {
73 addStatisticsTabs(getModel().getSimulator());
74 }
75
76
77
78
79
80 public static void main(final String[] args)
81 {
82 demo(true);
83 }
84
85
86
87
88
89 public static void demo(final boolean exitOnClose)
90 {
91 try
92 {
93 OTSAnimator simulator = new OTSAnimator("StraightSwing");
94 final StraightModelml#StraightModel">StraightModel otsModel = new StraightModel(simulator);
95 if (TabbedParameterDialog.process(otsModel.getInputParameterMap()))
96 {
97 simulator.initialize(Time.ZERO, Duration.ZERO, Duration.instantiateSI(1500.0), otsModel);
98 OTSAnimationPanel animationPanel = new OTSAnimationPanel(otsModel.getNetwork().getExtent(),
99 new Dimension(800, 600), simulator, otsModel, DEFAULT_COLORER, otsModel.getNetwork());
100 StraightSwingng.html#StraightSwing">StraightSwing app = new StraightSwing("Straight", animationPanel, otsModel);
101 app.setExitOnClose(exitOnClose);
102 }
103 else
104 {
105 if (exitOnClose)
106 {
107 System.exit(0);
108 }
109 }
110 }
111 catch (SimRuntimeException | NamingException | RemoteException | OTSDrawingException | DSOLException exception)
112 {
113 exception.printStackTrace();
114 }
115 }
116
117
118
119
120
121 protected final void addStatisticsTabs(final OTSSimulatorInterface simulator)
122 {
123 GraphPath<KpiLaneDirection> path;
124 try
125 {
126 path = GraphLaneUtil.createPath("Lane", new LaneDirection(getModel().getPath().get(0), GTUDirectionality.DIR_PLUS));
127 }
128 catch (NetworkException exception)
129 {
130 throw new RuntimeException("Could not create a path as a lane has no set speed limit.", exception);
131 }
132
133 RoadSampler sampler = new RoadSampler(simulator);
134 ContourDataSource<?> dataPool = new ContourDataSource<>(sampler, path);
135 TablePanel charts = new TablePanel(3, 2);
136 SwingPlot plot = null;
137
138 plot = new SwingTrajectoryPlot(
139 new TrajectoryPlot("TrajectoryPlot", Duration.instantiateSI(10.0), simulator, sampler, path));
140 charts.setCell(plot.getContentPane(), 0, 0);
141
142 plot = new SwingContourPlot(new ContourPlotDensity("DensityPlot", simulator, dataPool));
143 charts.setCell(plot.getContentPane(), 1, 0);
144
145 plot = new SwingContourPlot(new ContourPlotSpeed("SpeedPlot", simulator, dataPool));
146 charts.setCell(plot.getContentPane(), 2, 0);
147
148 plot = new SwingContourPlot(new ContourPlotFlow("FlowPlot", simulator, dataPool));
149 charts.setCell(plot.getContentPane(), 1, 1);
150
151 plot = new SwingContourPlot(new ContourPlotAcceleration("AccelerationPlot", simulator, dataPool));
152 charts.setCell(plot.getContentPane(), 2, 1);
153
154 getAnimationPanel().getTabbedPane().addTab(getAnimationPanel().getTabbedPane().getTabCount(), "statistics ", charts);
155 }
156 }