1 package org.opentrafficsim.road.network.lane;
2
3 import java.util.HashSet;
4 import java.util.Set;
5
6 import javax.naming.NamingException;
7
8 import nl.tudelft.simulation.dsol.SimRuntimeException;
9 import nl.tudelft.simulation.dsol.formalisms.eventscheduling.SimEventInterface;
10
11 import org.djunits.unit.AccelerationUnit;
12 import org.djunits.unit.LengthUnit;
13 import org.djunits.unit.SpeedUnit;
14 import org.djunits.unit.TimeUnit;
15 import org.djunits.value.vdouble.scalar.Acceleration;
16 import org.djunits.value.vdouble.scalar.Duration;
17 import org.djunits.value.vdouble.scalar.Length;
18 import org.djunits.value.vdouble.scalar.Speed;
19 import org.junit.Test;
20 import org.opentrafficsim.core.dsol.OTSDEVSSimulator;
21 import org.opentrafficsim.core.dsol.OTSDEVSSimulatorInterface;
22 import org.opentrafficsim.core.dsol.OTSSimTimeDouble;
23 import org.opentrafficsim.core.geometry.OTSGeometryException;
24 import org.opentrafficsim.core.geometry.OTSLine3D;
25 import org.opentrafficsim.core.geometry.OTSPoint3D;
26 import org.opentrafficsim.core.gtu.GTUException;
27 import org.opentrafficsim.core.gtu.GTUType;
28 import org.opentrafficsim.core.network.LongitudinalDirectionality;
29 import org.opentrafficsim.core.network.Network;
30 import org.opentrafficsim.core.network.NetworkException;
31 import org.opentrafficsim.core.network.OTSNetwork;
32 import org.opentrafficsim.core.network.OTSNode;
33 import org.opentrafficsim.road.car.CarTest;
34 import org.opentrafficsim.road.gtu.lane.LaneBasedIndividualGTU;
35 import org.opentrafficsim.road.gtu.lane.tactical.following.FixedAccelerationModel;
36 import org.opentrafficsim.road.gtu.lane.tactical.lanechangemobil.FixedLaneChangeModel;
37 import org.opentrafficsim.road.network.factory.LaneFactory;
38
39
40
41
42
43
44
45
46
47
48
49
50 public class CurveTest
51 {
52
53
54
55
56
57
58
59
60
61 @Test
62 public void curveTest() throws OTSGeometryException, SimRuntimeException, NamingException, NetworkException, GTUException
63 {
64 final int laneCount = 1;
65 GTUType gtuType = new GTUType("Car");
66 Set<GTUType> compatibility = new HashSet<GTUType>();
67 compatibility.add(gtuType);
68 LaneType laneType = new LaneType("CarLane", compatibility);
69 Speed speedLimit = new Speed(50, SpeedUnit.KM_PER_HOUR);
70 OTSDEVSSimulatorInterface simulator = CarTest.makeSimulator();
71 Network network = new OTSNetwork("curve test network");
72 OTSNode origin = new OTSNode(network, "origin", new OTSPoint3D(10, 10, 0));
73 OTSNode curveStart = new OTSNode(network, "curveStart", new OTSPoint3D(100, 10, 0));
74 OTSNode curveEnd = new OTSNode(network, "curveEnd", new OTSPoint3D(150, 60, 0));
75 OTSNode destination = new OTSNode(network, "destination", new OTSPoint3D(150, 150, 0));
76 Lane[] straight1 =
77 LaneFactory.makeMultiLane(network, "straight1", origin, curveStart, null, laneCount, laneType, speedLimit,
78 simulator, LongitudinalDirectionality.DIR_PLUS);
79 Lane[] straight2 =
80 LaneFactory.makeMultiLane(network, "straight2", curveEnd, destination, null, laneCount, laneType, speedLimit,
81 simulator, LongitudinalDirectionality.DIR_PLUS);
82 OTSLine3D curveLine = LaneFactory.makeBezier(origin, curveStart, curveEnd, destination);
83 Lane[] curve =
84 LaneFactory.makeMultiLane(network, "bezier", curveStart, curveEnd, curveLine.getPoints(), laneCount,
85 laneType, speedLimit, simulator, LongitudinalDirectionality.DIR_PLUS);
86 Lane[][] laneSets = new Lane[][] { straight1, curve, straight2 };
87 Length initialPosition = new Length(5, LengthUnit.METER);
88 Speed speed = new Speed(10, SpeedUnit.SI);
89 for (int lane = 0; lane < laneCount; lane++)
90 {
91
92 double cumulativeLength = 0;
93 for (Lane[] set : laneSets)
94 {
95 cumulativeLength += set[lane].getLength().si;
96 double timeAtEnd = simulator.getSimulatorTime().get().si + (cumulativeLength - initialPosition.si) / speed.si;
97 System.out.println("lane " + set[lane] + " length is " + set[lane].getLength()
98 + " time for reference to get to end " + timeAtEnd);
99 }
100 LaneBasedIndividualGTU car =
101 CarTest.makeReferenceCar("car", gtuType, straight1[lane], initialPosition, speed,
102 (OTSDEVSSimulator) simulator, new FixedAccelerationModel(new Acceleration(0, AccelerationUnit.SI),
103 new Duration(25, TimeUnit.SI)), new FixedLaneChangeModel(null), (OTSNetwork) network);
104 printEventList(simulator);
105 System.out.println("STEP");
106 simulator.step();
107 printEventList(simulator);
108 System.out.println("STEP");
109 simulator.step();
110 printEventList(simulator);
111
112 }
113 }
114
115
116
117
118
119 public void printEventList(final OTSDEVSSimulatorInterface simulator)
120 {
121 for (SimEventInterface<OTSSimTimeDouble> se : simulator.getEventList())
122 {
123 System.out.println("se: " + se);
124 }
125
126 }
127
128 }