Member: Onur Duman
E-mail: onur.duman@mail.mcgill.ca
The aim of this project is to study modelling of a public transportation system using multi modelling and formalism tool
Ptolemy II. This tool can be used to make a model using block diagrams and statecharts. In the model of transportation
system, both of them will be used so this will be a multimodelling
Basically, transportation system consists of trains which are travelling between stations. The purpose of this modelling
is to take both event concept and time concept into account using the multi modelling and formalism tool Ptolemy II.
Also, Model Modal concept of Ptolemy II will be used here which is putting block diagram logic or another state diagram
Inside a state diagram for complicated calculations.
Also, this model is going to be simulated by getting locations that the train has passed into account. That is a record of
locations the train has passed will be displayed on the screen and if the train is waiting, the output will also be delayed.
Progress of train will be done according to location of the train and some other constraints which will be detailed in the
explanation of the model in Design / Models part.
Sample transportation system studied here consists of four trains and six stations. Each train has an initial location which
is given at the start of simulation.
A train is allowed to depart if there is no train 100 yards in front of the train. A train goes in maximum speed if there is
no train 80 yards in front of the train. If there is a train 80 yards in front of the train, the train will go slowly, in which case its
position will be displayed after some amount of delay. Also, the track on which these trains travel is a circular track. So, this will be
taken into account during location calculations.
Each train has a passenger button, that is a passenger presses the passenger button if the passenger wishes to stop the train
at the next station. If none of the passengers request the train to stop at the next station, the train will pass the station
without stopping. If a train stops at a station, it will wait 90 seconds and if there are no trains 100 yards front of the
train, it will depart
During this simulation, the places where the train has passed on the track will be displayed and if the train stops on a station,
the next output( meaning the next location of the train) will be delayed in order to make the model more realistic. So the train
behaves according to its location on the track.
The design and models consist of both statecharts and block diagrams. In this project, modelling was started by making models of
simple functional blocks.
Firstly, a train is allowed to depart if there is no train 100 yards in front of the train. In order to check this, we need
a functional block which compares location of the train with location of other trains. A block diagram for this purpose is
shown below.
In this block diagram, each train comparison unit is given the task of comparing location of the train with location of
other trains. A detailed view of trainComparisonUnit is given below.
Each train comparison unit works as follows, if location of other train is greater than location of the train with whose location
locations of other trains are compared. If other train is in front of the train, and if the distance between them is less than or
equal to 100, the output is three since there is another train 100 yards front of the train. If location of another train is less than
location of train but since the path is circular, if the sum of distance between train and end of road( point 1200) in ou case
and the location between point 0 to location of the other train is less than 100 the other train is still 100 yards in front of the train
since the point 0 and the point 1200 are the same point, our track is underlined.
Similar functionality is used for checking if there is a train 80 yards of the train, just the constant 100 is changed with the constant 80
This information is used in order to understand if the train should maintain its maximum speed or it should go slowly.
The block diagram for checking if there is a train 80 yards front of the train is shown below.
So, as it can be seen from the diagram, just the constant is changed to 80 instead of 100, this is a good example of reuse.
Another problem is to get the distance from the train to the station and the station number of station to which the train
is approaching. If the train is approaching to a station on which train should stop at, the train is stopped at the station
so this information is needed. The block diagram designed for this purpose is given below. It gets the difference between train
and the station and reports the smallest distance and the station number of smallest station. Also, note that since the path is
circular, is the train has passed station numbered at 1000( stations are located at 0, 200, 400, 600, 800, 1000 ), it is approaching
the station numbered 0 and its distance is 1200 - trainLocation, this case is also handled since the track is circular.
Also, note that 5000 is used as an impossible number in order to ignore the stations the train has passed.
Now, putting these together, we have to model the train. Train is a stateful entity so it can not be modeled using just block diagrams
State diagram feature of Ptolemy II will be helpful here. High level view of the train is given below, ShortDistanceComparator, DistanceComparator
and TerminalDistanceAndNumber are already explained above, so in the following part, TrainFunction and PassengerModel will be explained.
State diagram for the train function is given below. Initial state of the train is PreDeparture. In this state, the train checks if it is more 100 yards away
from another train. If it is the case, train is not running so distance is not incremented( input location and output loc are used to keep track of where the
train is). If there are no trains 100 yards front of the train, train is allowed to depart and in this case location of the train is incresed. Note that we are taking
modulo 1200 after increasing since the path is circular. If the train is running, two cases can occur, it is passing a station and it is not scheduled to stop at the
station, so it is just passing the station without changing its behavior. If it is scheduled to stop at the station it is currently passing, it goes to stopAtStation
state and goes back to PreDeparture after 90 seconds( here this delay is achieved using refinements for states and this refinement will be detailed later).
Running state is a refined state since train can be running slowly or running at maximum speed but in both cases it is running. So, state diagram inside running state is
given below. This is just for keeping if the train is running slowly or running at maximum speed but in either case our events are generated according to location of the train
If the train is running at maximum speed and if there is a train 80 yards front of it, it slows down, if train is running slowly and there is no train in front of it, it goes back
to its maximum speed.
The state stopAtStation is also refined. This state is refined with a totally useless function but this is for the delay that the train should wait if it stops at a station.
The refinement of stopAtStation is shown below. Also note that we added a director in order to control number of firings
Lastly, in order to handle the case that a passenger presses a button, there is another state diagram named PassengerModel. It just sends input to output if there is no passenger
request. If there is passenger request sets next station to closest station. The state diagram for PassengerModel is shown below.
Putting all of these together gives the complete train model for the train.
First experiment is done for a train, initially at position 195 which was scheduled to stop at station 4 but during approach to station1, a passenger requested to stop at
station 1 and the train has stopped at station 1 but it could not continue becuase there is a train in front of it( 100 yards front).
Configuration of experiment is given and also the file for experiment is given at the appendix
Train Locations : 196 197 198 199 200 200 200 200 200 200 200 Train Next Stations: 4 4 4 1 1 1 1 1 1 1 ( at fourth iteration a passenger requested to stop at station 1( nearest station) )
Experiment File : experiment1.xml
The second experiment is done in order to confirm that after stopping at a station, the train is able to continue its travel
if there are no trains 100 yards front of the train
Train Locations : 196 197 198 199 200 200 200 201 202 203 ( After stopping at station 1, train can continue its travel) Train Next Stations: 0 0 0 1 1 1 1 1 1 1 ( at fourth iteration a passenger requested to stop at station 1( nearest station) )
Experiment File : experiment2.xml
To conclude, a train transportation system was studied using multi modelling tool Ptolemy II. Both statecharts and block diagrams are
used for this modelling, which made it a complicated model.
In this system trains travel on a counterclockwise direction and if there is a passenger who is going to get off on the next station, the train
stops at the next station. Otherwise, the train stops at its scheduled station. So, passengers are able to control the train.
Also, the train maintains its speed according to its distance to the train just in front of it. If the difference of distance of the train in front of it and
the distance of the train is more than 80, the train slows down.
State and variables of the train( meaning location and next_station) are changed mainly acording to the location of the train and location of the train is always dispalyed since the state of train mainly
depends on its location. Also, in order to simulate stop at station, we made a small delay of output if the train will stop at the station
1. Transportation System inspired from the article : "Executable Object Modelling with Statecharts"
Article Link
2. Ptolemy II Web site Ptolemy II Project