1   package org.opentrafficsim.draw.graphs;
2   
3   import static org.junit.Assert.assertEquals;
4   import static org.junit.Assert.assertNull;
5   import static org.junit.Assert.assertTrue;
6   import static org.junit.Assert.fail;
7   
8   import java.awt.event.ActionEvent;
9   import java.util.ArrayList;
10  import java.util.HashSet;
11  import java.util.LinkedHashSet;
12  import java.util.List;
13  import java.util.Set;
14  
15  import javax.naming.NamingException;
16  import javax.swing.JOptionPane;
17  
18  import org.djunits.unit.AccelerationUnit;
19  import org.djunits.unit.TimeUnit;
20  import org.djunits.unit.util.UNITS;
21  import org.djunits.value.vdouble.scalar.Acceleration;
22  import org.djunits.value.vdouble.scalar.Direction;
23  import org.djunits.value.vdouble.scalar.Duration;
24  import org.djunits.value.vdouble.scalar.Length;
25  import org.djunits.value.vdouble.scalar.Speed;
26  import org.djunits.value.vdouble.scalar.Time;
27  import org.djutils.immutablecollections.ImmutableArrayList;
28  import org.jfree.data.DomainOrder;
29  import org.junit.Test;
30  import org.mockito.ArgumentMatchers;
31  import org.mockito.Mockito;
32  import org.mockito.invocation.InvocationOnMock;
33  import org.mockito.stubbing.Answer;
34  import org.opentrafficsim.core.dsol.OTSSimulator;
35  import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
36  import org.opentrafficsim.core.geometry.OTSGeometryException;
37  import org.opentrafficsim.core.geometry.OTSPoint3D;
38  import org.opentrafficsim.core.gtu.GTUDirectionality;
39  import org.opentrafficsim.core.gtu.GTUException;
40  import org.opentrafficsim.core.gtu.GTUType;
41  import org.opentrafficsim.core.network.NetworkException;
42  import org.opentrafficsim.draw.graphs.GraphPath.Section;
43  import org.opentrafficsim.draw.graphs.road.GraphLaneUtil;
44  import org.opentrafficsim.kpi.interfaces.LaneDataInterface;
45  import org.opentrafficsim.kpi.sampling.KpiLaneDirection;
46  import org.opentrafficsim.road.gtu.lane.LaneBasedIndividualGTU;
47  import org.opentrafficsim.road.gtu.lane.tactical.LaneBasedCFLCTacticalPlanner;
48  import org.opentrafficsim.road.gtu.lane.tactical.following.FixedAccelerationModel;
49  import org.opentrafficsim.road.gtu.lane.tactical.following.GTUFollowingModelOld;
50  import org.opentrafficsim.road.gtu.lane.tactical.following.SequentialFixedAccelerationModel;
51  import org.opentrafficsim.road.gtu.lane.tactical.lanechangemobil.Egoistic;
52  import org.opentrafficsim.road.gtu.lane.tactical.lanechangemobil.LaneChangeModel;
53  import org.opentrafficsim.road.gtu.strategical.LaneBasedStrategicalPlanner;
54  import org.opentrafficsim.road.gtu.strategical.route.LaneBasedStrategicalRoutePlanner;
55  import org.opentrafficsim.road.network.OTSRoadNetwork;
56  import org.opentrafficsim.road.network.factory.LaneFactory;
57  import org.opentrafficsim.road.network.lane.DirectedLanePosition;
58  import org.opentrafficsim.road.network.lane.Lane;
59  import org.opentrafficsim.road.network.lane.LaneDirection;
60  import org.opentrafficsim.road.network.lane.LaneType;
61  import org.opentrafficsim.road.network.lane.OTSRoadNode;
62  import org.opentrafficsim.road.network.sampling.RoadSampler;
63  
64  import nl.tudelft.simulation.dsol.SimRuntimeException;
65  import nl.tudelft.simulation.dsol.formalisms.eventscheduling.SimEvent;
66  import nl.tudelft.simulation.dsol.formalisms.eventscheduling.SimEventInterface;
67  import nl.tudelft.simulation.dsol.simtime.SimTimeDoubleUnit;
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  public class ContourPlotTest implements UNITS
80  {
81  
82      
83      @SuppressWarnings("unchecked")
84      GraphPath<KpiLaneDirection> mockedPath = Mockito.mock(GraphPath.class);
85  
86      Section<KpiLaneDirection> section0 = Mockito.mock(Section.class);
87  
88      Section<KpiLaneDirection> section1 = Mockito.mock(Section.class);
89  
90      KpiLaneDirection direction0 = Mockito.mock(KpiLaneDirection.class);
91  
92      KpiLaneDirection direction1 = Mockito.mock(KpiLaneDirection.class);
93  
94      LaneDataInterface mockedLane0 = Mockito.mock(LaneDataInterface.class);
95  
96      LaneDataInterface mockedLane1 = Mockito.mock(LaneDataInterface.class);
97  
98      RoadSampler mockedRoadSampler = Mockito.mock(RoadSampler.class);
99  
100     OTSSimulatorInterface mockedSimulator = Mockito.mock(OTSSimulatorInterface.class);
101 
102     SimEventInterface<SimTimeDoubleUnit> lastScheduledEvent = null;
103 
104     
105 
106 
107 
108 
109 
110 
111     private GraphPath<KpiLaneDirection> dummyPath(final OTSSimulatorInterface simulator, final OTSRoadNetwork network)
112             throws Exception
113     {
114         LaneType laneType = network.getLaneType(LaneType.DEFAULTS.TWO_WAY_LANE);
115         OTSRoadNode b = new OTSRoadNode(network, "B", new OTSPoint3D(12345, 0, 0), Direction.ZERO);
116         ArrayList<Lane> result = new ArrayList<Lane>();
117         Lane[] lanes = LaneFactory.makeMultiLane(network, "AtoB",
118                 new OTSRoadNode(network, "A", new OTSPoint3D(1234, 0, 0), Direction.ZERO), b, null, 1, laneType,
119                 new Speed(100, KM_PER_HOUR), simulator);
120         result.add(lanes[0]);
121         
122         lanes = LaneFactory.makeMultiLane(network, "BtoC", b,
123                 new OTSRoadNode(network, "C", new OTSPoint3D(99999, 0, 0), Direction.ZERO), null, 1, laneType,
124                 new Speed(100, KM_PER_HOUR), null);
125         return GraphLaneUtil.createPath("AtoB", new LaneDirection(lanes[0], GTUDirectionality.DIR_PLUS));
126     }
127 
128     
129 
130 
131 
132     public final void setUp() throws SimRuntimeException
133     {
134         Mockito.when(this.mockedPath.getTotalLength()).thenReturn(Length.valueOf("2000m"));
135         Mockito.when(this.mockedPath.getNumberOfSeries()).thenReturn(2);
136         Mockito.when(this.mockedPath.get(0)).thenReturn(this.section0);
137         Mockito.when(this.mockedPath.get(1)).thenReturn(this.section1);
138         Mockito.when(this.mockedPath.getStartDistance(this.section0)).thenReturn(Length.ZERO);
139         Mockito.when(this.mockedPath.getStartDistance(this.section1)).thenReturn(Length.valueOf("1234m"));
140         Mockito.when(this.mockedPath.getSpeedLimit()).thenReturn(Speed.valueOf("100 km/h"));
141         List<Section<KpiLaneDirection>> sectionList = new ArrayList<>();
142         sectionList.add(this.section0);
143         sectionList.add(this.section1);
144         Mockito.when(this.mockedLane0.getLength()).thenReturn(Length.valueOf("1234m"));
145         Mockito.when(this.mockedLane1.getLength()).thenReturn(Length.valueOf("766m"));
146         Mockito.when(this.direction0.getLaneData()).thenReturn(this.mockedLane0);
147         Mockito.when(this.direction1.getLaneData()).thenReturn(this.mockedLane1);
148         Set<KpiLaneDirection> set0 = new HashSet<>();
149         set0.add(this.direction0);
150         Mockito.when(this.section0.iterator()).thenReturn(set0.iterator());
151         Set<KpiLaneDirection> set1 = new HashSet<>();
152         set1.add(this.direction1);
153         Mockito.when(this.section0.iterator()).thenReturn(set0.iterator());
154         Mockito.when(this.section1.iterator()).thenReturn(set1.iterator());
155         Mockito.when(this.mockedPath.getSections()).thenReturn(new ImmutableArrayList<>(sectionList));
156         Mockito.when(this.section0.getLength()).thenReturn(Length.valueOf("1234m"));
157         Mockito.when(this.section1.getLength()).thenReturn(Length.valueOf("766m"));
158         Mockito.when(this.mockedSimulator.scheduleEventAbs(ArgumentMatchers.any(Time.class), ArgumentMatchers.any(),
159                 ArgumentMatchers.any(), ArgumentMatchers.anyString(), ArgumentMatchers.isNull()))
160                 .thenAnswer(new Answer<SimEventInterface<SimTimeDoubleUnit>>()
161                 {
162                     @Override
163                     public SimEventInterface<SimTimeDoubleUnit> answer(final InvocationOnMock invocation) throws Throwable
164                     {
165                         ContourPlotTest.this.lastScheduledEvent = new SimEvent.TimeDoubleUnit(invocation.getArgument(0),
166                                 invocation.getArgument(1), invocation.getArgument(2), "update", null);
167                         return ContourPlotTest.this.lastScheduledEvent;
168                     }
169                 });
170         Mockito.when(this.mockedSimulator.getSimulatorTime()).thenReturn(Time.ZERO);
171     }
172 
173     
174 
175 
176 
177     @Test
178     public final void accelerationContourTest() throws Exception
179     {
180         setUp();
181         ContourDataSource<?> dataPool = new ContourDataSource<>(this.mockedRoadSampler, this.mockedPath);
182         ContourPlotAcceleration acp = new ContourPlotAcceleration("acceleration", this.mockedSimulator, dataPool);
183         assertTrue("newly created AccelerationContourPlot should not be null", null != acp);
184         assertEquals("SeriesKey should be \"acceleration\"", "acceleration", acp.getSeriesKey(0));
185         standardContourTests(this.mockedSimulator, acp, this.mockedPath, Double.NaN, 0);
186     }
187 
188     
189 
190 
191 
192     @Test
193     public final void densityContourTest() throws Exception
194     {
195         OTSRoadNetwork network = new OTSRoadNetwork("density contour test network", true);
196         OTSSimulatorInterface simulator = new OTSSimulator();
197         GraphPath<KpiLaneDirection> path = dummyPath(simulator, network);
198         RoadSampler sampler = new RoadSampler(simulator);
199         ContourDataSource<?> dataPool = new ContourDataSource<>(sampler, path);
200         ContourPlotDensity dcp = new ContourPlotDensity("Density", simulator, dataPool);
201         assertTrue("newly created DensityContourPlot should not be null", null != dcp);
202         assertEquals("SeriesKey should be \"density\"", "density", dcp.getSeriesKey(0));
203         GTUType gtuType = network.getGtuType(GTUType.DEFAULTS.CAR);
204         standardContourTests(simulator, dcp, path, 0, Double.NaN);
205     }
206 
207     
208 
209 
210 
211     @Test
212     public final void flowContourTest() throws Exception
213     {
214         OTSRoadNetwork network = new OTSRoadNetwork("flow contour test network", true);
215         OTSSimulatorInterface simulator = new OTSSimulator();
216         GraphPath<KpiLaneDirection> path = dummyPath(simulator, network);
217         RoadSampler sampler = new RoadSampler(simulator);
218         ContourDataSource<?> dataPool = new ContourDataSource<>(sampler, path);
219         ContourPlotFlow fcp = new ContourPlotFlow("Density", simulator, dataPool);
220         assertTrue("newly created DensityContourPlot should not be null", null != fcp);
221         assertEquals("SeriesKey should be \"flow\"", "flow", fcp.getSeriesKey(0));
222         GTUType gtuType = network.getGtuType(GTUType.DEFAULTS.CAR);
223         standardContourTests(simulator, fcp, path, 0, Double.NaN);
224     }
225 
226     
227 
228 
229 
230     @Test
231     public final void speedContourTest() throws Exception
232     {
233         OTSRoadNetwork network = new OTSRoadNetwork("flow contour test network", true);
234         OTSSimulatorInterface simulator = new OTSSimulator();
235         GraphPath<KpiLaneDirection> path = dummyPath(simulator, network);
236         RoadSampler sampler = new RoadSampler(simulator);
237         ContourDataSource<?> dataPool = new ContourDataSource<>(sampler, path);
238         ContourPlotSpeed scp = new ContourPlotSpeed("Density", simulator, dataPool);
239         assertTrue("newly created DensityContourPlot should not be null", null != scp);
240         assertEquals("SeriesKey should be \"speed\"", "speed", scp.getSeriesKey(0));
241         GTUType gtuType = network.getGtuType(GTUType.DEFAULTS.CAR);
242         standardContourTests(simulator, scp, path, Double.NaN, 50);
243     }
244 
245     
246 
247 
248 
249 
250 
251 
252 
253     static void printMatrix(final AbstractContourPlot<?> cp, final int fromX, final int toX, final int fromY, final int toY)
254     {
255         System.out.println("Contour plot data:");
256         int maxItem = cp.getItemCount(0);
257         for (int y = fromY; y <= toY; y++)
258         {
259             System.out.print(String.format("y=%3d ", y));
260             for (int x = fromX; x <= toX; x++)
261             {
262                 
263                 int item;
264                 for (item = 0; item < maxItem; item++)
265                 {
266                     if (cp.getXValue(0, item) == x && cp.getYValue(0, item) == y)
267                     {
268                         break;
269                     }
270                 }
271                 if (item < maxItem)
272                 {
273                     System.out.print(String.format("%10.6f", cp.getZValue(0, item)));
274                 }
275                 else
276                 {
277                     System.out.print(" -------- ");
278                 }
279             }
280             System.out.println("");
281         }
282         System.out.print("");
283     }
284 
285     
286 
287 
288 
289 
290 
291 
292 
293 
294 
295 
296     public static void standardContourTests(final OTSSimulatorInterface simulator, final AbstractContourPlot<?> cp,
297             final GraphPath<?> path, final double expectedZValue, final double expectedZValueWithTraffic) throws Exception
298     {
299         assertEquals("seriesCount should be 1", 1, cp.getSeriesCount());
300         assertEquals("domainOrder should be ASCENDING", DomainOrder.ASCENDING, cp.getDomainOrder());
301         assertEquals("indexOf always returns 0", 0, cp.indexOf(0));
302         assertEquals("indexOf always returns 0", 0, cp.indexOf("abc"));
303         assertNull("getGroup always returns null", cp.getGroup());
304         int xBins = cp.getDataPool().timeAxis.getBinCount();
305         int yBins = cp.getDataPool().spaceAxis.getBinCount();
306         int expectedXBins = (int) Math.ceil(((AbstractPlot.DEFAULT_INITIAL_UPPER_TIME_BOUND).getSI())
307                 / ContourDataSource.DEFAULT_TIME_GRANULARITIES[ContourDataSource.DEFAULT_TIME_GRANULARITY_INDEX] 
308                         + (cp.getDataPool().timeAxis.isInterpolate() ? 1 : 0));
309         assertEquals("Initial xBins should be " + expectedXBins, expectedXBins, xBins);
310         int expectedYBins = (int) Math.ceil(path.getTotalLength().getSI()
311                 / ContourDataSource.DEFAULT_SPACE_GRANULARITIES[ContourDataSource.DEFAULT_SPACE_GRANULARITY_INDEX]
312                         + (cp.getDataPool().timeAxis.isInterpolate() ? 1 : 0));
313         assertEquals("yBins should be " + expectedYBins, expectedYBins, yBins);
314         int bins = cp.getItemCount(0);
315         assertEquals("Total bin count is product of xBins * yBins", xBins * yBins, bins);
316         String initialUpperTimeBoundString = AbstractPlot.DEFAULT_INITIAL_UPPER_TIME_BOUND.toString();
317         
318         for (double timeGranularity : ContourDataSource.DEFAULT_TIME_GRANULARITIES)
319         {
320             cp.actionPerformed(new ActionEvent(timeGranularity, 0, "setTimeGranularity"));
321             for (double distanceGranularity : ContourDataSource.DEFAULT_SPACE_GRANULARITIES)
322             {
323                 cp.actionPerformed(new ActionEvent(distanceGranularity, 0, "setSpaceGranularity"));
324                 cp.notifyPlotChange();
325                 expectedXBins = (int) Math.ceil((AbstractPlot.DEFAULT_INITIAL_UPPER_TIME_BOUND.getSI()) / timeGranularity);
326                 xBins = cp.getDataPool().timeAxis.getBinCount();
327                 assertEquals("Modified xBins should be " + expectedXBins, expectedXBins, xBins);
328                 expectedYBins = (int) Math.ceil(path.get(0).getLength().getSI() / distanceGranularity);
329                 yBins = cp.getDataPool().spaceAxis.getBinCount();
330                 assertEquals("Modified yBins should be " + expectedYBins, expectedYBins, yBins);
331                 bins = cp.getItemCount(0);
332                 assertEquals("Total bin count is product of xBins * yBins", xBins * yBins, bins);
333                 for (int item = 0; item < bins; item++)
334                 {
335                     double x = cp.getXValue(0, item);
336                     assertTrue("X should be >= 0", x >= 0);
337                     assertTrue("X should be <= " + initialUpperTimeBoundString,
338                             x <= AbstractPlot.DEFAULT_INITIAL_UPPER_TIME_BOUND.getSI());
339                     Number alternateX = cp.getX(0, item);
340                     assertEquals("getXValue and getX should return things that have the same value", x,
341                             alternateX.doubleValue(), 0.000001);
342                     double y = cp.getYValue(0, item);
343                     Number alternateY = cp.getY(0, item);
344                     assertEquals("getYValue and getY should return things that have the same value", y,
345                             alternateY.doubleValue(), 0.000001);
346                     double z = cp.getZValue(0, item);
347                     if (Double.isNaN(expectedZValue))
348                     {
349                         assertTrue("Z value should be NaN", Double.isNaN(z));
350                     }
351                     else
352                     {
353                         assertEquals("Z value should be " + expectedZValue, expectedZValue, z, 0.0001);
354                     }
355                     Number alternateZ = cp.getZ(0, item);
356                     if (Double.isNaN(expectedZValue))
357                     {
358                         assertTrue("Alternate Z value should be NaN", Double.isNaN(alternateZ.doubleValue()));
359                     }
360                     else
361                     {
362                         assertEquals("Alternate Z value should be " + expectedZValue, expectedZValue, alternateZ.doubleValue(),
363                                 0.0000);
364                     }
365                 }
366                 try
367                 {
368                     cp.getXValue(0, -1);
369                     fail("Should have thrown an Exception");
370                 }
371                 catch (RuntimeException e)
372                 {
373                     
374                 }
375                 try
376                 {
377                     cp.getXValue(0, bins);
378                     fail("Should have thrown an Exception");
379                 }
380                 catch (RuntimeException e)
381                 {
382                     
383                 }
384                 
385                 
386                 
387                 
388                 
389                 
390                 
391                 
392                 
393                 
394                 
395                 
396                 
397                 
398                 
399                 
400                 
401                 
402             }
403         }
404         
405         try
406         {
407             cp.actionPerformed(new ActionEvent(cp, 0, "blabla"));
408             fail("Should have thrown an Exception");
409         }
410         catch (RuntimeException e)
411         {
412             
413         }
414         try
415         {
416             cp.actionPerformed(new ActionEvent(cp, 0, "setDistanceGranularity -1"));
417             fail("Should have thrown an Exception");
418         }
419         catch (RuntimeException e)
420         {
421             
422         }
423         try
424         {
425             cp.actionPerformed(new ActionEvent(cp, 0, "setDistanceGranularity abc"));
426             fail("Should have thrown an Exception");
427         }
428         catch (RuntimeException e)
429         {
430             
431         }
432         try
433         {
434             cp.actionPerformed(new ActionEvent(cp, 0, "setDistanceGranularitIE 10")); 
435             fail("Should have thrown an Exception");
436         }
437         catch (RuntimeException e)
438         {
439             
440         }
441         
442         final double useTimeGranularity = 30; 
443         cp.actionPerformed(new ActionEvent(useTimeGranularity, 0, "setTimeGranularity"));
444         final double useDistanceGranularity =
445                 ContourDataSource.DEFAULT_SPACE_GRANULARITIES[ContourDataSource.DEFAULT_SPACE_GRANULARITIES.length - 1];
446         cp.actionPerformed(new ActionEvent(useDistanceGranularity, 0, "setDistanceGranularity"));
447         cp.notifyPlotChange();
448         bins = cp.getItemCount(0);
449         Time initialTime = new Time(0, TimeUnit.BASE_SECOND);
450         Length initialPosition = new Length(100, METER);
451         Speed initialSpeed = new Speed(50, KM_PER_HOUR);
452         
453         SequentialFixedAccelerationModel gtuFollowingModel =
454                 new SequentialFixedAccelerationModel(simulator, new Acceleration(2.0, AccelerationUnit.METER_PER_SECOND_2));
455         
456         gtuFollowingModel
457                 .addStep(new FixedAccelerationModel(new Acceleration(0, METER_PER_SECOND_2), new Duration(60, SECOND)));
458         
459         gtuFollowingModel
460                 .addStep(new FixedAccelerationModel(new Acceleration(0, METER_PER_SECOND_2), new Duration(600, SECOND)));
461         
462         gtuFollowingModel
463                 .addStep(new FixedAccelerationModel(new Acceleration(0, METER_PER_SECOND_2), new Duration(300, SECOND)));
464         LaneChangeModel laneChangeModel = new Egoistic();
465 
466         
467         for (int item = 0; item < bins; item++)
468         {
469             double x = cp.getXValue(0, item);
470             assertTrue("X should be >= 0", x >= 0);
471             assertTrue("X should be <= " + initialUpperTimeBoundString, x <= AbstractPlot.DEFAULT_INITIAL_UPPER_TIME_BOUND.si);
472             Number alternateX = cp.getX(0, item);
473             assertEquals("getXValue and getX should return things that have the same value", x, alternateX.doubleValue(),
474                     0.000001);
475             double y = cp.getYValue(0, item);
476             Number alternateY = cp.getY(0, item);
477             assertEquals("getYValue and getY should return things that have the same value", y, alternateY.doubleValue(),
478                     0.000001);
479             double z = cp.getZValue(0, item);
480             if (Double.isNaN(expectedZValue))
481             {
482                 assertTrue("Z value should be NaN (got " + z + ")", Double.isNaN(z));
483             }
484             else
485             {
486                 assertEquals("Z value should be " + expectedZValue, expectedZValue, z, 0.0001);
487             }
488             Number alternateZ = cp.getZ(0, item);
489             if (Double.isNaN(expectedZValue))
490             {
491                 assertTrue("Alternate Z value should be NaN", Double.isNaN(alternateZ.doubleValue()));
492             }
493             else
494             {
495                 assertEquals("Alternate Z value should be " + expectedZValue, expectedZValue, alternateZ.doubleValue(), 0.0000);
496             }
497         }
498 
499         
500         
501         
502         
503         
504         
505         
506         
507         
508         
509         
510         
511         
512         
513         
514         
515         
516         
517         
518         
519         
520         
521         
522         
523         
524         
525         
526         
527         
528         
529         
530         
531         
532         
533         
534         
535         
536         
537         
538         
539         
540         
541         
542         
543         
544         
545         
546         
547         
548         
549         
550         
551         
552         
553         
554         
555         
556         
557         
558         
559         
560         
561         
562         
563         
564         
565         
566         
567         
568         
569         
570         
571         
572         
573         
574         
575         
576         
577         
578         
579         
580         
581         
582         
583         
584         
585         
586         
587         
588         
589         
590         
591         
592         
593         
594         
595         
596         
597         
598         
599         
600         
601         
602         
603         
604         
605         
606         
607         
608         
609         
610         
611         
612         
613         
614         
615         
616         
617         
618         
619         
620         
621         
622         
623         
624         
625         
626         
627         
628         
629         
630         
631         
632         
633         
634         
635         
636         
637         
638         
639         
640         
641         
642         
643         
644         
645         
646         
647         
648         
649         
650         
651         
652         
653         
654         
655         
656         
657         
658         
659         
660         
661         
662         
663         
664         
665         
666         
667         
668         
669         
670         
671         
672         
673         
674         
675         
676         
677         
678         
679         
680         
681         
682         
683         
684         
685         
686         
687         
688         
689         
690         
691         
692         
693         
694         
695         
696         
697         
698         
699         
700         
701         
702         
703         
704         
705         
706         
707         
708         
709         
710         
711         
712         
713         
714         
715         
716         
717         
718         
719         
720         
721         
722         
723         
724         
725         
726         
727         
728         
729         
730         
731         
732         
733         
734         
735         
736         
737     }
738 
739     
740 
741 
742 
743 
744 
745 
746 
747 
748 
749 
750 
751 
752 
753 
754 
755 
756 
757 
758     private static LaneBasedIndividualGTU makeReferenceCar(final String id, final GTUType gtuType, final Lane lane,
759             final Length initialPosition, final Speed initialSpeed, final OTSSimulatorInterface simulator,
760             final GTUFollowingModelOld gtuFollowingModel, final LaneChangeModel laneChangeModel, final OTSRoadNetwork network)
761             throws NamingException, NetworkException, SimRuntimeException, GTUException, OTSGeometryException
762     {
763         Length length = new Length(5.0, METER);
764         Length width = new Length(2.0, METER);
765         Set<DirectedLanePosition> initialLongitudinalPositions = new LinkedHashSet<>(1);
766         initialLongitudinalPositions.add(new DirectedLanePosition(lane, initialPosition, GTUDirectionality.DIR_PLUS));
767         Speed maxSpeed = new Speed(120, KM_PER_HOUR);
768         LaneBasedIndividualGTU gtu =
769                 new LaneBasedIndividualGTU(id, gtuType, length, width, maxSpeed, length.times(0.5), simulator, network);
770         LaneBasedStrategicalPlanner strategicalPlanner = new LaneBasedStrategicalRoutePlanner(
771                 new LaneBasedCFLCTacticalPlanner(gtuFollowingModel, laneChangeModel, gtu), gtu);
772         gtu.init(strategicalPlanner, initialLongitudinalPositions, initialSpeed);
773 
774         return gtu;
775     }
776 
777     
778 
779 
780 
781 
782     public static void main(final String[] args) throws Exception
783     {
784         ContourPlotTesttourPlotTest.html#ContourPlotTest">ContourPlotTest cpt = new ContourPlotTest();
785         System.out.println("Click the OK button");
786         JOptionPane.showMessageDialog(null, "ContourPlot", "Start experiment", JOptionPane.INFORMATION_MESSAGE);
787         System.out.println("Running ...");
788         cpt.densityContourTest();
789         System.out.println("Finished");
790     }
791 
792 }