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.value.vdouble.scalar.Duration;
8   import org.djunits.value.vdouble.scalar.Time;
9   import org.opentrafficsim.core.dsol.OTSModelInterface;
10  import org.opentrafficsim.core.network.Link;
11  import org.opentrafficsim.core.network.OTSNetwork;
12  import org.opentrafficsim.core.network.OTSNode;
13  
14  import nl.tudelft.simulation.dsol.SimRuntimeException;
15  import nl.tudelft.simulation.dsol.simtime.SimTimeDoubleUnit;
16  import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
17  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
18  
19  /**
20   * <p>
21   * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
22   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
23   * <p>
24   * $LastChangedDate: 2018-09-19 13:55:45 +0200 (Wed, 19 Sep 2018) $, @version $Revision: 4006 $, by $Author: averbraeck $,
25   * initial version Sep 9, 2014 <br>
26   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
27   * @author <a href="http://www.citg.tudelft.nl">Guus Tamminga</a>
28   */
29  public class ShapeModel implements OTSModelInterface
30  {
31      /** */
32      private static final long serialVersionUID = 20140815L;
33  
34      /** The simulator. */
35      private DEVSSimulatorInterface.TimeDoubleUnit simulator;
36  
37      /** Nodes from shape file. */
38      private Map<String, OTSNode> nodes;
39  
40      /** Links from shape file. */
41      private Map<String, Link> shpLinks;
42      
43      /** the network. */
44      private OTSNetwork network = new OTSNetwork("shape model network");
45  
46      /** {@inheritDoc} */
47      @Override
48      public final void constructModel(final SimulatorInterface<Time, Duration, SimTimeDoubleUnit> theSimulator)
49              throws SimRuntimeException
50      {
51          this.simulator = (DEVSSimulatorInterface.TimeDoubleUnit) theSimulator;
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(Time.ZERO, 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, SimTimeDoubleUnit> getSimulator()
70      {
71          return this.simulator;
72      }
73  
74      /** {@inheritDoc} */
75      @Override
76      public final OTSNetwork getNetwork()
77      {
78          return this.network;
79      }
80      
81  }