Sunteți pe pagina 1din 7

Trip Through Germany

Sean Ross

Objective:
You have come into some money and would like to take your parents and grandparents on a once-in-alifetime trip before the Fed completely devalues the US currency and the Euro is worthless. Oma and
Opa live in Chicago and are elated by the 2008 election results. Your parents have recently moved to
Nashville, Tn. You will be taking your Mom, Dad, Oma and Opa back to Germany to visit all of the places
that were near/dear to their hearts growing up, especially before the war.
Here are the cities as follows:
Rostock
Lubeck (home of the best marzipan)
Hamburg (Oma/Opa want to drive under the river - a taxi can do this as well)
Bremen
Hannover (Consumer Electronics haven - purchase each a new iPad at 180 Euros each)
Kassel
Dusseldorf
Koln (taxi will be needed to visit the castle 10km away from the hauptbahnhof)
St. Augustine
Bonn
Wiesbaden
** Frankfurt
Mannheim
Karlsruhe
Baden Baden (Oma wants to visit a Spa here, therefore, you will need to spend the day)
** Stuttgart
** Munchen (Munich)
Nurnberg
Dresden
Leipzig
** Berlin
Basel, Switzerland (Opa and Dad want to purchase a nice watch and this is the best place for such a
purchase - you will be spending $6k/watch)
You will be using Priceline.com, Travelocity.com, Orbitz.com or whatever online travel site you would like
to use. As Oma/Opa are advancing in years, you want to minimize time traveled (Oma can basically only
handle short periods of time traveling, especially with a bad back).
The cities that are starred are the only cities you are allowed as a starting point (or entry into Germany),
because your plane arrives into Germany from the US. You will have the option of renting a car, or taking
the ICE train http://www.raileurope.com/train-faq/european-trains/ice/how-to-book.h... (Links to an
external site.)
If you take the train, you will need to take a taxi (1,2 Euros/km traveled). Most taxis can barely
accommodate 5 people comfortably.
You are not only going to calculate the optimal route based on the TSP, but you will also need to
MINIMIZE your costs. If you rent a car, it will cost roughly 300 Euros/week for Diesels and 350

Euros/week for petrol based cars plus taxes. Normally taxes for these cars are 2x the base rate (eg. 300
Euros because you rented this from the airport; 300 Euros German taxes). Travel speed from point-topoint is roughly 130kmh (max). If you drive a Turbo Diesel (Audi/BMW/VW), you can get roughly
13km/liter and petrol based cars can get a little bit better mileage at about 22km/liter and current petrol
prices can be found here: http://www.aaireland.ie/AA/Motoring-advice/Petrol-Prices.aspx (Links to an
external site.)
For the database chapter you will be collecting ALL of the necessary data for this assignment placing this
data in an open source database of your own choice (MySQL, postgres, sqllite, etc.) You will also be
using this to pull and store your data for whatever algorithm you feel will work the best below. Hint: you
might want ALL of the data in your database already calculated? Remember, I want this as
km/Euros and then have your program use http://www.xe.com/ (Links to an external site.) to convert to
miles/km.
For the chapters on Graphs/Trees you will be using Dijkstra, Prim or possibly Kruskal's algorithms to
solve the optimization piece of cost, time & travel. Bonus points for the one who optimizes all of the
constraints. I would like a bottom line COST, TIME and ROUTE for this trip. As in Physics
problems, omit friction, lodging and food costs.

What Worked:
I Used a list of tuples to represent my map, and storing my map in an
adjacency matrix worked the best for reading and displaying the data.
What didn't Work:
I was never able to connect to www.xe.com to convert to USD from within my
application I kept getting automation error from the website.

Comments:
Originally I wanted to make a map for prices to compare public trans port and
cabs to renting a car. Since there were no trans that run between some of the
longer distances and would cost more than the total of a rental it seemed as
though it would do no good.

__author__ = 'Sean Ross'


import GermanyDataBase
import sys
idx_dict = {'Berlin': 0, 'Leipzig': 1, 'Dresden': 2, 'Hamburg': 3, 'Hanover': 4, 'Lubeck': 5, 'Rostock': 6,
'Nurenberg': 7, 'Kassel': 8, 'Frankfurt': 9, 'Bremen': 10, 'Munich': 11, 'Stuttgart': 12, 'Karlsuhe':
13,
'Bonn': 14, 'Wiesbaden': 15, 'Duseldorf': 16, 'Koln': 17, 'St. Augustine': 18, 'Mannheim': 19,
'Baden-Baden': 20}
flight_time_to = 13.85
flight_time_from = 15.63
flight_cost = 8577.47
def shortest_path(dist_map, starting_point):
visited = []
total_dist = 0
node = starting_point
while len(visited) < len(dist_map):
sm_tup = find_smallest(node, total_dist, visited)
total_dist = sm_tup[1]
visited.append(node[0])
node = dist_map[idx_dict[sm_tup[0]]]
# if len(new_node) > 0:
# node = new_node
ret = (total_dist, visited)
return ret
def find_smallest(node, total_dist, visited):
e1 = node[1][0][1]
n1 = node[1][0][0]
leng = len(node[1])
new_node = node[0]
smallest = total_dist
idx = 0
while idx < len(node[1]) - 1:
e2 = node[1][idx + 1][1]
n2 = node[1][idx + 1][0]
if not visited.__contains__(n1) and not visited.__contains__(n2):
if e2 + total_dist < e1 + total_dist:
smallest = e2 + total_dist
new_node = n2
e1 = e2
n1 = n2

else:
if not visited.__contains__(n1):
smallest = e1 + total_dist
new_node =n1
if not visited.__contains__(n2):
smallest = e2 + total_dist
new_node = n2
e1 = e2
n1 = n2
idx += 1
ret = (new_node, smallest)
return ret
def time_conversion(hr):
minu = int(hr*60 % 60)
hr = int(hr)
time = (hr, minu)
return time
def petrol_vs_diesel():
km = data[0]
petrol = km/22.0*20.36+(350*2*3)
diesel = km/13.0*20.36+(300*2*3)
if diesel > petrol:
return (petrol, 'petrol')
else:
return (diesel, 'diesel')
data = shortest_path(GermanyDataBase.reformat_data(),
GermanyDataBase.reformat_data()[idx_dict['Stuttgart']])
idx = 1
print '%s' % "The shortest path through germany starting from Stuttgart "
while idx < len(data[1]):
sys.stdout.write(" > ")
sys.stdout.write(data[1][idx])
idx += 1
if idx % 5 is 0:
print ''
print '%s%s%s%s%s%s%s%s%s' % (" with a total distance traveled of ", data[0], " km. Total \ntravel
Time ",

cost ',

time_conversion(data[0]/130 + flight_time_to + flight_time_from)[0], ' hours and ',


time_conversion(data[0]/130 + flight_time_to + flight_time_from)[1], ' minuets.\n Total
petrol_vs_diesel()[0] + flight_cost, ' EU')

__author__ = 'Sean'
import MySQLdb
city_dict = {1: 'Berlin', 2: 'Leipzig', 3: 'Dresden', 4: 'Hamburg', 5: 'Hanover', 6: 'Lubeck', 7: 'Rostock',
8: 'Nurenberg', 9: 'Kassel', 10: 'Frankfurt', 11: 'Bremen', 12: 'Munich', 13: 'Stuttgart', 14:
'Karlsuhe',
15: 'Bonn', 16: 'Wiesbaden', 17: 'Duseldorf', 18: 'Koln', 19: 'St. Augustine', 20: 'Mannheim',
21: 'Baden-Baden'}
# Connect to the Data Bae
data_base = MySQLdb.connect("localhost", "Opa", "Gutentag", "germany_trip")
# Create a cursor object using the cursor method
cursor = data_base.cursor()
def read_data_base():
results = []
# Setup an SQL query to read the entire data base
sql_query = "SELECT * FROM germany_distances \
WHERE Cities < bit_length(32)"
try:
# Execute the SQL command
cursor.execute(sql_query)
# Fetch all the rows in a list of lists.
results = cursor.fetchall()
except MySQLdb.OperationalError:
print "Unable to fetch Column"
except MySQLdb.ProgrammingError:
print "Unable to fetch Table"
return results
def reformat_data():
results = read_data_base()
new_results = []
for row in results:
i=1
new_row = ()
while i < len(row):

if row[i] is not None:


tup = (city_dict[i], int(row[i]))
new_row += (tup, )
del tup
i += 1
dist_row = (row[0], new_row)
new_results.append(dist_row)
del new_row
del dist_row
return new_results

S-ar putea să vă placă și