View Javadoc
1   package org.opentrafficsim.road.gtu.generator;
2   
3   import java.io.Serializable;
4   import java.rmi.RemoteException;
5   import java.util.Collections;
6   import java.util.LinkedHashMap;
7   import java.util.LinkedHashSet;
8   import java.util.LinkedList;
9   import java.util.Map;
10  import java.util.Queue;
11  import java.util.Set;
12  import java.util.SortedSet;
13  import java.util.TreeSet;
14  
15  import javax.media.j3d.Bounds;
16  import javax.naming.NamingException;
17  
18  import org.djunits.unit.DurationUnit;
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.djunits.value.vdouble.scalar.Time;
23  import org.opentrafficsim.base.Identifiable;
24  import org.opentrafficsim.base.TimeStampedObject;
25  import org.opentrafficsim.base.parameters.ParameterException;
26  import org.opentrafficsim.core.distributions.Generator;
27  import org.opentrafficsim.core.distributions.ProbabilityException;
28  import org.opentrafficsim.core.geometry.OTSGeometryException;
29  import org.opentrafficsim.core.gtu.GTUDirectionality;
30  import org.opentrafficsim.core.gtu.GTUException;
31  import org.opentrafficsim.core.gtu.GTUType;
32  import org.opentrafficsim.core.gtu.RelativePosition;
33  import org.opentrafficsim.core.gtu.animation.GTUColorer;
34  import org.opentrafficsim.core.idgenerator.IdGenerator;
35  import org.opentrafficsim.core.network.NetworkException;
36  import org.opentrafficsim.core.network.OTSNetwork;
37  import org.opentrafficsim.road.gtu.animation.DefaultCarAnimation;
38  import org.opentrafficsim.road.gtu.generator.GeneratorPositions.GeneratorLanePosition;
39  import org.opentrafficsim.road.gtu.generator.characteristics.LaneBasedGTUCharacteristics;
40  import org.opentrafficsim.road.gtu.generator.characteristics.LaneBasedGTUCharacteristicsGenerator;
41  import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
42  import org.opentrafficsim.road.gtu.lane.LaneBasedIndividualGTU;
43  import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayGTU;
44  import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayGTUReal;
45  import org.opentrafficsim.road.network.lane.CrossSectionLink;
46  import org.opentrafficsim.road.network.lane.DirectedLanePosition;
47  import org.opentrafficsim.road.network.lane.Lane;
48  import org.opentrafficsim.road.network.lane.LaneDirection;
49  
50  import nl.tudelft.simulation.dsol.SimRuntimeException;
51  import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
52  import nl.tudelft.simulation.language.Throw;
53  import nl.tudelft.simulation.language.d3.DirectedPoint;
54  
55  /**
56   * Lane based GTU generator. This generator generates lane based GTUs using a LaneBasedTemplateGTUType. The template is used to
57   * generate a set of GTU characteristics at the times implied by the headway generator. These sets are queued until there is
58   * sufficient room to construct a GTU at the specified lane locations. The speed of a construction GTU may be reduced to ensure
59   * it does not run into its immediate leader GTU.
60   * <p>
61   * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
62   * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
63   * <p>
64   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Mar 8, 2016 <br>
65   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
66   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
67   */
68  public class LaneBasedGTUGenerator implements Serializable, Identifiable, GTUGenerator
69  {
70      /** */
71      private static final long serialVersionUID = 20160000L;
72  
73      /** FIFO for templates that have not been generated yet due to insufficient room/headway, per position, and per link. */
74      private final Map<CrossSectionLink, Map<GeneratorLanePosition, Queue<TimeStampedObject<LaneBasedGTUCharacteristics>>>> unplacedTemplates =
75              new LinkedHashMap<>();
76  
77      /** Name of the GTU generator. */
78      private final String id;
79  
80      /** Time distribution that determines the interval times between GTUs. */
81      private final Generator<Duration> interarrivelTimeGenerator;
82  
83      /** Generates most properties of the GTUs. */
84      private final LaneBasedGTUCharacteristicsGenerator laneBasedGTUCharacteristicsGenerator;
85  
86      /** Total number of GTUs generated so far. */
87      private long generatedGTUs = 0;
88  
89      /** Retry interval for checking if a GTU can be placed. */
90      private Duration reTryInterval = new Duration(0.1, DurationUnit.SI);
91  
92      /** Location and initial direction provider for all generated GTUs. */
93      private final GeneratorPositions generatorPositions;
94  
95      /** Network. */
96      private final OTSNetwork network;
97  
98      /** Simulator. */
99      private final DEVSSimulatorInterface.TimeDoubleUnit simulator;
100 
101     /** The way that this generator checks if it is safe to construct and place the next lane based GTU. */
102     private final RoomChecker roomChecker;
103 
104     /** The GTU colorer that will be linked to each generated GTU. */
105     private final GTUColorer gtuColorer;
106 
107     /** ID generator. */
108     private final IdGenerator idGenerator;
109 
110     /** Initial distance over which lane changes shouldn't be performed. */
111     private Length noLaneChangeDistance = null;
112 
113     /** Vehicle generation is ignored on these lanes. */
114     private Set<LaneDirection> disabled = new LinkedHashSet<>();
115 
116     /**
117      * Construct a new lane base GTU generator.
118      * @param id String; name of the new GTU generator
119      * @param interarrivelTimeGenerator Generator&lt;Duration&gt;; generator for the interval times between GTUs
120      * @param gtuColorer GTUColorer; the GTU colorer that will be used by all generated GTUs
121      * @param laneBasedGTUCharacteristicsGenerator LaneBasedGTUCharacteristicsGenerator; generator of the characteristics of
122      *            each GTU
123      * @param generatorPositions GeneratorPositions; location and initial direction provider for all generated GTUs
124      * @param network OTSNetwork; the OTS network that owns the generated GTUs
125      * @param simulator DEVSSimulatorInterface.TimeDoubleUnit; simulator
126      * @param roomChecker LaneBasedGTUGenerator.RoomChecker; the way that this generator checks that there is sufficient room to
127      *            place a new GTU
128      * @param idGenerator IdGenerator; id generator
129      * @throws SimRuntimeException when <cite>startTime</cite> lies before the current simulation time
130      * @throws ProbabilityException pe
131      * @throws ParameterException if drawing from the interarrival generator fails
132      */
133     public LaneBasedGTUGenerator(final String id, final Generator<Duration> interarrivelTimeGenerator,
134             final GTUColorer gtuColorer, final LaneBasedGTUCharacteristicsGenerator laneBasedGTUCharacteristicsGenerator,
135             final GeneratorPositions generatorPositions, final OTSNetwork network,
136             final DEVSSimulatorInterface.TimeDoubleUnit simulator, final RoomChecker roomChecker, final IdGenerator idGenerator)
137             throws SimRuntimeException, ProbabilityException, ParameterException
138     {
139         this.id = id;
140         this.interarrivelTimeGenerator = interarrivelTimeGenerator;
141         this.laneBasedGTUCharacteristicsGenerator = laneBasedGTUCharacteristicsGenerator;
142         this.generatorPositions = generatorPositions;
143         this.network = network;
144         this.simulator = simulator;
145         this.roomChecker = roomChecker;
146         this.gtuColorer = gtuColorer;
147         this.idGenerator = idGenerator;
148         Duration headway = this.interarrivelTimeGenerator.draw();
149         if (headway != null) // otherwise no demand at all
150         {
151             simulator.scheduleEventRel(headway, this, this, "generateCharacteristics", new Object[] {});
152         }
153     }
154 
155     /**
156      * Sets the initial distance over which lane changes shouldn't be performed.
157      * @param noLaneChangeDistance Length; initial distance over which lane changes shouldn't be performed
158      */
159     public void setNoLaneChangeDistance(final Length noLaneChangeDistance)
160     {
161         this.noLaneChangeDistance = noLaneChangeDistance;
162     }
163 
164     /**
165      * Generate the characteristics of the next GTU.
166      * @throws ProbabilityException when something is wrongly defined in the LaneBasedTemplateGTUType
167      * @throws SimRuntimeException when this method fails to re-schedule itself or the call to the method that tries to place a
168      *             GTU on the road
169      * @throws ParameterException in case of a parameter problem
170      * @throws GTUException if strategical planner cannot generate a plan
171      */
172     @SuppressWarnings("unused")
173     private void generateCharacteristics() throws ProbabilityException, SimRuntimeException, ParameterException, GTUException
174     {
175         synchronized (this.unplacedTemplates)
176         {
177             this.generatedGTUs++;
178             LaneBasedGTUCharacteristics characteristics = this.laneBasedGTUCharacteristicsGenerator.draw();
179             GTUType gtuType = characteristics.getGTUType();
180             // gather information on number of unplaced templates per lane, and per link, for the drawing of a new position
181             Map<CrossSectionLink, Map<Integer, Integer>> unplaced = new LinkedHashMap<>();
182             for (CrossSectionLink link : this.unplacedTemplates.keySet())
183             {
184                 Map<Integer, Integer> linkMap = new LinkedHashMap<>();
185                 Map<GeneratorLanePosition, Queue<TimeStampedObject<LaneBasedGTUCharacteristics>>> linkTemplates =
186                         this.unplacedTemplates.get(link);
187                 for (GeneratorLanePosition lanePosition : linkTemplates.keySet())
188                 {
189                     linkMap.put(lanePosition.getLaneNumber(), linkTemplates.get(lanePosition).size());
190                 }
191                 unplaced.put(link, linkMap);
192             }
193             // position draw
194             Speed desiredSpeed = characteristics.getStrategicalPlannerFactory().peekDesiredSpeed(gtuType,
195                     this.generatorPositions.speedLimit(gtuType), characteristics.getMaximumSpeed());
196             GeneratorLanePosition lanePosition =
197                     this.generatorPositions.draw(gtuType, unplaced, desiredSpeed, characteristics.getRoute());
198             // add template in the right map location
199             if (!this.unplacedTemplates.containsKey(lanePosition.getLink()))
200             {
201                 this.unplacedTemplates.put(lanePosition.getLink(), new LinkedHashMap<>());
202             }
203             Map<GeneratorLanePosition, Queue<TimeStampedObject<LaneBasedGTUCharacteristics>>> linkMap =
204                     this.unplacedTemplates.get(lanePosition.getLink());
205             if (!linkMap.containsKey(lanePosition))
206             {
207                 linkMap.put(lanePosition, new LinkedList<>());
208             }
209             Queue<TimeStampedObject<LaneBasedGTUCharacteristics>> queue = linkMap.get(lanePosition);
210             queue.add(new TimeStampedObject<LaneBasedGTUCharacteristics>(characteristics, this.simulator.getSimulatorTime()));
211             if (queue.size() == 1)
212             {
213                 this.simulator.scheduleEventNow(this, this, "tryToPlaceGTU", new Object[] { lanePosition });
214             }
215         }
216         Duration headway = this.interarrivelTimeGenerator.draw();
217         if (headway != null)
218         {
219             this.simulator.scheduleEventRel(headway, this, this, "generateCharacteristics", new Object[] {});
220         }
221     }
222 
223     /**
224      * Check if the queue is non-empty and, if it is, try to place the GTUs in the queue on the road.
225      * @param position GeneratorLanePosition; position
226      * @throws SimRuntimeException should never happen
227      * @throws GTUException when something wrong in the definition of the GTU
228      * @throws OTSGeometryException when something is wrong in the definition of the GTU
229      * @throws NetworkException when something is wrong with the initial location of the GTU
230      * @throws NamingException ???
231      * @throws ProbabilityException pe
232      */
233     @SuppressWarnings("unused")
234     private void tryToPlaceGTU(final GeneratorLanePosition position) throws SimRuntimeException, GTUException, NamingException,
235             NetworkException, OTSGeometryException, ProbabilityException
236     {
237         TimeStampedObject<LaneBasedGTUCharacteristics> timedCharacteristics;
238         Queue<TimeStampedObject<LaneBasedGTUCharacteristics>> queue =
239                 this.unplacedTemplates.get(position.getLink()).get(position);
240 
241         // skip if disabled at this lane-direction
242         Set<LaneDirection> lanes = new LinkedHashSet<>();
243         for (DirectedLanePosition pos : position.getPosition())
244         {
245             lanes.add(pos.getLaneDirection());
246         }
247         if (!Collections.disjoint(this.disabled, lanes))
248         {
249             queue.remove();
250             return;
251         }
252 
253         synchronized (queue)
254         {
255             timedCharacteristics = queue.peek();
256         }
257         if (null == timedCharacteristics)
258         {
259             return; // Do not re-schedule this method
260         }
261 
262         LaneBasedGTUCharacteristics characteristics = timedCharacteristics.getObject();
263         SortedSet<HeadwayGTU> leaders = new TreeSet<>();
264         for (DirectedLanePosition dirPos : position.getPosition())
265         {
266             getFirstLeaders(dirPos.getLaneDirection(), dirPos.getPosition().neg().minus(characteristics.getFront()),
267                     dirPos.getPosition(), leaders);
268         }
269         Duration since = this.simulator.getSimulatorTime().minus(timedCharacteristics.getTimestamp());
270         Placement placement = this.roomChecker.canPlace(leaders, characteristics, since, position.getPosition());
271         if (placement.canPlace())
272         {
273             // There is enough room; remove the template from the queue and construct the new GTU
274             synchronized (queue)
275             {
276                 queue.remove();
277             }
278             placeGtu(characteristics, placement.getPosition(), placement.getSpeed());
279             if (queue.size() > 0)
280             {
281                 this.simulator.scheduleEventNow(this, this, "tryToPlaceGTU", new Object[] { position });
282             }
283         }
284         else if (queue.size() > 0)
285         {
286             this.simulator.scheduleEventRel(this.reTryInterval, this, this, "tryToPlaceGTU", new Object[] { position });
287         }
288     }
289 
290     /**
291      * @param characteristics LaneBasedGTUCharacteristics; characteristics
292      * @param position Set&lt;DirectedLanePosition&gt;; position
293      * @param speed Speed; speed
294      * @throws NamingException on exception
295      * @throws GTUException on exception
296      * @throws NetworkException on exception
297      * @throws SimRuntimeException on exception
298      * @throws OTSGeometryException on exception
299      */
300     final void placeGtu(final LaneBasedGTUCharacteristics characteristics, final Set<DirectedLanePosition> position,
301             final Speed speed) throws NamingException, GTUException, NetworkException, SimRuntimeException, OTSGeometryException
302     {
303         String gtuId = this.idGenerator.nextId();
304         LaneBasedIndividualGTU gtu = new LaneBasedIndividualGTU(gtuId, characteristics.getGTUType(),
305                 characteristics.getLength(), characteristics.getWidth(), characteristics.getMaximumSpeed(),
306                 characteristics.getFront(), this.simulator, this.network);
307         gtu.setMaximumAcceleration(characteristics.getMaximumAcceleration());
308         gtu.setMaximumDeceleration(characteristics.getMaximumDeceleration());
309         gtu.setVehicleModel(characteristics.getVehicleModel());
310         gtu.setNoLaneChangeDistance(this.noLaneChangeDistance);
311         gtu.initWithAnimation(
312                 characteristics.getStrategicalPlannerFactory().create(gtu, characteristics.getRoute(),
313                         characteristics.getOrigin(), characteristics.getDestination()),
314                 position, speed, DefaultCarAnimation.class, this.gtuColorer);
315     }
316 
317     /**
318      * Adds the first GTU on the lane to the set, or any number or leaders on downstream lane(s) if there is no GTU on the lane.
319      * @param lane LaneDirection; lane to search on
320      * @param startDistance Length; distance from generator location (nose) to start of the lane
321      * @param beyond Length; location to search downstream of which is the generator position, or the start for downstream lanes
322      * @param set Set&lt;HeadwayGTU&gt;; set to add the GTU's to
323      * @throws GTUException if a GTU is incorrectly positioned on a lane
324      */
325     private void getFirstLeaders(final LaneDirection lane, final Length startDistance, final Length beyond,
326             final Set<HeadwayGTU> set) throws GTUException
327     {
328         LaneBasedGTU next = lane.getLane().getGtuAhead(beyond, lane.getDirection(), RelativePosition.FRONT,
329                 this.simulator.getSimulatorTime());
330         if (next != null)
331         {
332             Length headway;
333             if (lane.getDirection().isPlus())
334             {
335                 headway = startDistance.plus(next.position(lane.getLane(), next.getRear()));
336             }
337             else
338             {
339                 headway = startDistance.plus(lane.getLane().getLength().minus(next.position(lane.getLane(), next.getRear())));
340             }
341             if (headway.si < 300)
342             {
343                 set.add(new HeadwayGTUReal(next, headway, true));
344             }
345             return;
346         }
347         Map<Lane, GTUDirectionality> downstreamLanes = lane.getLane().downstreamLanes(lane.getDirection(), GTUType.VEHICLE);
348         for (Lane downstreamLane : downstreamLanes.keySet())
349         {
350             Length startDistanceDownstream = startDistance.plus(lane.getLane().getLength());
351             if (startDistanceDownstream.si > 300)
352             {
353                 return;
354             }
355             GTUDirectionality dir = downstreamLanes.get(downstreamLane);
356             Length beyondDownstream = dir.isPlus() ? Length.ZERO : downstreamLane.getLength();
357             getFirstLeaders(new LaneDirection(downstreamLane, dir), startDistanceDownstream, beyondDownstream, set);
358         }
359     }
360 
361     /** {@inheritDoc} */
362     @Override
363     public final String toString()
364     {
365         return "LaneBasedGTUGenerator " + this.id + " on " + this.generatorPositions;
366     }
367 
368     /**
369      * @return generatedGTUs.
370      */
371     public final long getGeneratedGTUs()
372     {
373         return this.generatedGTUs;
374     }
375 
376     /**
377      * @param generatedGTUs set generatedGTUs.
378      */
379     public final void setGeneratedGTUs(final long generatedGTUs)
380     {
381         this.generatedGTUs = generatedGTUs;
382     }
383 
384     /**
385      * Retrieve the id of this LaneBasedGTUGenerator.
386      * @return String; the id of this LaneBasedGTUGenerator
387      */
388     @Override
389     public final String getId()
390     {
391         return this.id;
392     }
393 
394     /**
395      * Retrieve the GTUColorer that this LaneBasedGTUGenerator assigns to all generated GTUs.
396      * @return GtuColorer; the GTUColorer that this LaneBasedGTUGenerator assigns to all generated GTUs
397      */
398     public final GTUColorer getGtuColorer()
399     {
400         return this.gtuColorer;
401     }
402 
403     /**
404      * Disable the vehicle generator during the specific time. Underlying processes such as drawing characteristics and headways
405      * are continued, but simply will not result in the actual generation of a GTU.
406      * @param start Time; start time
407      * @param end Time; end time
408      * @param laneDirections Set&lt;LaneDirection&gt;; lanes to disable generation on
409      * @throws SimRuntimeException if time is incorrect
410      */
411     public void disable(final Time start, final Time end, final Set<LaneDirection> laneDirections) throws SimRuntimeException
412     {
413         Throw.when(end.lt(start), SimRuntimeException.class, "End time %s is before start time %s.", end, start);
414         this.simulator.scheduleEventAbs(start, this, this, "disable", new Object[] { laneDirections });
415         this.simulator.scheduleEventAbs(end, this, this, "enable", new Object[0]);
416     }
417 
418     /**
419      * Disables the generator.
420      * @param laneDirections Set&lt;LaneDirection&gt;; lanes to disable generation on
421      */
422     @SuppressWarnings("unused")
423     private void disable(final Set<LaneDirection> laneDirections)
424     {
425         this.disabled = laneDirections;
426     }
427 
428     /**
429      * Enables the generator.
430      */
431     @SuppressWarnings("unused")
432     private void enable()
433     {
434         this.disabled = new LinkedHashSet<>();
435     }
436 
437     /**
438      * Interface for class that checks that there is sufficient room for a proposed new GTU and returns the maximum safe speed
439      * and position for the proposed new GTU.
440      */
441     public interface RoomChecker
442     {
443         /**
444          * Return the maximum safe speed and position for a new GTU with the specified characteristics. Returns
445          * {@code Placement.NO} if there is no safe speed and position. This method might be called with an empty leader set
446          * such that the desired speed can be implemented.
447          * @param leaders SortedSet&lt;HeadwayGTU&gt;; leaders, usually 1, possibly more after a branch
448          * @param characteristics LaneBasedGTUCharacteristics; characteristics of the proposed new GTU
449          * @param since Duration; time since the GTU wanted to arrive
450          * @param initialPosition Set&lt;DirectedLanePosition&gt;; initial position
451          * @return Speed; maximum safe speed, or null if a GTU with the specified characteristics cannot be placed at the
452          *         current time
453          * @throws NetworkException this method may throw a NetworkException if it encounters an error in the network structure
454          * @throws GTUException on parameter exception
455          */
456         Placement canPlace(SortedSet<HeadwayGTU> leaders, LaneBasedGTUCharacteristics characteristics, Duration since,
457                 Set<DirectedLanePosition> initialPosition) throws NetworkException, GTUException;
458     }
459 
460     /**
461      * Placement contains the information that a {@code RoomChecker} returns.
462      * <p>
463      * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
464      * <br>
465      * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
466      * <p>
467      * @version $Revision$, $LastChangedDate$, by $Author$, initial version 12 jan. 2018 <br>
468      * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
469      * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
470      * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
471      */
472     public static final class Placement
473     {
474 
475         /** Value if the GTU cannot be placed. */
476         public static final Placement NO = new Placement();
477 
478         /** Speed. */
479         private final Speed speed;
480 
481         /** Position. */
482         private final Set<DirectedLanePosition> position;
483 
484         /**
485          * Constructor for NO.
486          */
487         private Placement()
488         {
489             this.speed = null;
490             this.position = null;
491         }
492 
493         /**
494          * Constructor.
495          * @param speed Speed; speed
496          * @param position Set&lt;DirectedLanePosition&gt;; position
497          */
498         public Placement(final Speed speed, final Set<DirectedLanePosition> position)
499         {
500             Throw.whenNull(speed, "Speed may not be null. Use Placement.NO if the GTU cannot be placed.");
501             Throw.whenNull(position, "Position may not be null. Use Placement.NO if the GTU cannot be placed.");
502             this.speed = speed;
503             this.position = position;
504         }
505 
506         /**
507          * Returns whether the GTU can be placed.
508          * @return whether the GTU can be placed
509          */
510         public boolean canPlace()
511         {
512             return this.speed != null && this.position != null;
513         }
514 
515         /**
516          * Returns the speed.
517          * @return Speed; speed
518          */
519         public Speed getSpeed()
520         {
521             return this.speed;
522         }
523 
524         /**
525          * Returns the position.
526          * @return Set&lt;DirectedLanePosition&gt;; position
527          */
528         public Set<DirectedLanePosition> getPosition()
529         {
530             return this.position;
531         }
532 
533         /** {@inheritDoc} */
534         @Override
535         public String toString()
536         {
537             return "Placement [speed=" + this.speed + ", position=" + this.position + "]";
538         }
539 
540     }
541 
542     /** {@inheritDoc} */
543     @Override
544     public DirectedPoint getLocation() throws RemoteException
545     {
546         return this.generatorPositions.getLocation();
547     }
548 
549     /** {@inheritDoc} */
550     @Override
551     public Bounds getBounds() throws RemoteException
552     {
553         return this.generatorPositions.getBounds();
554     }
555 
556     /**
557      * Returns the number of vehicles in queue per included position for animation.
558      * @return number of vehicles in queue per included position for animation
559      */
560     public Map<DirectedPoint, Integer> getQueueLengths()
561     {
562         Map<DirectedPoint, Integer> result = new LinkedHashMap<>();
563         for (CrossSectionLink link : this.unplacedTemplates.keySet())
564         {
565             for (GeneratorLanePosition lanePosition : this.unplacedTemplates.get(link).keySet())
566             {
567                 result.put(lanePosition.getPosition().iterator().next().getLocation(),
568                         this.unplacedTemplates.get(link).get(lanePosition).size());
569             }
570         }
571         for (GeneratorLanePosition lanePosition : this.generatorPositions.getAllPositions())
572         {
573             DirectedPoint p = lanePosition.getPosition().iterator().next().getLocation();
574             if (!result.containsKey(p))
575             {
576                 result.put(p, 0);
577             }
578         }
579         return result;
580     }
581 
582 }