-
Notifications
You must be signed in to change notification settings - Fork 0
/
City.py
39 lines (30 loc) · 1.06 KB
/
City.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
import math
class City:
def __init__(self, id, name = None, longitude=None, latitude=None):
self.id = id
if name is not None:
self.name = name
else:
self.name = None
self.longitude = longitude
self.latitude = latitude
self.matrix = []
def __repr__(self):
return str(self.getID()) + ', ' + self.name + f": ({str(self.getLatitude())}, {str(self.getLongitude())})"
def getID(self):
return str(self.id)
def getName(self):
return str(self.name)
def getLatitude(self):
return self.latitude
def getLongitude(self):
return self.longitude
def get_coordinates(self):
return [self.latitude, self.longitude]
def get_cost_matrix(self):
return self.matrix
def distanceTo(self, city):
xDistance = abs(self.getLongitude() - city.getLongitude())
yDistance = abs(self.getLatitude() - city.getLatitude())
distance = math.sqrt((xDistance * xDistance) + (yDistance * yDistance))
return distance