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.OTSNetwork;
15 import org.opentrafficsim.core.network.OTSNode;
16
17 import nl.tudelft.simulation.dsol.SimRuntimeException;
18 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
19
20
21
22
23
24
25
26
27
28
29
30 public class ShapeModel implements OTSModelInterface
31 {
32
33 private static final long serialVersionUID = 20140815L;
34
35
36 private OTSDEVSSimulatorInterface simulator;
37
38
39 private Map<String, OTSNode> nodes;
40
41
42 private Map<String, Link> shpLinks;
43
44
45 private OTSNetwork network = new OTSNetwork("shape model network");
46
47
48 @Override
49 public final void constructModel(final SimulatorInterface<Time, Duration, OTSSimTimeDouble> theSimulator)
50 throws SimRuntimeException, RemoteException
51 {
52 this.simulator = (OTSDEVSSimulatorInterface) theSimulator;
53 try
54 {
55
56 this.nodes = ShapeFileReader.readNodes(network, "/gis/TESTcordonnodes.shp", "NODENR", true, true);
57 this.shpLinks = new HashMap<>();
58 ShapeFileReader.readLinks(network, "/gis/TESTcordonlinks_aangevuld.shp", this.shpLinks, this.nodes, this.simulator);
59
60 this.simulator.scheduleEventAbs(Time.ZERO, this, this, "ntmFlowTimestep", null);
61 }
62 catch (Throwable exception)
63 {
64 exception.printStackTrace();
65 }
66 }
67
68
69 @Override
70 public final SimulatorInterface<Time, Duration, OTSSimTimeDouble> getSimulator() throws RemoteException
71 {
72 return this.simulator;
73 }
74
75
76 @Override
77 public final OTSNetwork getNetwork()
78 {
79 return this.network;
80 }
81
82 }