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
23
24
25
26
27
28
29
30
31 public class ShapeModel implements OTSModelInterface
32 {
33
34 private static final long serialVersionUID = 20140815L;
35
36
37 private OTSDEVSSimulatorInterface simulator;
38
39
40 private Map<String, OTSNode> nodes;
41
42
43 private Map<String, Link> shpLinks;
44
45
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
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
68 @Override
69 public final SimulatorInterface<Time, Duration, OTSSimTimeDouble> getSimulator() throws RemoteException
70 {
71 return this.simulator;
72 }
73
74 }