-
Notifications
You must be signed in to change notification settings - Fork 0
/
12_5.py
31 lines (29 loc) · 979 Bytes
/
12_5.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
class Node(object):
def __init__(self, name):
"""nameは文字列とする"""
self.name = name
def getName(self):
return self.name
def __str__(self):
return self.name
class Edge(object):
def __init__(self, src, dest):
"""srcとdestはどちらもNodeオブジェクトとする"""
self.src = src
self.dest = dest
def getSource(self):
return self.src
def getDestination(self):
return self.dest
def __str__(self):
return self.src.getName() + '->' + self.dest.getName()
class WeightedEdge(Edge):
def __init__(self, src, dest, weight = 0.0):
"""srcとdestはNodeオブジェクトとし、weightは数とする"""
self.src = src
self.dest = dest
self.weight = weight
def getWeight(self):
return self.weight
def __str__(self):
return self.src.getName() + '->(' + str(self.weight) +')' + self.dest.getName()