View Javadoc
1   package org.opentrafficsim.road.test;
2   
3   import java.awt.geom.Rectangle2D;
4   import java.awt.geom.Rectangle2D.Double;
5   import java.io.IOException;
6   import java.net.URL;
7   import java.util.ArrayList;
8   
9   import javax.naming.NamingException;
10  import javax.swing.JPanel;
11  import javax.swing.SwingUtilities;
12  import javax.xml.parsers.ParserConfigurationException;
13  
14  import nl.tudelft.simulation.dsol.SimRuntimeException;
15  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
16  import nl.tudelft.simulation.language.io.URLResource;
17  
18  import org.djunits.unit.TimeUnit;
19  import org.djunits.value.vdouble.scalar.DoubleScalar;
20  import org.djunits.value.vdouble.scalar.Duration;
21  import org.djunits.value.vdouble.scalar.Time;
22  import org.opentrafficsim.core.dsol.OTSDEVSSimulatorInterface;
23  import org.opentrafficsim.core.dsol.OTSModelInterface;
24  import org.opentrafficsim.core.dsol.OTSSimTimeDouble;
25  import org.opentrafficsim.core.geometry.OTSGeometryException;
26  import org.opentrafficsim.core.gtu.GTUException;
27  import org.opentrafficsim.core.gtu.animation.GTUColorer;
28  import org.opentrafficsim.core.network.NetworkException;
29  import org.opentrafficsim.road.network.factory.xml.XmlNetworkLaneParser;
30  import org.opentrafficsim.simulationengine.AbstractWrappableAnimation;
31  import org.opentrafficsim.simulationengine.OTSSimulationException;
32  import org.opentrafficsim.simulationengine.properties.AbstractProperty;
33  import org.opentrafficsim.simulationengine.properties.PropertyException;
34  import org.xml.sax.SAXException;
35  
36  /**
37   * Four stop demo
38   * <p>
39   * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
40   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
41   * <p>
42   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Dec 1, 2015 <br>
43   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
44   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
45   * @author Wouter Schakel
46   */
47  public class LMRSTests extends AbstractWrappableAnimation
48  {
49      /**
50       * Main program.
51       * @param args String[]; the command line arguments (not used)
52       * @throws SimRuntimeException should never happen
53       */
54      public static void main(final String[] args) throws SimRuntimeException
55      {
56          SwingUtilities.invokeLater(new Runnable()
57          {
58              @Override
59              public void run()
60              {
61                  try
62                  {
63                  	LMRSTests xmlModel = new LMRSTests();
64                      // 1 hour simulation run for testing
65                      xmlModel.buildAnimator(new Time(0.0, TimeUnit.SECOND), new Duration(0.0, TimeUnit.SECOND),
66                          new Duration(60.0, TimeUnit.MINUTE), new ArrayList<AbstractProperty<?>>(), null, true);
67                  }
68                  catch (SimRuntimeException | NamingException | OTSSimulationException | PropertyException exception)
69                  {
70                      exception.printStackTrace();
71                  }
72              }
73          });
74      }
75  
76      /** {@inheritDoc} */
77      @Override
78      public final String shortName()
79      {
80          return "TestXMLModel";
81      }
82  
83      /** {@inheritDoc} */
84      @Override
85      public final String description()
86      {
87          return "TestXMLModel";
88      }
89  
90      /** {@inheritDoc} */
91      @Override
92      public final void stopTimersThreads()
93      {
94          super.stopTimersThreads();
95      }
96  
97      /** {@inheritDoc} */
98      @Override
99      protected final JPanel makeCharts()
100     {
101         return null;
102     }
103 
104     /** {@inheritDoc} */
105     @Override
106     protected final OTSModelInterface makeModel(final GTUColorer colorer)
107     {
108         return new TestXMLModel();
109     }
110 
111     /** {@inheritDoc} */
112     @Override
113     protected final Double makeAnimationRectangle()
114     {
115         return new Rectangle2D.Double(-100, -100, 3200, 200);
116     }
117 
118     /** {@inheritDoc} */
119     @Override
120     public String toString()
121     {
122         return "LMRSTests []";
123     }
124 
125     /**
126      * Model to test the XML parser.
127      * <p>
128      * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. <br>
129      * All rights reserved. BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim
130      * License</a>.
131      * <p>
132      * $LastChangedDate: 2015-09-14 01:33:02 +0200 (Mon, 14 Sep 2015) $, @version $Revision: 1401 $, by $Author: averbraeck $,
133      * initial version un 27, 2015 <br>
134      * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
135      * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
136      */
137     class TestXMLModel implements OTSModelInterface
138     {
139         /** */
140         private static final long serialVersionUID = 20141121L;
141 
142         /** The simulator. */
143         private OTSDEVSSimulatorInterface simulator;
144 
145         /** {@inheritDoc} */
146         @Override
147         public final
148             void
149             constructModel(
150                 final SimulatorInterface<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble> pSimulator)
151                 throws SimRuntimeException
152         {
153             this.simulator = (OTSDEVSSimulatorInterface) pSimulator;
154             //URL url = URLResource.getResource("/LMRSStraightTest.xml");
155             //URL url = URLResource.getResource("/LMRSLaneDropTest.xml");
156             URL url = URLResource.getResource("/LMRSOnRampTest.xml");
157             //URL url = URLResource.getResource("/LMRSOnRampTaperTest.xml");
158             //URL url = URLResource.getResource("/networkv2_90km_V5.xml");
159             XmlNetworkLaneParser nlp = new XmlNetworkLaneParser(this.simulator);
160             try
161             {
162                 nlp.build(url);
163             }
164             catch (NetworkException | ParserConfigurationException | SAXException | IOException | NamingException
165                 | GTUException | OTSGeometryException exception)
166             {
167                 exception.printStackTrace();
168             }
169         }
170 
171         /** {@inheritDoc} */
172         @Override
173         public SimulatorInterface<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble>
174             getSimulator()
175 
176         {
177             return this.simulator;
178         }
179 
180         /** {@inheritDoc} */
181         @Override
182         public final String toString()
183         {
184             return "TestXMLModel [simulator=" + this.simulator + "]";
185         }
186 
187     }
188 
189 }