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