View Javadoc
1   package org.opentrafficsim.demo.geometry;
2   
3   import java.awt.Color;
4   import java.io.Serializable;
5   import java.rmi.RemoteException;
6   
7   import javax.naming.NamingException;
8   
9   import org.djunits.unit.util.UNITS;
10  import org.djunits.value.vdouble.scalar.Direction;
11  import org.djunits.value.vdouble.scalar.Length;
12  import org.djunits.value.vdouble.scalar.Speed;
13  import org.opentrafficsim.core.dsol.AbstractOTSModel;
14  import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
15  import org.opentrafficsim.core.geometry.OTSGeometryException;
16  import org.opentrafficsim.core.geometry.OTSLine3D;
17  import org.opentrafficsim.core.geometry.OTSPoint3D;
18  import org.opentrafficsim.core.network.LinkType;
19  import org.opentrafficsim.core.network.NetworkException;
20  import org.opentrafficsim.draw.road.LaneAnimation;
21  import org.opentrafficsim.draw.road.ShoulderAnimation;
22  import org.opentrafficsim.road.network.OTSRoadNetwork;
23  import org.opentrafficsim.road.network.lane.CrossSectionLink;
24  import org.opentrafficsim.road.network.lane.Lane;
25  import org.opentrafficsim.road.network.lane.NoTrafficLane;
26  import org.opentrafficsim.road.network.lane.OTSRoadNode;
27  import org.opentrafficsim.road.network.lane.Shoulder;
28  import org.opentrafficsim.road.network.lane.changing.LaneKeepingPolicy;
29  
30  import nl.tudelft.simulation.dsol.SimRuntimeException;
31  
32  /**
33   * <p>
34   * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
35   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
36   * <p>
37   * $LastChangedDate: 2020-05-08 13:45:24 +0200 (Fri, 08 May 2020) $, @version $Revision: 6465 $, by $Author: pknoppers $,
38   * initial version ct 17, 2014 <br>
39   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
40   */
41  /** */
42  public class TestModel extends AbstractOTSModel implements UNITS
43  {
44      /**
45       * @param simulator OTSSimulatorInterface; the simulator
46       */
47      public TestModel(final OTSSimulatorInterface simulator)
48      {
49          super(simulator);
50      }
51  
52      /** */
53      private static final long serialVersionUID = 1L;
54  
55      /** the network. */
56      private OTSRoadNetwork network = new OTSRoadNetwork("geometry test network", true, getSimulator());
57  
58      /** {@inheritDoc} */
59      @Override
60      public final void constructModel() throws SimRuntimeException
61      {
62          // create a small graph and a road around it.
63  
64          try
65          {
66              OTSRoadNode n0 = new OTSRoadNode(this.network, "N0", new OTSPoint3D(-25.0, 0.0), Direction.ZERO);
67              OTSRoadNode n1 = new OTSRoadNode(this.network, "N1", new OTSPoint3D(0.0, 0.0), Direction.ZERO);
68              CrossSectionLink l01 =
69                      new CrossSectionLink(this.network, "L01", n0, n1, network.getLinkType(LinkType.DEFAULTS.ROAD),
70                              new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(-25.0, 0.0), new OTSPoint3D(0.0, 0.0)}),
71                              LaneKeepingPolicy.KEEPRIGHT);
72  
73              OTSRoadNode n2 = new OTSRoadNode(this.network, "N2", new OTSPoint3D(25.0, 20.0), Direction.ZERO);
74              CrossSectionLink l12 =
75                      new CrossSectionLink(this.network, "L12", n1, n2, network.getLinkType(LinkType.DEFAULTS.ROAD),
76                              new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(0.0, 0.0), new OTSPoint3D(25.0, 20.0)}),
77                              LaneKeepingPolicy.KEEPRIGHT);
78  
79              OTSRoadNode n3 = new OTSRoadNode(this.network, "N3", new OTSPoint3D(50.0, 0.0), Direction.ZERO);
80              CrossSectionLink l23 =
81                      new CrossSectionLink(this.network, "L23", n2, n3, network.getLinkType(LinkType.DEFAULTS.ROAD),
82                              new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(25.0, 20.0), new OTSPoint3D(50.0, 0.0)}),
83                              LaneKeepingPolicy.KEEPRIGHT);
84  
85              OTSRoadNode n4 = new OTSRoadNode(this.network, "N4", new OTSPoint3D(75.0, -20.0), Direction.ZERO);
86              CrossSectionLink l34 =
87                      new CrossSectionLink(this.network, "L34", n3, n4, network.getLinkType(LinkType.DEFAULTS.ROAD),
88                              new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(50.0, 0.0), new OTSPoint3D(75.0, -20.0)}),
89                              LaneKeepingPolicy.KEEPRIGHT);
90  
91              OTSRoadNode n5 = new OTSRoadNode(this.network, "N5", new OTSPoint3D(100.0, 0.0), Direction.ZERO);
92              CrossSectionLink l45 =
93                      new CrossSectionLink(this.network, "L45", n4, n5, network.getLinkType(LinkType.DEFAULTS.ROAD),
94                              new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(75.0, -20.0), new OTSPoint3D(100.0, 0.0)}),
95                              LaneKeepingPolicy.KEEPRIGHT);
96  
97              OTSRoadNode n6 = new OTSRoadNode(this.network, "N6", new OTSPoint3D(125.0, 0.0), Direction.ZERO);
98              CrossSectionLink l56 =
99                      new CrossSectionLink(this.network, "L56", n5, n6, network.getLinkType(LinkType.DEFAULTS.ROAD),
100                             new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(100.0, 0.0), new OTSPoint3D(125.0, 0.0)}),
101                             LaneKeepingPolicy.KEEPRIGHT);
102 
103             OTSRoadNode n7 = new OTSRoadNode(this.network, "N7", new OTSPoint3D(300.0, 0.0), Direction.ZERO);
104             CrossSectionLink l67 =
105                     new CrossSectionLink(this.network, "L67", n6, n7, network.getLinkType(LinkType.DEFAULTS.ROAD),
106                             new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(125.0, 0.0), new OTSPoint3D(150.0, 0.0),
107                                     new OTSPoint3D(175.0, 20.0), new OTSPoint3D(200.0, 0.0), new OTSPoint3D(225.0, -20.0),
108                                     new OTSPoint3D(250.0, 0.0), new OTSPoint3D(300.0, 0.0)}),
109                             LaneKeepingPolicy.KEEPRIGHT);
110 
111             add2x2Lanes(l01);
112             add2x2Lanes(l12);
113             add2x2Lanes(l23);
114             add2x2Lanes(l34);
115             add2x2Lanes(l45);
116             add2x2Lanes(l56);
117             add2x2Lanes(l67);
118         }
119         catch (NetworkException | OTSGeometryException exception)
120         {
121             exception.printStackTrace();
122         }
123     }
124 
125     /**
126      * The road is as follows; The design line goes from left to right.
127      * 
128      * <pre>
129      * ----------------------- +9.50
130      * SSSSS Shoulder SL SSSSS +9.00 (width = 1.0)
131      * ----------------------- +8.50
132      * EEEEE Emergency ELL EEE +8.25 (width = 0.5)
133      * ----------------------- +8.00
134      * LLLLL Lane L1 LLLLLLLLL +6.25 (width = 3.5)
135      * ----------------------- +4.50
136      * LLLLL Lane L2 LLLLLLLLL +2.75 (width = 3.5)
137      * ----------------------- +1.00
138      * EEEEE Emergency ELM EEE +0.75 (width = 0.5)
139      * ----------------------- +0.50
140      * SSSSS Shoulder SM SSSSS +0.00 (width = 1.0)
141      * ----------------------- -0.50
142      * EEEEE Emergency ERM EEE -0.75 (width = 0.5)
143      * ----------------------- -1.00
144      * LLLLL Lane R2 LLLLLLLLL -2.75 (width = 3.5)
145      * ----------------------- -4.50
146      * LLLLL Lane R1 LLLLLLLLL -6.25 (width = 3.5)
147      * ----------------------- -8.00
148      * EEEEE Emergency ERR EEE -8.25 (width = 0.5)
149      * ----------------------- -8.50
150      * SSSSS Shoulder SR SSSSS -9.00 (width = 1.0)
151      * ----------------------- -9.50
152      * </pre>
153      *
154      * <br>
155      * @param link CrossSectionLink; link.
156      * @throws NetworkException on network inconsistency
157      * @throws OTSGeometryException on network inconsistency
158      */
159     private void add2x2Lanes(final CrossSectionLink link) throws NetworkException, OTSGeometryException
160     {
161         // four lanes, grass underneath, lines between lane1-2 and lane 2-3, barrier between lane 2-3
162         // lane is 3.5 meters wide. gap between 3-4 is one meter. outside 0.5 meters on both sides
163         Length m05 = new Length(0.5, METER);
164         Length m10 = new Length(1.0, METER);
165         Length m35 = new Length(3.5, METER);
166         Speed speedLimit = new Speed(100, KM_PER_HOUR);
167 
168         Shoulder sL = new Shoulder(link, "sL", new Length(9.0, METER), m10);
169 
170         Lane laneELL = new NoTrafficLane(link, "ELL", new Length(8.25, METER), new Length(8.25, METER), m05, m05);
171         Lane laneL1 = new Lane(link, "L1", new Length(6.25, METER), new Length(6.25, METER), m35, m35, null, speedLimit);
172         Lane laneL2 = new Lane(link, "L2", new Length(2.75, METER), new Length(2.75, METER), m35, m35, null, speedLimit);
173         Lane laneELM = new NoTrafficLane(link, "ELM", new Length(0.75, METER), new Length(0.75, METER), m05, m05);
174 
175         Shoulder sM = new Shoulder(link, "sM", new Length(0.0, METER), m10);
176 
177         Lane laneERM = new NoTrafficLane(link, "ERM", new Length(-0.75, METER), new Length(-0.75, METER), m05, m05);
178         Lane laneR2 = new Lane(link, "R2", new Length(-2.75, METER), new Length(-2.75, METER), m35, m35, null, speedLimit);
179         Lane laneR1 = new Lane(link, "R1", new Length(-6.25, METER), new Length(-6.25, METER), m35, m35, null, speedLimit);
180         Lane laneERR = new NoTrafficLane(link, "ERR", new Length(-8.25, METER), new Length(-8.25, METER), m05, m05);
181 
182         Shoulder sR = new Shoulder(link, "sR", new Length(-9.0, METER), m10);
183 
184         try
185         {
186             new LaneAnimation(laneELL, this.simulator, Color.GRAY);
187             new LaneAnimation(laneL1, this.simulator, Color.GRAY);
188             new LaneAnimation(laneL2, this.simulator, Color.GRAY);
189             new LaneAnimation(laneELM, this.simulator, Color.GRAY);
190             new LaneAnimation(laneERM, this.simulator, Color.GRAY);
191             new LaneAnimation(laneR2, this.simulator, Color.GRAY);
192             new LaneAnimation(laneR1, this.simulator, Color.GRAY);
193             new LaneAnimation(laneERR, this.simulator, Color.GRAY);
194 
195             new ShoulderAnimation(sL, this.simulator, Color.GREEN);
196             new ShoulderAnimation(sM, this.simulator, Color.GREEN);
197             new ShoulderAnimation(sR, this.simulator, Color.GREEN);
198         }
199         catch (NamingException | RemoteException ne)
200         {
201             //
202         }
203     }
204 
205     /** {@inheritDoc} */
206     @Override
207     public final OTSRoadNetwork getNetwork()
208     {
209         return this.network;
210     }
211 
212     /** {@inheritDoc} */
213     @Override
214     public Serializable getSourceId()
215     {
216         return "TestModel";
217     }
218 
219 }