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.DurationUnit;
12 import org.djunits.unit.LengthUnit;
13 import org.djunits.unit.SpeedUnit;
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 = LaneFactory.makeMultiLane(network, "straight1", origin, curveStart, null, laneCount, laneType,
79 speedLimit, simulator, LongitudinalDirectionality.DIR_PLUS);
80 Lane[] straight2 = LaneFactory.makeMultiLane(network, "straight2", curveEnd, destination, null, laneCount, laneType,
81 speedLimit, simulator, LongitudinalDirectionality.DIR_PLUS);
82 OTSLine3D curveLine = LaneFactory.makeBezier(origin, curveStart, curveEnd, destination);
83 Lane[] curve = LaneFactory.makeMultiLane(network, "bezier", curveStart, curveEnd, curveLine.getPoints(), laneCount,
84 laneType, speedLimit, simulator, LongitudinalDirectionality.DIR_PLUS);
85 Lane[][] laneSets = new Lane[][] { straight1, curve, straight2 };
86 Length initialPosition = new Length(5, LengthUnit.METER);
87 Speed speed = new Speed(10, SpeedUnit.SI);
88 for (int lane = 0; lane < laneCount; lane++)
89 {
90
91 double cumulativeLength = 0;
92 for (Lane[] set : laneSets)
93 {
94 cumulativeLength += set[lane].getLength().si;
95 double timeAtEnd = simulator.getSimulatorTime().get().si + (cumulativeLength - initialPosition.si) / speed.si;
96 System.out.println("lane " + set[lane] + " length is " + set[lane].getLength()
97 + " time for reference to get to end " + timeAtEnd);
98 }
99 LaneBasedIndividualGTU car = CarTest.makeReferenceCar("car", gtuType, straight1[lane], initialPosition, speed,
100 (OTSDEVSSimulator) simulator,
101 new FixedAccelerationModel(new Acceleration(0, AccelerationUnit.SI), new Duration(25, DurationUnit.SI)),
102 new FixedLaneChangeModel(null), (OTSNetwork) network);
103 printEventList(simulator);
104 System.out.println("STEP");
105 simulator.step();
106 printEventList(simulator);
107 System.out.println("STEP");
108 simulator.step();
109 printEventList(simulator);
110
111 }
112 }
113
114
115
116
117
118 public void printEventList(final OTSDEVSSimulatorInterface simulator)
119 {
120 for (SimEventInterface<OTSSimTimeDouble> se : simulator.getEventList())
121 {
122 System.out.println("se: " + se);
123 }
124
125 }
126
127 }