1 package org.opentrafficsim.road.network;
2
3 import java.util.LinkedHashMap;
4 import java.util.Map;
5
6 import org.djutils.exceptions.Throw;
7 import org.djutils.immutablecollections.Immutable;
8 import org.djutils.immutablecollections.ImmutableHashMap;
9 import org.djutils.immutablecollections.ImmutableMap;
10 import org.opentrafficsim.core.compatibility.GTUCompatibility;
11 import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
12 import org.opentrafficsim.core.gtu.GTUType;
13 import org.opentrafficsim.core.network.LongitudinalDirectionality;
14 import org.opentrafficsim.core.network.OTSNetwork;
15 import org.opentrafficsim.road.gtu.lane.tactical.routesystem.RouteSystem;
16 import org.opentrafficsim.road.network.lane.LaneType;
17
18
19
20
21
22
23
24
25
26 public class OTSRoadNetwork extends OTSNetwork implements RoadNetwork
27 {
28
29 private static final long serialVersionUID = 1L;
30
31
32 private Map<String, LaneType> laneTypeMap = new LinkedHashMap<>();
33
34
35 private RouteSystem routeSystem;
36
37
38
39
40
41
42
43 public OTSRoadNetwork(final String id, final boolean addDefaultTypes, final OTSSimulatorInterface simulator)
44 {
45 super(id, addDefaultTypes, simulator);
46 if (addDefaultTypes)
47 {
48 addDefaultLaneTypes();
49 }
50
51 this.routeSystem = null;
52 }
53
54
55 @Override
56 public void addDefaultLaneTypes()
57 {
58 GTUCompatibility<LaneType> noTrafficCompatibility = new GTUCompatibility<>((LaneType) null);
59 new LaneType("NONE", noTrafficCompatibility, this);
60 GTUCompatibility<LaneType> roadCompatibility = new GTUCompatibility<>((LaneType) null);
61 roadCompatibility.addAllowedGTUType(getGtuType(GTUType.DEFAULTS.ROAD_USER), LongitudinalDirectionality.DIR_BOTH);
62 LaneTypene/LaneType.html#LaneType">LaneType twoWayLane = new LaneType("TWO_WAY_LANE", roadCompatibility, this);
63 new LaneType("RURAL_ROAD", twoWayLane, new GTUCompatibility<>(roadCompatibility), this);
64 new LaneType("URBAN_ROAD", twoWayLane, new GTUCompatibility<>(roadCompatibility), this);
65 new LaneType("RESIDENTIAL_ROAD", twoWayLane, new GTUCompatibility<>(roadCompatibility), this);
66 GTUCompatibility<LaneType> oneWayLaneCompatibility = new GTUCompatibility<>(roadCompatibility);
67 oneWayLaneCompatibility.addAllowedGTUType(getGtuType(GTUType.DEFAULTS.ROAD_USER), LongitudinalDirectionality.DIR_PLUS);
68 oneWayLaneCompatibility.addAllowedGTUType(getGtuType(GTUType.DEFAULTS.PEDESTRIAN), LongitudinalDirectionality.DIR_BOTH);
69 new LaneType("ONE_WAY_LANE", oneWayLaneCompatibility, this);
70 GTUCompatibility<LaneType> highwayLaneCompatibility = new GTUCompatibility<>(oneWayLaneCompatibility)
71 .addAllowedGTUType(getGtuType(GTUType.DEFAULTS.PEDESTRIAN), LongitudinalDirectionality.DIR_NONE);
72 new LaneType("FREEWAY", highwayLaneCompatibility, this);
73 new LaneType("HIGHWAY", highwayLaneCompatibility, this);
74 GTUCompatibility<LaneType> busLaneCompatibility = new GTUCompatibility<>(roadCompatibility);
75 busLaneCompatibility.addAllowedGTUType(getGtuType(GTUType.DEFAULTS.BUS), LongitudinalDirectionality.DIR_BOTH);
76 busLaneCompatibility.addAllowedGTUType(getGtuType(GTUType.DEFAULTS.ROAD_USER), LongitudinalDirectionality.DIR_NONE);
77 new LaneType("BUS_LANE", busLaneCompatibility, this);
78 GTUCompatibility<LaneType> mopedAndBicycleLaneCompatibility = new GTUCompatibility<>(roadCompatibility);
79 mopedAndBicycleLaneCompatibility.addAllowedGTUType(getGtuType(GTUType.DEFAULTS.BICYCLE),
80 LongitudinalDirectionality.DIR_BOTH);
81 mopedAndBicycleLaneCompatibility.addAllowedGTUType(getGtuType(GTUType.DEFAULTS.ROAD_USER),
82 LongitudinalDirectionality.DIR_NONE);
83 new LaneType("MOPED_PATH", mopedAndBicycleLaneCompatibility, this);
84 GTUCompatibility<LaneType> bicycleOnlyCompatibility = new GTUCompatibility<>(mopedAndBicycleLaneCompatibility);
85 bicycleOnlyCompatibility.addAllowedGTUType(getGtuType(GTUType.DEFAULTS.MOPED), LongitudinalDirectionality.DIR_NONE);
86 new LaneType("BICYCLE_PATH", bicycleOnlyCompatibility, this);
87 GTUCompatibility<LaneType> pedestriansOnly = new GTUCompatibility<>(roadCompatibility);
88 pedestriansOnly.addAllowedGTUType(getGtuType(GTUType.DEFAULTS.ROAD_USER), LongitudinalDirectionality.DIR_NONE);
89 new LaneType("FOOTPATH", pedestriansOnly, this);
90 }
91
92
93 @Override
94 public void addLaneType(final LaneType laneType)
95 {
96 this.laneTypeMap.put(laneType.getId(), laneType);
97 }
98
99
100 @Override
101 public LaneType getLaneType(final String laneTypeId)
102 {
103 return this.laneTypeMap.get(laneTypeId);
104 }
105
106
107 @Override
108 public LaneType getLaneType(final LaneType.DEFAULTS laneTypeEnum)
109 {
110 return this.laneTypeMap.get(laneTypeEnum.getId());
111 }
112
113
114 @Override
115 public ImmutableMap<String, LaneType> getLaneTypes()
116 {
117 return new ImmutableHashMap<>(this.laneTypeMap, Immutable.WRAP);
118 }
119
120
121
122
123
124 public void setRouteSystem(final RouteSystem routeSystem)
125 {
126 Throw.whenNull(routeSystem, "Route system may not be null.");
127 this.routeSystem = routeSystem;
128 }
129
130
131
132
133
134 public RouteSystem getRouteSystem()
135 {
136 return this.routeSystem;
137 }
138
139 }