View Javadoc
1   package org.opentrafficsim.demo.geometry.shape;
2   
3   import java.rmi.RemoteException;
4   import java.util.HashMap;
5   import java.util.Map;
6   
7   import org.djunits.unit.TimeUnit;
8   import org.djunits.value.vdouble.scalar.Duration;
9   import org.djunits.value.vdouble.scalar.Time;
10  import org.opentrafficsim.core.dsol.OTSDEVSSimulatorInterface;
11  import org.opentrafficsim.core.dsol.OTSModelInterface;
12  import org.opentrafficsim.core.dsol.OTSSimTimeDouble;
13  import org.opentrafficsim.core.network.Link;
14  import org.opentrafficsim.core.network.Network;
15  import org.opentrafficsim.core.network.OTSNetwork;
16  import org.opentrafficsim.core.network.OTSNode;
17  
18  import nl.tudelft.simulation.dsol.SimRuntimeException;
19  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
20  
21  /**
22   * <p>
23   * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
24   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
25   * <p>
26   * $LastChangedDate: 2016-10-16 14:55:54 +0200 (Sun, 16 Oct 2016) $, @version $Revision: 2386 $, by $Author: averbraeck $,
27   * initial version Sep 9, 2014 <br>
28   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
29   * @author <a href="http://www.citg.tudelft.nl">Guus Tamminga</a>
30   */
31  public class ShapeModel implements OTSModelInterface
32  {
33      /** */
34      private static final long serialVersionUID = 20140815L;
35  
36      /** The simulator. */
37      private OTSDEVSSimulatorInterface simulator;
38  
39      /** Nodes from shape file. */
40      private Map<String, OTSNode> nodes;
41  
42      /** Links from shape file. */
43      private Map<String, Link> shpLinks;
44  
45      /** {@inheritDoc} */
46      @Override
47      public final void constructModel(final SimulatorInterface<Time, Duration, OTSSimTimeDouble> theSimulator)
48              throws SimRuntimeException, RemoteException
49      {
50          this.simulator = (OTSDEVSSimulatorInterface) theSimulator;
51          Network network = new OTSNetwork("shape model network");
52          try
53          {
54              // Read the shape files with the function:
55              this.nodes = ShapeFileReader.readNodes(network, "/gis/TESTcordonnodes.shp", "NODENR", true, true);
56              this.shpLinks = new HashMap<>();
57              ShapeFileReader.readLinks(network, "/gis/TESTcordonlinks_aangevuld.shp", this.shpLinks, this.nodes, this.simulator);
58  
59              this.simulator.scheduleEventAbs(new Time(0.0, TimeUnit.SECOND), this, this, "ntmFlowTimestep", null);
60          }
61          catch (Throwable exception)
62          {
63              exception.printStackTrace();
64          }
65      }
66  
67      /** {@inheritDoc} */
68      @Override
69      public final SimulatorInterface<Time, Duration, OTSSimTimeDouble> getSimulator() throws RemoteException
70      {
71          return this.simulator;
72      }
73  
74  }