View Javadoc

1   /*
2    * Created on Aug 20, 2004
3    * 
4    * (c) copyright 2004 <a href="http://www.simulation.tudelft.nl">Delft
5    * University of Technology </a>, the Netherlands. <br> See for project
6    * information <a href="http://www.simulation.tudelft.nl">
7    * www.simulation.tudelft.nl </a> <br> License of use: <a
8    * href="http://www.gnu.org/copyleft/gpl.html">General Public License (GPL)
9    * </a>, no warranty <br>
10   * 
11   * @version May 31, 2004 <br> @author <a
12   * href="http://www.tbm.tudelft.nl/webstaf/elisangelak/index.htm">Elisangela
13   * Mieko Kanacilo * </a>
14   */
15  
16  package nl.tudelft.simulation.traffic.station;
17  
18  import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
19  import nl.tudelft.simulation.traffic.controlpoint.blocks.BlockTrafficLight;
20  import nl.tudelft.simulation.traffic.track.TrackInterface;
21  import nl.tudelft.simulation.traffic.vehicle.VehiclePhysicalInterface;
22  
23  /*
24   * Created on Sep 28, 2004
25   * 
26   * Copyright (c) 2003, 2004 Delft University of Technology Jaffalaan 5, 2628 BX
27   * Delft, the Netherlands All rights reserved.
28   * 
29   * This software is proprietary information of Delft University of Technology
30   * The code is published under the General Public License
31   */
32  /***
33   * <br>
34   * This class is the implementation of a stopping place. Each station is divided
35   * into stopping places and the number varies accordingly to its length
36   * 
37   * (c) copyright 2003-2004 <a href="http://www.simulation.tudelft.nl">Delft
38   * University of Technology </a>, the Netherlands. <br>
39   * See for project information <a href="http://www.simulation.tudelft.nl">
40   * www.simulation.tudelft.nl </a> <br>
41   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
42   * License (GPL) </a>, no warranty <br>
43   * 
44   * @version Aug 20, 2004 <br>
45   * @author <a
46   * href="http://www.tbm.tudelft.nl/webstaf/elisangelak/index.htm">Elisangela
47   * Kanacilo </a>
48   */
49  public class StoppingPlace
50  {
51      /*** point where the vehicle is allowed to stop */
52      private double progression;
53  
54      /*** length of the stoppingPlace */
55      private double length;
56  
57      /*** controls the availability of the stopping place */
58      private boolean claimed = false;
59  
60      /*** stationTrack to which the stopping place belong */
61      private Station station;
62  
63      /*** track on where the stopping place starts */
64      private TrackInterface startTrack;
65  
66      /*** object to call when sensor is triggered */
67      private BlockTrafficLight callBack;
68  
69      /*** object to call when sensor is triggered */
70      private int sensor;
71  
72      /*** simulator for the virtual BlockTrafficLight */
73      //   private DEVSSimulatorInterface simulator;
74      /***
75       * @param station station to where it belongs
76       * @param track starting track of the stopping place
77       * @param progression position related to the track where the stoppingPlace
78       * starts
79       * @param requestDistance
80       * @param length length of the stopping place
81       * @param simulator
82       */
83      public StoppingPlace(final Station station, final TrackInterface track,
84              final double progression, final double requestDistance,
85              final double length, final DEVSSimulatorInterface simulator)
86      {
87          this.station = station;
88          this.startTrack = track;
89          this.progression = progression;
90          this.length = length;
91          new StationHaltingTrafficLight(this.station, this.station.getName(),
92                  this.startTrack, this.progression, requestDistance + 5.0,
93                  requestDistance, simulator, 0, 10);
94      }
95  
96      /***
97       * @return
98       */
99      public boolean claimStoppingPlace()
100     {
101         if (this.claimed)
102             return false;
103         this.setClaimed(true);
104         return true;
105     }
106 
107     /*** make the stopping place available */
108     public void releaseStoppingPlace()
109     {
110         if (!this.isClaimed())
111             System.out.print("WARNING: stopping place of the progression"
112                     + this.getProgression() + " is already available");
113         else
114         {
115             this.setClaimed(false);
116             System.out.print("stopping place of progression" + this.progression
117                     + " is now set as available");
118         }
119     }
120 
121     /***
122      * (non-Javadoc)
123      * 
124      * @param vehicle
125      * 
126      * @see nl.tudelft.simulation.traffic.controlpoint.ControlPointInterface#pass(nl.tudelft.simulation.traffic.vehicle.VehiclePhysicalInterface)
127      */
128     public void pass(final VehiclePhysicalInterface vehicle)
129     {
130         this.callBack.triggerSensor(this.sensor, vehicle);
131         this.setClaimed(false);
132     }
133 
134     /***
135      * @return Returns the stationTrack.
136      */
137     public Station getStation()
138     {
139         return this.station;
140     }
141 
142     /***
143      * check if the place was already claimed
144      * 
145      * @return
146      */
147     public boolean isClaimed()
148     {
149         return this.claimed;
150     }
151 
152     /***
153      * @return Returns the length.
154      */
155     public double getLength()
156     {
157         return this.length;
158     }
159 
160     /***
161      * @return Returns the progression.
162      */
163     public double getProgression()
164     {
165         return this.progression;
166     }
167 
168     /***
169      * @param claimed The claimed to set.
170      */
171     public void setClaimed(boolean claimed)
172     {
173         this.claimed = claimed;
174     }
175 
176     /***
177      * @return Returns the startTrack.
178      */
179     public TrackInterface getStartTrack()
180     {
181         return this.startTrack;
182     }
183 }