1 package org.opentrafficsim.demo.carFollowing;
2
3 import org.djunits.unit.LengthUnit;
4 import org.djunits.value.vdouble.scalar.Length;
5 import org.djunits.value.vdouble.scalar.Speed;
6 import org.opentrafficsim.core.network.NetworkException;
7 import org.opentrafficsim.road.gtu.generator.LaneBasedGTUGenerator;
8 import org.opentrafficsim.road.gtu.lane.LaneBasedGTUCharacteristics;
9 import org.opentrafficsim.road.gtu.lane.tactical.following.GTUFollowingModelOld;
10 import org.opentrafficsim.road.gtu.lane.tactical.following.IDMOld;
11 import org.opentrafficsim.road.network.lane.DirectedLanePosition;
12 import org.opentrafficsim.road.network.lane.Lane;
13
14
15
16
17
18
19
20
21
22
23 public class CanPlaceDemoCode implements LaneBasedGTUGenerator.RoomChecker
24 {
25
26 private static Length maxDistance = new Length(Double.MAX_VALUE, LengthUnit.SI);
27
28
29 private static Length precision = new Length(0.1, LengthUnit.METER);
30
31
32 @Override
33 public Speed canPlace(Speed leaderSpeed, org.djunits.value.vdouble.scalar.Length headway,
34 LaneBasedGTUCharacteristics laneBasedGTUCharacteristics) throws NetworkException
35 {
36
37
38 Lane lane = null;
39 for (DirectedLanePosition dlp : laneBasedGTUCharacteristics.getInitialLongitudinalPositions())
40 {
41 if (dlp.getLane().getLaneType().isCompatible(laneBasedGTUCharacteristics.getGTUType()))
42 {
43 lane = dlp.getLane();
44 break;
45 }
46 }
47 if (null == lane)
48 {
49 throw new NetworkException(
50 "No " + laneBasedGTUCharacteristics.getGTUType() + "-compatible lane in initial longitudinal positions");
51 }
52
53 Speed speedLimit = lane.getSpeedLimit(laneBasedGTUCharacteristics.getGTUType());
54 Speed maximumSpeed = laneBasedGTUCharacteristics.getMaximumSpeed();
55 GTUFollowingModelOld gfm = new IDMOld();
56 if (headway.lt(
57 gfm.minimumHeadway(leaderSpeed, leaderSpeed, precision, maxDistance, speedLimit, maximumSpeed)))
58 {
59 return null;
60 }
61 return leaderSpeed;
62 }
63
64 }