Docsity

Practice Assignment 4 - Algorithms and Data Structures | CS 2420, Assignments of Computer Science

Toggle sidebar
bg1
CS 2420 – Fall 2006
Assignment 4 – 20 points
Due September 27, 2006
Railroad Tycoon
Story Line:
It's a wild frontier out there, in the Australian Outback. Mining towns, farming towns, military forts,
trading posts... and all of them need the same thing: A way to get their goods and services from one
place to another. That's where you come in, you old railroad baron, you. If you can get set of railroad
lines in place, you can charge money for anything that moves on your lines. And because money is an
important thing in your life, you want to make your railroad lines for as little money as possible.
Objective:
Given a set of towns, their locations, and their elevations, write a function that designs a railroad
network designed to service each town at minimum cost. Additionally, you are to write a function that
will plan a path from any one town to any other town using that rail system.
Details, details:
You are to read from standard input a list of towns, followed by three integers describing an x and y
coordinate (in kilometers), and an elevation (also in kilometers):
<town name> <x coordinate> <y coordinate> <elevation>
The last town in the list is always called “Zaboonaboon.”
You may assume a maximum number of 50 towns, if you wish.
The cost to create a railroad between two points can be determined by the following equation:
cost(k$) = distance + (10 * distance * sine(elevation_angle) )
For example, two towns 1km from each other on the same elevation could be joined by a railroad for a
cost of 1 Australian kilodollar, but two towns 1km from each other with a height different of 100 meters
would cost roughly 1.995 Australian kilodollars.
Your function should be given an array of coordinates and elevations, plus an (empty) adjacency array
(plus whatever else you need). It should fill in the adjacency array with the designed railroad system
and return the cost needed to build it. Your program should print to standard output the resulting
adjacency array.
CS 2420 – Assignment 3 Page 1
pf3
pf4

Partial preview of the text

Download Practice Assignment 4 - Algorithms and Data Structures | CS 2420 and more Assignments Computer Science in PDF only on Docsity!

CS 2420 – Fall 2006

Assignment 4 – 20 points

Due September 27, 2006

Railroad Tycoon

Story Line:

It's a wild frontier out there, in the Australian Outback. Mining towns, farming towns, military forts,

trading posts... and all of them need the same thing: A way to get their goods and services from one

place to another. That's where you come in, you old railroad baron, you. If you can get set of railroad

lines in place, you can charge money for anything that moves on your lines. And because money is an

important thing in your life, you want to make your railroad lines for as little money as possible.

Objective:

Given a set of towns, their locations, and their elevations, write a function that designs a railroad

network designed to service each town at minimum cost. Additionally, you are to write a function that

will plan a path from any one town to any other town using that rail system.

Details, details:

You are to read from standard input a list of towns, followed by three integers describing an x and y

coordinate (in kilometers), and an elevation (also in kilometers):

The last town in the list is always called “Zaboonaboon.”

You may assume a maximum number of 50 towns, if you wish.

The cost to create a railroad between two points can be determined by the following equation:

cost(k$) = distance + (10 * distance * sine(elevation_angle) )

For example, two towns 1km from each other on the same elevation could be joined by a railroad for a

cost of 1 Australian kilodollar, but two towns 1km from each other with a height different of 100 meters

would cost roughly 1.995 Australian kilodollars.

Your function should be given an array of coordinates and elevations, plus an (empty) adjacency array

(plus whatever else you need). It should fill in the adjacency array with the designed railroad system

and return the cost needed to build it. Your program should print to standard output the resulting

adjacency array.

Following the list of towns is a set of town pairs, coming from standard input. Your program should

read in each pair and print out to standard output the distance along your railroad system from one to

the other, along with the names of the cities visited along the way. The last destination in the list of

town pairs is always “Zaboonaboon,” which appears nowhere else in the list.

Questions:

1. Use both the depth-first and the breadth-first strategy to traverse the graph in Figure 1,

beginning with vertex a and list the vertices in the order in which each traversal visits

them. Always consider the edges in left-to-right order.

Figure 1 Graph Figure 2 Graph

2. For the directed graph in Figure 1, show the topological order.

3. For the graph in Figure 2, show the minimum spanning tree.

4. For the graph in Figure 2, find the shortest path to each node in the graph starting at node

a.

What to turn in:

Include a short narrative of your program in with your report, including the questions, and describe one

set of results garnered from it. Turn in your source code along with your report in a zipped archive.

And for the set of pairs: Sheilaville Billabong Wangalawa Fangbooboo Walkaboutcanyon Fangbooboo Sheilaville Yangboola Mercy Cawbillabilla Fangbooboo Walkaboutcanyon Chikamakagalwallawalla Plax Killdunnen Walkaboutcanyon Sheilaville Coocoobyrnie Boongalla Fangbooboo Walkaboutcanyon Zaboonaboon My program found: Sheilaville -> Gatorcreek -> Wangalawa -> Flitcairn -> Fangbooboo -> Billabong Wangalawa -> Flitcairn -> Fangbooboo Walkaboutcanyon -> Mercy -> Zaboonaboon -> X -> Billabong -> Fangbooboo Sheilaville -> Gatorcreek -> Wangalawa -> Flitcairn -> Chikamakagalwallawalla -> Cawbillabilla -> Yangboola Mercy -> Zaboonaboon -> X -> Billabong -> Fangbooboo -> Flitcairn -> Chikamakagalwallawalla -> Cawbillabilla Fangbooboo -> Billabong -> X -> Zaboonaboon -> Mercy -> Walkaboutcanyon Chikamakagalwallawalla -> Flitcairn -> Fangbooboo -> Billabong -> X -> Plax Killdunnen -> Yangboola -> Cawbillabilla -> Chikamakagalwallawalla -> Flitcairn -> Fangbooboo -> Billabong -> X -> Zaboonaboon -> Mercy -> Walkaboutcanyon Sheilaville -> Gatorcreek -> Wangalawa -> Flitcairn -> Fangbooboo -> Billabong -> X -> Zaboonaboon -> Mercy -> Coocoobyrnie Boongalla -> Zaboonaboon -> X -> Billabong -> Fangbooboo Walkaboutcanyon -> Mercy -> Zaboonaboon