-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathworksheet.py
138 lines (112 loc) · 3.3 KB
/
worksheet.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
from sre_constants import ASSERT
from modules.open_digraph import *
from modules.circuit_boolean import *
import inspect
n0 = node(0, 'a', {3:1, 4:1}, {1:1, 2:1})
n1 = node(1, 'b', {0:1}, {2:2, 5:1})
n2 = node(2, 'c', {0:1, 1:2}, {6:1})
i0 = node(3, 'i0', {}, {0:1})
i1 = node(4, 'i1', {}, {0:1})
o0 = node(5, 'o0', {1:1}, {})
o1 = node(6, 'o1', {2:1}, {})
G = open_digraph([3,4], [5,6], [n0,n1,n2,i0,i1,o0,o1])
n3 = node(0, 'x', {}, {1:1,2:1})
n4 = node(1, 'y', {0:1}, {2:1})
n5 = node(2, 'z', {0:1,1:1}, {0:1})
opd = open_digraph([0],[2],[n3,n4,n5])
circuit = bool_circ.random_bool_circ(4,3,3)
circuit_v2 = bool_circ.pars_parenthese("((x0)&(x1)&(x2))|((x1)&(~(x2)))")
#G.save_as_dot_file(verbose=True)
#print(opd.is_cyclic())
#bool_circ.adder('0101', '1110').save_as_dot_file(verbose=True)
def print_test():
print(n0)
print(n1)
print(n2)
print(repr(n0))
print(repr(n1))
print(repr(n2))
print(opd)
print(repr(opd))
def get_test():
print(n1.get_id())
print(n1.get_label())
print(n1.get_parents_ids())
print(n1.get_children_ids())
print(opd.get_input_ids())
print(opd.get_output_ids())
print(opd.get_id_node_map())
print(opd.get_nodes())
print(opd.get_node_ids())
print(opd.get_node_by_id(1))
print(opd.get_nodes_by_ids([1,2]))
def set_test():
print("node setters")
n0.set_id(3)
print(n0.get_id())
n0.set_label("w")
print(n0.get_label())
n0.set_parent_ids({1:2, 2:1})
print(n0.get_parents_ids())
n0.set_children_ids({})
print(n0.get_children_ids())
n0.add_child_id(4,1)
print(n0.get_children_ids())
n0.add_parent_id(0, 0)
print(n0.get_parents_ids())
print("\nopen digraph setters")
opd.set_input_ids([1,2])
print(opd.get_input_ids())
opd.set_output_ids([])
print(opd.get_output_ids())
opd.add_input_id(1)
print(opd.get_input_ids())
opd.add_output_id(4)
print(opd.get_output_ids())
def exo9():
print(dir(node))
print(dir(open_digraph))
print()
print(inspect.getsource(node.__init__))
print(inspect.getdoc(node.__init__))
print(inspect.getsourcefile(node.__init__))
#Exercice 10
#print(opd.new_id())
def Exercice_11_test():
print(repr(opd))
opd.add_edge(2, 0)
print(repr(opd))
opd.add_edge(2, 0)
print(repr(opd))
def Exercice_12_test():
print(repr(opd))
opd.add_node('w', {0:2}, {1:1, 2:3})
print(repr(opd))
print(opd)
def TP3_ex8_test():
graph = open_digraph.random_graph(4, 8, 8, 4)
print(graph)
print(graph.is_well_formed())
def TP3_ex10_test():
graph = open_digraph.random_graph(4, 4, 1, 2)
print(repr(graph))
print(graph.adjacency_matrix())
def TP5_exo_all(opd, G):
print(G)
print(opd.min_id(), " ", opd.max_id())
print(G.min_id(), " ", G.max_id())
GRAPH = opd.parallel(G)
print(GRAPH.connected_components())
def dijkstra_test(G):
#On se rend compte que la distance entre i0 et lui même est bien 0
# la distance entre i0 et o0 est bien 3
# On voit bien dans prev que b est la node qui précède o0 dans le chemin le plus cours
dist, prev = G.dijkstra(i0,o0)
print(dist)
print("\n", prev)
def TP11_exo_5():
circ = bool_circ.pars_parenthese("~(0)")
circ.evaluate()
circ.save_as_dot_file(verbose=True)
print(circ)
TP11_exo_5()