CS452 - Real-Time Programming - Winter 2013
Lecture 26 - Reserving Track
Public Service Annoucements
- When you will give the second demo
Track Reservations
A possible solution to collision avoidance
You have to be able to look ahead.
To do so treat the track as a divisible resource like pixels on a display.
Train driver requests some of the resource in order to move.
- He needs enough track that it can come to a stop.
- The server that "gives" we would call a reservation manager.
- The train driver should always be prepared to act safely if a request
for track fails.
A Staged Approach
1. A very simple way to do it not very well
- Train driver gets a job to do using the train, and figures out whither
he needs to move.
- Train driver asks for a route to that place.
- Train driver is blocked until no other train is moving.
- Route provided avoids stopped trains, which are guaranteed to stay
in the same place.
- Train driver requests track all the way to the end of the route from
the track manager.
- Train driver drives the train to the end of the route.
- Train driver switches switches as needed.
- It's not a bad idea to switch switches even for merging.
Why?
- As a general rule train drivers can only switch switches that they
have reserved.
- Train driver tells route finder
- that the train is stopped at the end of its route.
Only one problem here but it's a big one: only one train moves at a time.
But, you have basic route-finding and sensor attribution working and there
are no collisions.
Just be sure that your implementation is extensible to the following
extensions.
2. Getting two trains moving at once
We have to elaborate the third step above to take into account other
moving trains.
- as above
- as above
- Route finder excludes track blocked by stationery trains and track that
is reserved
- The train driver is blocked until the request (2.) can be
satisfied.
- Except for sidings this should almost always be possible.
- as above
- as above
- Train driver returns requested track to the track manager.
You now have two trains moving at once most of the time, but the solution
does not scale well with number of trains.
3. Removing one bottleneck
A moving train holds its entire route until it is finished moving. It
could free parts of the route it will not traverse again. To do so elaborate
steps 5 and 6.
- as above
- as above
- as above
- as above
- Train driver drives to the end of the route switching switches.
- As it leaves track for the last time it returns that part of the
reservation to the track manager.
- Train driver continues to hold the piece of track on which the train
sits.
Trains that are blocked waiting for a route now wait for less time, the
solution scales a little better but more improvements can be made.
4. Removing another bottleneck
The solution above can be made less conservative by starting a train
moving before it can get a complete path by giving the train driver
incomplete routes, by changing steps 3, 4 & 5.
- as above
- as above
- If possible route finder provides a route that goes all the way. If
not, route finder chooses an intermediate destination closer to the final
destination that doesn't cross any route.
- Train driver requests track to the intermediate destination.
- Train driver drives to the intermediate destination.
- It releases track as it leaves it.
- It periodically requests a route extension. If it gets one it
reserves the additional track and adjusts its driving
accordingly.
- as above
Return to: