View Javadoc
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   * <p>
28   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
29   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
30   * </p>
31   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
32   * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
33   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
34   */
35  public class TurboRoundaboutDemo extends OtsSimulationApplication<TurboRoundaboutModel>
36  {
37      /** */
38      private static final long serialVersionUID = 20161211L;
39  
40      /**
41       * Create a T-Junction demo.
42       * @param title the title of the Frame
43       * @param panel the tabbed panel to display
44       * @param model the model
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       * Main program.
53       * @param args the command line arguments (not used)
54       */
55      public static void main(final String[] args)
56      {
57          demo(true);
58      }
59  
60      /**
61       * Start the demo.
62       * @param exitOnClose when running stand-alone: true; when running as part of a demo: false
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       * The simulation model.
86       */
87      public static class TurboRoundaboutModel extends AbstractOtsModel
88      {
89          /** */
90          private static final long serialVersionUID = 20161211L;
91  
92          /** The network. */
93          private RoadNetwork network;
94  
95          /**
96           * @param simulator the simulator for this model
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 }