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