1 package org.opentrafficsim.demo.conflict;
2
3 import java.awt.Dimension;
4 import java.net.URL;
5 import java.rmi.RemoteException;
6
7 import javax.naming.NamingException;
8
9 import org.djunits.value.vdouble.scalar.Duration;
10 import org.djunits.value.vdouble.scalar.Time;
11 import org.djutils.io.URLResource;
12 import org.opentrafficsim.core.dsol.AbstractOtsModel;
13 import org.opentrafficsim.core.dsol.OtsAnimator;
14 import org.opentrafficsim.core.dsol.OtsSimulatorInterface;
15 import org.opentrafficsim.core.perception.HistoryManagerDevs;
16 import org.opentrafficsim.demo.DefaultsFactory;
17 import org.opentrafficsim.demo.conflict.TurboRoundaboutDemo.TurboRoundaboutModel;
18 import org.opentrafficsim.road.network.RoadNetwork;
19 import org.opentrafficsim.road.network.factory.xml.parser.XmlParser;
20 import org.opentrafficsim.swing.gui.OtsAnimationPanel;
21 import org.opentrafficsim.swing.gui.OtsSimulationApplication;
22
23 import nl.tudelft.simulation.dsol.SimRuntimeException;
24 import nl.tudelft.simulation.language.DsolException;
25
26
27
28
29
30
31
32
33
34
35 public class TurboRoundaboutDemo extends OtsSimulationApplication<TurboRoundaboutModel>
36 {
37
38 private static final long serialVersionUID = 20161211L;
39
40
41
42
43
44
45
46 public TurboRoundaboutDemo(final String title, final OtsAnimationPanel panel, final TurboRoundaboutModel model)
47 {
48 super(model, panel, DefaultsFactory.GTU_TYPE_MARKERS.toMap());
49 }
50
51
52
53
54
55 public static void main(final String[] args)
56 {
57 demo(true);
58 }
59
60
61
62
63
64 public static void demo(final boolean exitOnClose)
65 {
66 try
67 {
68 OtsAnimator simulator = new OtsAnimator("TurboRoundaboutDemo");
69 final TurboRoundaboutModel junctionModel = new TurboRoundaboutModel(simulator);
70 simulator.initialize(Time.ZERO, Duration.ZERO, Duration.instantiateSI(3600.0), junctionModel,
71 HistoryManagerDevs.noHistory(simulator));
72 OtsAnimationPanel animationPanel = new OtsAnimationPanel(junctionModel.getNetwork().getExtent(),
73 new Dimension(800, 600), simulator, junctionModel, DEFAULT_GTU_COLORERS, junctionModel.getNetwork());
74 TurboRoundaboutDemo app = new TurboRoundaboutDemo("Turbo-Roundabout demo", animationPanel, junctionModel);
75 app.setExitOnClose(exitOnClose);
76 animationPanel.enableSimulationControlButtons();
77 }
78 catch (SimRuntimeException | NamingException | RemoteException | DsolException exception)
79 {
80 exception.printStackTrace();
81 }
82 }
83
84
85
86
87 public static class TurboRoundaboutModel extends AbstractOtsModel
88 {
89
90 private static final long serialVersionUID = 20161211L;
91
92
93 private RoadNetwork network;
94
95
96
97
98 public TurboRoundaboutModel(final OtsSimulatorInterface simulator)
99 {
100 super(simulator);
101 }
102
103 @Override
104 public void constructModel() throws SimRuntimeException
105 {
106 try
107 {
108 URL xmlURL = URLResource.getResource("/resources/conflict/TurboRoundabout.xml");
109 this.network = new RoadNetwork("TurboRoundabout", getSimulator());
110 new XmlParser(this.network).setUrl(xmlURL).build();
111 }
112 catch (Exception exception)
113 {
114 exception.printStackTrace();
115 }
116 }
117
118 @Override
119 public RoadNetwork getNetwork()
120 {
121 return this.network;
122 }
123
124 }
125 }