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