View Javadoc
1   package org.opentrafficsim.demo;
2   
3   import java.rmi.RemoteException;
4   import java.util.ArrayList;
5   import java.util.HashSet;
6   import java.util.LinkedHashSet;
7   import java.util.List;
8   import java.util.Set;
9   import java.util.SortedMap;
10  import java.util.TreeMap;
11  
12  import javax.naming.NamingException;
13  
14  import org.djunits.unit.DurationUnit;
15  import org.djunits.unit.LengthUnit;
16  import org.djunits.unit.SpeedUnit;
17  import org.djunits.unit.UNITS;
18  import org.djunits.value.vdouble.scalar.DoubleScalar;
19  import org.djunits.value.vdouble.scalar.Duration;
20  import org.djunits.value.vdouble.scalar.Length;
21  import org.djunits.value.vdouble.scalar.Speed;
22  import org.opentrafficsim.base.parameters.ParameterException;
23  import org.opentrafficsim.core.distributions.Distribution;
24  import org.opentrafficsim.core.distributions.Distribution.FrequencyAndObject;
25  import org.opentrafficsim.core.distributions.Generator;
26  import org.opentrafficsim.core.distributions.ProbabilityException;
27  import org.opentrafficsim.core.dsol.AbstractOTSModel;
28  import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
29  import org.opentrafficsim.core.geometry.OTSGeometryException;
30  import org.opentrafficsim.core.geometry.OTSPoint3D;
31  import org.opentrafficsim.core.gtu.GTU;
32  import org.opentrafficsim.core.gtu.GTUDirectionality;
33  import org.opentrafficsim.core.gtu.GTUException;
34  import org.opentrafficsim.core.gtu.GTUType;
35  import org.opentrafficsim.core.idgenerator.IdGenerator;
36  import org.opentrafficsim.core.network.Network;
37  import org.opentrafficsim.core.network.NetworkException;
38  import org.opentrafficsim.core.network.Node;
39  import org.opentrafficsim.core.network.OTSNode;
40  import org.opentrafficsim.core.network.route.FixedRouteGenerator;
41  import org.opentrafficsim.core.network.route.ProbabilisticRouteGenerator;
42  import org.opentrafficsim.core.network.route.Route;
43  import org.opentrafficsim.core.parameters.ParameterFactory;
44  import org.opentrafficsim.core.units.distributions.ContinuousDistDoubleScalar;
45  import org.opentrafficsim.road.gtu.generator.CFRoomChecker;
46  import org.opentrafficsim.road.gtu.generator.GeneratorPositions;
47  import org.opentrafficsim.road.gtu.generator.LaneBasedGTUGenerator;
48  import org.opentrafficsim.road.gtu.generator.characteristics.LaneBasedTemplateGTUType;
49  import org.opentrafficsim.road.gtu.generator.characteristics.LaneBasedTemplateGTUTypeDistribution;
50  import org.opentrafficsim.road.gtu.lane.tactical.following.IDMPlusFactory;
51  import org.opentrafficsim.road.gtu.lane.tactical.lmrs.DefaultLMRSPerceptionFactory;
52  import org.opentrafficsim.road.gtu.lane.tactical.lmrs.LMRSFactory;
53  import org.opentrafficsim.road.gtu.strategical.LaneBasedStrategicalPlanner;
54  import org.opentrafficsim.road.gtu.strategical.LaneBasedStrategicalPlannerFactory;
55  import org.opentrafficsim.road.gtu.strategical.route.LaneBasedStrategicalRoutePlannerFactory;
56  import org.opentrafficsim.road.network.OTSRoadNetwork;
57  import org.opentrafficsim.road.network.factory.LaneFactory;
58  import org.opentrafficsim.road.network.lane.CrossSectionLink;
59  import org.opentrafficsim.road.network.lane.DirectedLanePosition;
60  import org.opentrafficsim.road.network.lane.Lane;
61  import org.opentrafficsim.road.network.lane.LaneType;
62  import org.opentrafficsim.road.network.lane.object.sensor.SinkSensor;
63  
64  import nl.tudelft.simulation.dsol.SimRuntimeException;
65  import nl.tudelft.simulation.dsol.model.inputparameters.InputParameterDouble;
66  import nl.tudelft.simulation.dsol.model.inputparameters.InputParameterException;
67  import nl.tudelft.simulation.dsol.model.inputparameters.InputParameterMap;
68  import nl.tudelft.simulation.dsol.model.inputparameters.InputParameterSelectionMap;
69  import nl.tudelft.simulation.event.EventInterface;
70  import nl.tudelft.simulation.event.EventListenerInterface;
71  import nl.tudelft.simulation.event.EventType;
72  import nl.tudelft.simulation.jstats.distributions.DistContinuous;
73  import nl.tudelft.simulation.jstats.distributions.DistErlang;
74  import nl.tudelft.simulation.jstats.distributions.DistUniform;
75  import nl.tudelft.simulation.jstats.streams.MersenneTwister;
76  import nl.tudelft.simulation.jstats.streams.StreamInterface;
77  
78  /**
79   * Simulate a single lane road of 5 km length. Vehicles are generated at a constant rate of 1500 veh/hour. At time 300s a
80   * blockade is inserted at position 4 km; this blockade is removed at time 500s. The used car following algorithm is IDM+
81   * <a href="http://opentrafficsim.org/downloads/MOTUS%20reference.pdf"><i>Integrated Lane Change Model with Relaxation and
82   * Synchronization</i>, by Wouter J. Schakel, Victor L. Knoop and Bart van Arem, 2012</a>. <br>
83   * Output is a set of block charts:
84   * <ul>
85   * <li>Traffic density</li>
86   * <li>Speed</li>
87   * <li>Flow</li>
88   * <li>Acceleration</li>
89   * </ul>
90   * All these graphs display simulation time along the horizontal axis and distance along the road along the vertical axis.
91   * <p>
92   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
93   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
94   * <p>
95   * $LastChangedDate: 2019-01-06 01:35:05 +0100 (Sun, 06 Jan 2019) $, @version $Revision: 4831 $, by $Author: averbraeck $,
96   * initial version ug 1, 2014 <br>
97   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
98   */
99  public class NetworksModel extends AbstractOTSModel implements EventListenerInterface, UNITS
100 {
101     /** */
102     private static final long serialVersionUID = 20140815L;
103 
104     /** The network. */
105     private final OTSRoadNetwork network = new OTSRoadNetwork("network", true);
106 
107     /** Strategical planner generator for cars. */
108     private LaneBasedStrategicalPlannerFactory<LaneBasedStrategicalPlanner> strategicalPlannerGeneratorCars = null;
109 
110     /** Strategical planner generator for trucks. */
111     private LaneBasedStrategicalPlannerFactory<LaneBasedStrategicalPlanner> strategicalPlannerGeneratorTrucks = null;
112 
113     /** The probability that the next generated GTU is a passenger car. */
114     private double carProbability;
115 
116     /** Minimum distance. */
117     private Length minimumDistance = new Length(0, METER);
118 
119     /** Maximum distance. */
120     private Length maximumDistance = new Length(5000, METER);
121 
122     /** The random number generator used to decide what kind of GTU to generate. */
123     private StreamInterface stream = new MersenneTwister(12345);
124 
125     /** The route generator for the main line. */
126     private Generator<Route> routeGeneratorMain;
127 
128     /** The route generator for the onramp. */
129     private Generator<Route> routeGeneratorRamp;
130 
131     /** The speed limit. */
132     private Speed speedLimit = new Speed(60, KM_PER_HOUR);
133 
134     /** The sequence of Lanes that all vehicles will follow. */
135     private List<List<Lane>> paths = new ArrayList<>();
136 
137     /** Id generator (used by all generators). */
138     private IdGenerator idGenerator = new IdGenerator("");
139 
140     /** The probability distribution for the variable part of the headway. */
141     private DistContinuous headwayGenerator;
142 
143     /**
144      * @param simulator OTSSimulatorInterface; the simulator for this model
145      */
146     public NetworksModel(final OTSSimulatorInterface simulator)
147     {
148         super(simulator);
149         createInputParameters();
150     }
151 
152     /**
153      * Create input parameters for the networks demo.
154      */
155     private void createInputParameters()
156     {
157         InputParameterHelper.makeInputParameterMapCarTruck(this.inputParameterMap, 1.0);
158         try
159         {
160             InputParameterMap genericMap = (InputParameterMap) this.inputParameterMap.get("generic");
161 
162             genericMap.add(new InputParameterDouble("flow", "Flow per input lane", "Traffic flow per input lane", 500d, 0d,
163                     3000d, true, true, "%.0f veh/h", 1.5));
164 
165             SortedMap<String, String> networks = new TreeMap<>();
166             networks.put("Merge 1 plus 1 into 1", "M111");
167             networks.put("Merge 2 plus 1 into 2", "M212");
168             networks.put("Merge 2 plus 2 into 4", "M224");
169             networks.put("Split 1 into 1 plus 1", "S111");
170             networks.put("Split 2 into 1 plus 2", "S212");
171             networks.put("Split 4 into 2 plus 2", "S422");
172             InputParameterSelectionMap<String, String> paramSelect = new InputParameterSelectionMap<String, String>("network",
173                     "Network to run simulation for", "Network to run simulaton for", networks, "M111", 2.0);
174             genericMap.add(paramSelect);
175         }
176         catch (InputParameterException exception)
177         {
178             exception.printStackTrace();
179         }
180 
181     }
182 
183     /** {@inheritDoc} */
184     @Override
185     @SuppressWarnings("checkstyle:methodlength")
186     public final void constructModel() throws SimRuntimeException
187     {
188         this.network.addListener(this, Network.GTU_ADD_EVENT);
189         this.network.addListener(this, Network.GTU_REMOVE_EVENT);
190         try
191         {
192             GTUType car = this.network.getGtuType(GTUType.DEFAULTS.CAR);
193             this.carProbability = (double) getInputParameter("generic.carProbability");
194 
195             ParameterFactory params = new InputParameterHelper(getInputParameterMap());
196             this.strategicalPlannerGeneratorCars = new LaneBasedStrategicalRoutePlannerFactory(
197                     new LMRSFactory(new IDMPlusFactory(this.stream), new DefaultLMRSPerceptionFactory()), params);
198             this.strategicalPlannerGeneratorTrucks = new LaneBasedStrategicalRoutePlannerFactory(
199                     new LMRSFactory(new IDMPlusFactory(this.stream), new DefaultLMRSPerceptionFactory()), params);
200 
201             OTSNode from = new OTSNode(this.network, "From", new OTSPoint3D(0, 0, 0));
202             OTSNode end = new OTSNode(this.network, "End", new OTSPoint3D(2000, 0, 0));
203             OTSNode from2a = new OTSNode(this.network, "From2a", new OTSPoint3D(0, -50, 0));
204             OTSNode from2b = new OTSNode(this.network, "From2b", new OTSPoint3D(490, -2, 0));
205             OTSNode firstVia = new OTSNode(this.network, "Via1", new OTSPoint3D(500, 0, 0));
206             OTSNode end2a = new OTSNode(this.network, "End2a", new OTSPoint3D(1020, -2, 0));
207             OTSNode end2b = new OTSNode(this.network, "End2b", new OTSPoint3D(2000, -50, 0));
208             OTSNode secondVia = new OTSNode(this.network, "Via2", new OTSPoint3D(1000, 0, 0));
209 
210             String networkType = getInputParameter("generic.network").toString();
211             boolean merge = networkType.startsWith("M");
212             int lanesOnMain = Integer.parseInt("" + networkType.charAt(merge ? 1 : 3));
213             int lanesOnBranch = Integer.parseInt("" + networkType.charAt(2));
214             int lanesOnCommon = lanesOnMain + lanesOnBranch;
215             int lanesOnCommonCompressed = Integer.parseInt("" + networkType.charAt(merge ? 3 : 1));
216 
217             double contP = (double) getInputParameter("generic.flow");
218             Duration averageHeadway = new Duration(3600.0 / contP, SECOND);
219             Duration minimumHeadway = new Duration(3, SECOND);
220             this.headwayGenerator =
221                     new DistErlang(new MersenneTwister(1234), 4, DoubleScalar.minus(averageHeadway, minimumHeadway).getSI());
222 
223             LaneType laneType = this.network.getLaneType(LaneType.DEFAULTS.TWO_WAY_LANE);
224             if (merge)
225             {
226                 // provide a route -- at the merge point, the GTU can otherwise decide to "go back"
227                 ArrayList<Node> mainRouteNodes = new ArrayList<>();
228                 mainRouteNodes.add(from);
229                 mainRouteNodes.add(firstVia);
230                 mainRouteNodes.add(secondVia);
231                 mainRouteNodes.add(end);
232                 Route mainRoute = new Route("main", mainRouteNodes);
233                 this.routeGeneratorMain = new FixedRouteGenerator(mainRoute);
234 
235                 ArrayList<Node> rampRouteNodes = new ArrayList<>();
236                 rampRouteNodes.add(from2a);
237                 rampRouteNodes.add(from2b);
238                 rampRouteNodes.add(firstVia);
239                 rampRouteNodes.add(secondVia);
240                 rampRouteNodes.add(end);
241                 Route rampRoute = new Route("ramp", rampRouteNodes);
242                 this.routeGeneratorRamp = new FixedRouteGenerator(rampRoute);
243             }
244             else
245             {
246                 // determine the routes
247                 List<FrequencyAndObject<Route>> routeProbabilities = new ArrayList<>();
248 
249                 ArrayList<Node> mainRouteNodes = new ArrayList<>();
250                 mainRouteNodes.add(from);
251                 mainRouteNodes.add(firstVia);
252                 mainRouteNodes.add(secondVia);
253                 mainRouteNodes.add(end);
254                 Route mainRoute = new Route("main", mainRouteNodes);
255                 routeProbabilities.add(new FrequencyAndObject<>(lanesOnMain, mainRoute));
256 
257                 ArrayList<Node> sideRouteNodes = new ArrayList<>();
258                 sideRouteNodes.add(from);
259                 sideRouteNodes.add(firstVia);
260                 sideRouteNodes.add(secondVia);
261                 sideRouteNodes.add(end2a);
262                 sideRouteNodes.add(end2b);
263                 Route sideRoute = new Route("side", sideRouteNodes);
264                 routeProbabilities.add(new FrequencyAndObject<>(lanesOnBranch, sideRoute));
265                 try
266                 {
267                     this.routeGeneratorMain = new ProbabilisticRouteGenerator(routeProbabilities, new MersenneTwister(1234));
268                 }
269                 catch (ProbabilityException exception)
270                 {
271                     exception.printStackTrace();
272                 }
273             }
274 
275             if (merge)
276             {
277                 setupGenerator(LaneFactory.makeMultiLane(this.network, "From2a to From2b", from2a, from2b, null, lanesOnBranch,
278                         0, lanesOnCommon - lanesOnBranch, laneType, this.speedLimit, this.simulator));
279                 LaneFactory.makeMultiLaneBezier(this.network, "From2b to FirstVia", from2a, from2b, firstVia, secondVia,
280                         lanesOnBranch, lanesOnCommon - lanesOnBranch, lanesOnCommon - lanesOnBranch, laneType, this.speedLimit,
281                         this.simulator);
282             }
283             else
284             {
285                 LaneFactory.makeMultiLaneBezier(this.network, "SecondVia to end2a", firstVia, secondVia, end2a, end2b,
286                         lanesOnBranch, lanesOnCommon - lanesOnBranch, lanesOnCommon - lanesOnBranch, laneType, this.speedLimit,
287                         this.simulator);
288                 setupSink(LaneFactory.makeMultiLane(this.network, "end2a to end2b", end2a, end2b, null, lanesOnBranch,
289                         lanesOnCommon - lanesOnBranch, 0, laneType, this.speedLimit, this.simulator), laneType);
290             }
291 
292             Lane[] startLanes = LaneFactory.makeMultiLane(this.network, "From to FirstVia", from, firstVia, null,
293                     merge ? lanesOnMain : lanesOnCommonCompressed, laneType, this.speedLimit, this.simulator);
294             setupGenerator(startLanes);
295             Lane[] common = LaneFactory.makeMultiLane(this.network, "FirstVia to SecondVia", firstVia, secondVia, null,
296                     lanesOnCommon, laneType, this.speedLimit, this.simulator);
297             setupSink(
298                     LaneFactory.makeMultiLane(this.network, "SecondVia to end", secondVia, end, null,
299                             merge ? lanesOnCommonCompressed : lanesOnMain, laneType, this.speedLimit, this.simulator),
300                     laneType);
301 
302             for (int index = 0; index < lanesOnCommon; index++)
303             {
304                 this.paths.add(new ArrayList<Lane>());
305                 Lane lane = common[index];
306                 // Follow back
307                 while (lane.prevLanes(car).size() > 0)
308                 {
309                     if (lane.prevLanes(car).size() > 1)
310                     {
311                         throw new NetworkException("This network should not have lane merge points");
312                     }
313                     lane = lane.prevLanes(car).keySet().iterator().next();
314                 }
315                 // Follow forward
316                 while (true)
317                 {
318                     this.paths.get(index).add(lane);
319                     int branching = lane.nextLanes(car).size();
320                     if (branching == 0)
321                     {
322                         break;
323                     }
324                     if (branching > 1)
325                     {
326                         throw new NetworkException("This network should not have lane split points");
327                     }
328                     lane = lane.nextLanes(car).keySet().iterator().next();
329                 }
330             }
331         }
332         catch (SimRuntimeException | NetworkException | OTSGeometryException | InputParameterException | GTUException
333                 | ParameterException | NamingException | ProbabilityException exception)
334         {
335             exception.printStackTrace();
336         }
337     }
338 
339     /**
340      * Add a generator to an array of Lane.
341      * @param lanes Lane[]; the lanes that must get a generator at the start
342      * @return Lane[]; the lanes
343      * @throws GTUException when lane position out of bounds
344      * @throws SimRuntimeException when generation scheduling fails
345      * @throws ProbabilityException when probability distribution is wrong
346      * @throws ParameterException when a parameter is missing for the perception of the GTU
347      */
348     private Lane[] setupGenerator(final Lane[] lanes)
349             throws SimRuntimeException, GTUException, ProbabilityException, ParameterException
350     {
351         for (Lane lane : lanes)
352         {
353             makeGenerator(lane);
354         }
355         return lanes;
356     }
357 
358     /**
359      * Build a generator.
360      * @param lane Lane; the lane on which the generated GTUs are placed
361      * @return LaneBasedGTUGenerator
362      * @throws GTUException when lane position out of bounds
363      * @throws SimRuntimeException when generation scheduling fails
364      * @throws ProbabilityException when probability distribution is wrong
365      * @throws ParameterException when a parameter is missing for the perception of the GTU
366      */
367     private LaneBasedGTUGenerator makeGenerator(final Lane lane)
368             throws GTUException, SimRuntimeException, ProbabilityException, ParameterException
369     {
370         Distribution<LaneBasedTemplateGTUType> distribution = new Distribution<>(this.stream);
371         Length initialPosition = new Length(16, METER);
372         Set<DirectedLanePosition> initialPositions = new LinkedHashSet<>(1);
373         initialPositions.add(new DirectedLanePosition(lane, initialPosition, GTUDirectionality.DIR_PLUS));
374 
375         LaneBasedTemplateGTUType template = makeTemplate(this.stream, lane,
376                 new ContinuousDistDoubleScalar.Rel<Length, LengthUnit>(new DistUniform(this.stream, 3, 6), METER),
377                 new ContinuousDistDoubleScalar.Rel<Length, LengthUnit>(new DistUniform(this.stream, 1.6, 2.0), METER),
378                 new ContinuousDistDoubleScalar.Rel<Speed, SpeedUnit>(new DistUniform(this.stream, 140, 180), KM_PER_HOUR),
379                 initialPositions, this.strategicalPlannerGeneratorCars);
380         // System.out.println("Constructed template " + template);
381         distribution.add(new FrequencyAndObject<>(this.carProbability, template));
382         template = makeTemplate(this.stream, lane,
383                 new ContinuousDistDoubleScalar.Rel<Length, LengthUnit>(new DistUniform(this.stream, 8, 14), METER),
384                 new ContinuousDistDoubleScalar.Rel<Length, LengthUnit>(new DistUniform(this.stream, 2.0, 2.5), METER),
385                 new ContinuousDistDoubleScalar.Rel<Speed, SpeedUnit>(new DistUniform(this.stream, 100, 140), KM_PER_HOUR),
386                 initialPositions, this.strategicalPlannerGeneratorTrucks);
387         // System.out.println("Constructed template " + template);
388         distribution.add(new FrequencyAndObject<>(1.0 - this.carProbability, template));
389         LaneBasedTemplateGTUTypeDistribution templateDistribution = new LaneBasedTemplateGTUTypeDistribution(distribution);
390         LaneBasedGTUGenerator.RoomChecker roomChecker = new CFRoomChecker();
391         return new LaneBasedGTUGenerator(lane.getId(), new Generator<Duration>()
392         {
393             @SuppressWarnings("synthetic-access")
394             @Override
395             public Duration draw()
396             {
397                 return new Duration(NetworksModel.this.headwayGenerator.draw(), DurationUnit.SI);
398             }
399         }, templateDistribution, GeneratorPositions.create(initialPositions, this.stream), this.network, this.simulator,
400                 roomChecker, this.idGenerator);
401     }
402 
403     /**
404      * @param randStream StreamInterface; the random stream to use
405      * @param lane Lane; reference lane to generate GTUs on
406      * @param lengthDistribution ContinuousDistDoubleScalar.Rel&lt;Length,LengthUnit&gt;; distribution of the GTU length
407      * @param widthDistribution ContinuousDistDoubleScalar.Rel&lt;Length,LengthUnit&gt;; distribution of the GTU width
408      * @param maximumSpeedDistribution ContinuousDistDoubleScalar.Rel&lt;Speed,SpeedUnit&gt;; distribution of the GTU's maximum
409      *            speed
410      * @param initialPositions Set&lt;DirectedLanePosition&gt;; initial position(s) of the GTU on the Lane(s)
411      * @param strategicalPlannerFactory LaneBasedStrategicalPlannerFactory&lt;LaneBasedStrategicalPlanner&gt;; factory to
412      *            generate the strategical planner for the GTU
413      * @return template for a GTU
414      * @throws GTUException when characteristics cannot be initialized
415      */
416     LaneBasedTemplateGTUType makeTemplate(final StreamInterface randStream, final Lane lane,
417             final ContinuousDistDoubleScalar.Rel<Length, LengthUnit> lengthDistribution,
418             final ContinuousDistDoubleScalar.Rel<Length, LengthUnit> widthDistribution,
419             final ContinuousDistDoubleScalar.Rel<Speed, SpeedUnit> maximumSpeedDistribution,
420             final Set<DirectedLanePosition> initialPositions,
421             final LaneBasedStrategicalPlannerFactory<LaneBasedStrategicalPlanner> strategicalPlannerFactory) throws GTUException
422     {
423         return new LaneBasedTemplateGTUType(this.network.getGtuType(GTUType.DEFAULTS.CAR), new Generator<Length>()
424         {
425             @Override
426             public Length draw()
427             {
428                 return lengthDistribution.draw();
429             }
430         }, new Generator<Length>()
431         {
432             @Override
433             public Length draw()
434             {
435                 return widthDistribution.draw();
436             }
437         }, new Generator<Speed>()
438         {
439             @Override
440             public Speed draw()
441             {
442                 return maximumSpeedDistribution.draw();
443             }
444         }, strategicalPlannerFactory,
445                 lane.getParentLink().getStartNode().getId().equals("From") ? this.routeGeneratorMain : this.routeGeneratorRamp);
446 
447     }
448 
449     /**
450      * Append a sink to each lane of an array of Lanes.
451      * @param lanes Lane[]; the array of lanes
452      * @param laneType LaneType; the LaneType for cars
453      * @return Lane[]; the lanes
454      * @throws NetworkException on network inconsistency
455      * @throws OTSGeometryException on problem making the path for a link
456      */
457     private Lane[] setupSink(final Lane[] lanes, final LaneType laneType) throws NetworkException, OTSGeometryException
458     {
459         CrossSectionLink link = lanes[0].getParentLink();
460         Node to = link.getEndNode();
461         Node from = link.getStartNode();
462         double endLinkLength = 50; // [m]
463         double endX = to.getPoint().x + (endLinkLength / link.getLength().getSI()) * (to.getPoint().x - from.getPoint().x);
464         double endY = to.getPoint().y + (endLinkLength / link.getLength().getSI()) * (to.getPoint().y - from.getPoint().y);
465         Node end = new OTSNode(this.network, link.getId() + "END", new OTSPoint3D(endX, endY, to.getPoint().z));
466         CrossSectionLink endLink = LaneFactory.makeLink(this.network, link.getId() + "endLink", to, end, null, this.simulator);
467         for (Lane lane : lanes)
468         {
469             // Overtaking left and right allowed on the sinkLane
470             Lane sinkLane = new Lane(endLink, lane.getId() + "." + "sinkLane", lane.getLateralCenterPosition(1.0),
471                     lane.getLateralCenterPosition(1.0), lane.getWidth(1.0), lane.getWidth(1.0), laneType, this.speedLimit);
472             new SinkSensor(sinkLane, new Length(10.0, METER), this.simulator);
473         }
474         return lanes;
475     }
476 
477     /** The set of GTUs that we want to sample regularly. */
478     private Set<GTU> knownGTUs = new HashSet<>();
479 
480     /** {@inheritDoc} */
481     @Override
482     public void notify(final EventInterface event) throws RemoteException
483     {
484         EventType eventType = event.getType();
485         if (Network.GTU_ADD_EVENT.equals(eventType))
486         {
487             System.out.println("A GTU just got created. It's Id is " + (String) event.getContent());
488             this.knownGTUs.add(this.network.getGTU((String) event.getContent()));
489         }
490         else if (Network.GTU_REMOVE_EVENT.equals(eventType))
491         {
492             System.out.println("A GTU with id " + ((String) event.getContent()) + " was removed from the network");
493             this.knownGTUs.remove(this.network.getGTU((String) event.getContent()));
494         }
495     }
496 
497     /** {@inheritDoc} */
498     @Override
499     public OTSRoadNetwork getNetwork()
500     {
501         return this.network;
502     }
503 
504     /**
505      * @param index int; the rank number of the path
506      * @return List&lt;Lane&gt;; the set of lanes for the specified index
507      */
508     public final List<Lane> getPath(final int index)
509     {
510         return this.paths.get(index);
511     }
512 
513     /**
514      * Return the number of paths that can be used to show graphs.
515      * @return int; the number of paths that can be used to show graphs
516      */
517     public final int pathCount()
518     {
519         return this.paths.size();
520     }
521 
522     /**
523      * @return minimumDistance
524      */
525     public final Length getMinimumDistance()
526     {
527         return this.minimumDistance;
528     }
529 
530     /**
531      * @return maximumDistance
532      */
533     public final Length getMaximumDistance()
534     {
535         return this.maximumDistance;
536     }
537 
538 }