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
21
22
23
24
25
26
27
28
29 public class ShapeModel implements OTSModelInterface
30 {
31
32 private static final long serialVersionUID = 20140815L;
33
34
35 private DEVSSimulatorInterface.TimeDoubleUnit simulator;
36
37
38 private Map<String, OTSNode> nodes;
39
40
41 private Map<String, Link> shpLinks;
42
43
44 private OTSNetwork network = new OTSNetwork("shape model network");
45
46
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
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
68 @Override
69 public final SimulatorInterface<Time, Duration, SimTimeDoubleUnit> getSimulator()
70 {
71 return this.simulator;
72 }
73
74
75 @Override
76 public final OTSNetwork getNetwork()
77 {
78 return this.network;
79 }
80
81 }