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