0% found this document useful (0 votes)
2 views

Complex Algorithms

The document outlines two algorithms, find_route and calculate_fare, for a railway system. The find_route algorithm determines if a destination station is reachable from a starting station and calculates the shortest valid route, while the calculate_fare algorithm computes the fare based on the destination, traveler characteristics, and fare type. Both algorithms interact with user inputs and produce outputs that are essential for ticketing and fare calculation processes.

Uploaded by

nisiy20365
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Complex Algorithms

The document outlines two algorithms, find_route and calculate_fare, for a railway system. The find_route algorithm determines if a destination station is reachable from a starting station and calculates the shortest valid route, while the calculate_fare algorithm computes the fare based on the destination, traveler characteristics, and fare type. Both algorithms interact with user inputs and produce outputs that are essential for ticketing and fare calculation processes.

Uploaded by

nisiy20365
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

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.

Input and Output:


The input into the algorithm find_route will be a starting station and a destination station.
The algorithm will return if the station is reachable and the best possible route for the
user to travel on. The signatures are as follows for the algorithm find_route.

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.

Events transmitted to other objects:


The output from the find_route algorithm will be used in other classes in the production
of the ticket and calculation of the fare. So the find_route algorithm will insert the correct
destination into calculatefare in the TicketSale control class. This calculated fare would
then be inserted into PaymentWindow with the destination station. After the payment
cycle is complete the ticket will be produced.

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).

Input and Output


The input required for this algorithm is provided by the traveler: destination, traveler
characteristic and fare type.
The output produced is based upon the quickest, cheapest route found (Assume: the
quickest route traversed produces the cheapest fare).
The signatures are as follows for the algorithm calculate_fare:

Calculate_fare(source_station, destination, faretype, traveler)


{
Will return TotalPrice (the price for the cheapest – ie quickest route traversed)

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.

Other Operations: The FindShortestRoute(route_array) will return the shortest (and as


we assume cheapest) route.

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)

You might also like