Complex Algorithms
Complex Algorithms
Name:
find_route
Description:
The railway layout is made up of several lines (red, blue … etc), which contain stations
on each line. Based on the design of the rail network it is possible to get from one station
to any other possible station. After there has been 1 or many routes established the
algorithm would check if the route is valid, i.e. the station is reachable via that line. If
there is more than one route to the destination station, the algorithm will calculate the
shortest route for the user.
find_route(origin_station, destination)
{
will return ROUTE_ARRAY (Array of all possible routes between
origin and destination stations)
check_route(route_array)
{will return BOOLEAN (if the destination is reachable, and
remove all unreachable paths from route_ array)
find_shortest_route(route_array)
{will return shortest route of
valid routes in the route_array}
}
}
The route information will be displayed on the interface and printed on the customer’s
ticket for later reference.
Preconditions:
The user will enter into the system their origin and destination station.
Post Conditions:
The user will receive if the station is reachable, the route is valid and the shortest route.
The issuing of a ticket and the display on the interface will show this. If the destination is
not reachable it will be displayed to the user by a dialogue box, and allow them to choose
an alternate destination.
Other Operations:
The other operation called will be calculatefare. It will allow for the correct fare to be
calculated after there is a correct origin and destination station.
Attributes:
The attributes used in finding the best route are Status, Origin and Destination. Status will
be a Boolean variable that will return whether a station is operational or not. Origin will
be the default station that machine is set to. Destination will be set based on the
destination station that the user inserts into the PurchaseTicketWindow.
Response to Exceptions:
If the destination is not valid, or is unavailable the user will be prompted through a dialog
box. This box will inform the user the station is unavailable and allow the user to close
the box and return to selecting another possible destination.
Name:
Calculate_Fare
Description:
The system will calculate the traveller’s fare by processing the inputed values the traveler
has specified (destination station/zone, traveler characteristics , fare type) along with the
known values (stored rates in the system database and the default station).
Preconditions: The user will enter their selected destination, fare type and traveler
characteristic into the system
The system will find the cheapest route by running the complex algorithm shown above.
Postcoditions: The system will return to the user the TotalPrice, a value based upon the
cheapest and quickest route traversed.
Events transmitted to other objects: The TotalPrice value, found using CalculateFare, will
be used to find the BalanceLeft in the PaymentWindow, once the traveler has selected to
pay for the ticket/s by cash and starts pushing the cash denomination buttons.
Attributes:
The attributes used in calculating the fare are: source_station, destination, faretype and
traveler. The source station is the origin station (set to default within the system – default
depends on the station where the system is located). The destination, is the provided
station/zone to be reached from the source_station (specified by the traveler).
The faretype is the type of ticket that the traveler wishes to purchase (for example a
weekly ticket). The traveler is the characteristic of the traveler – which determines the
fare rate (for egs a child will be granted a 50% discount)