-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNode.py
110 lines (96 loc) · 3.71 KB
/
Node.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
'''
Created on Feb 25, 2014
@author: Oscar
'''
import ast
import json
class Metro(object):
'''
A Metro object representing a node of the graph
'''
code = ""
name = ""
country = ""
continent = ""
timezone = 0
coordinates = {}
population = 0
region = 0
routes = {} #Where Key is the destination metro's name
djikstras_visit = False
djikstras_distance = float('+inf')
prev = None
def __init__(self, code, name, country, continent, timezone, coordinates, population, region, routes):
'''
Constructor for the Metro
'''
self.code = code
self.name = name
self.country = country
self.continent = continent
self.timezone = timezone
self.coordinates = coordinates
self.population = population
self.region = region
self.routes = routes
def printInformation(self):
'''
Prints all the information about the Metro
'''
destinations = ""
print "Code: " + self.code
print "Name: " + self.name
print "Country: " + self.country
print "Continent: " + self.continent
print "Timezone:", self.timezone
print "Coordinates:",
for key in self.coordinates:
print key + ":", self.coordinates[key],
print
print "Population:", self.population
print "Region:", self.region
print "Destinations:",
destinations = [(self.routes[key].destination.name + " at " + str(self.routes[key].distance) + " kilometers") for key in self.routes]
print ", ".join(destinations)
def setCode(self, code):
if type(code) is not str:
print "Please enter a valid code."
else:
self.code = code
def setName(self, name):
if type(name) is not str:
print "Please enter a valid name."
else:
self.name = name
def setCountry(self, country):
if type(country) is not str:
print "Please enter a valid country."
else:
self.country = country
def setContinent(self, continent):
if (continent != "North America" and continent != "South America" and continent != "Antarctica" and
continent != "Europe" and continent != "Asia" and continent != "Australia" and continent!="Africa"):
print "Please enter a valid continent (North America, South America, Antarctica, Europe, Asia, or Australia, or Africa)."
else:
self.continent = continent
def setTimezone(self, timezone):
if type(timezone) is not int:
print "Please enter a valid timezone value."
else:
self.timezone = timezone
def setCoordinates(self):
coordOneDir = raw_input("What is the first heading of the coordinate? ")
coordOneVal = raw_input("What is the degree of the first heading? ")
coordTwoDir = raw_input("What is the second heading of the coordinate? ")
coordTwoVal = raw_input("What is the degree of the second heading? ")
self.coordinates = {coordOneDir: coordOneVal, coordTwoDir: coordTwoVal}
def setPopulation(self, population):
if population<0 or type(population) is not int:
print "Please enter a valid population value."
else:
self.population = population
def setRegion(self, region):
if region<0 or type(region) is not int:
print "Please enter a valid region value."
else:
self.region = region