-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.py
73 lines (68 loc) · 2.71 KB
/
graph.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
##########################################################################
# #
# cwb2dot #
# Copyright (C) 2019 Tobia Tesan #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
##########################################################################
from process import *
from misc import *
class Node():
def __init__(self, p, e, name=[]):
self.color = False
debug_out(e.__class__)
assert(e.__class__ == set)
self.p = p
self.e = e
self.name = name
def __repr__(self):
return "Node("+str(self.p) +"," +str(self.e)+")"
class Edge():
def __eq__(self, other):
if (other.__class__ == Edge and
other.a == self.a and
other.n == self.n):
return True
return False
def __hash__(self):
return hash(self.a) + hash(self.n)
def __init__(self, a, n, name=[]):
assert(a is not None)
assert(isinstance(a, Action))
assert(n is not None)
assert(isinstance(n, Node))
self.a = a
self.n = n
def __repr__(self):
return "--"+str(self.a)+"-->" +str(self.n.p)
def traverse(g):
visited = list()
traversal = list()
import queue
q = queue.Queue()
q.put(g)
visited.append(g)
while (not q.empty()):
n = q.get()
traversal.append(n)
for e in n.e:
if(e.n not in visited):
q.put(e.n)
visited.append(e.n)
print("TRAVERSAL")
for v in visited:
print("")
print(v)
print("END TRAVERSAL OF", len(visited), "NODES")