generated from framunoz/python-library-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.py
151 lines (120 loc) · 3.8 KB
/
example.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
139
140
141
142
143
144
145
146
147
148
149
150
151
import networkx as nx
from matplotlib import pyplot as plt
from rubiks_cube.cube import RubikCube
from rubiks_cube.graph import make_graph, generate_file
from rubiks_cube.movements import CubeMove as CM
from rubiks_cube.plotters import GraphPlotter
from rubiks_cube.satisfiability import solve_clause_interpreted, generate_cnf_file
from rubiks_cube.utils import Color
def main():
# f = Face(Color.BLUE, (2, 2))
rc = RubikCube.from_dims(
(1, 3, 2),
# {CM.R2, CM.U2, CM.D2}
)
print(rc, end="\n\n")
rc = rc.make_movements("hola")
print("\n", rc, "\n", sep="")
# list_of_movements = [
# CM.U, CM.R, CM.D, CM.L,
# CM.D, CM.R, CM.D, CM.R
# ]
list_of_movements = [
CM.U2, CM.R2, CM.D2, CM.L2,
CM.D2, CM.R2, CM.D2, CM.R2
]
for m in list_of_movements:
print(f"{m = }")
rc = rc.make_a_move(m)
print(rc, end="\n\n")
print("Faces")
for f in rc.faces:
print(f, end="\n\n")
print(CM.R)
print(hash(Color.BLUE), hash(Color.BLUE))
print(hash("blue"), hash("blue"))
def main2():
g: nx.Graph = make_graph(
(1, 3, 2),
{CM.R2, CM.L2, CM.B2}
)
n: int = len(g)
m: int = g.number_of_edges()
print(f"{n = }, {m = }")
# for i, rc in enumerate(g.nodes):
# print(f"Estado {i = }")
# print(rc)
# print(g.nodes[rc])
# print("Vecinos:")
# neighbors = list(g[rc].keys())
# neighbors.sort(key=lambda x: hash(x))
# print(g[rc])
gp = GraphPlotter(g)
gp.compute_kamada_kawai_layout()
U, V = gp.find_bipartite()
gp.draw()
# Dictionaries in the convention id - Rubik's Cube. Bipartition
print({g.nodes[n]["id"]: n for n in U})
print({g.nodes[n]["id"]: n for n in V})
plt.show()
def main3():
g: nx.Graph = make_graph((1, 3, 2), {CM.R2, CM.L2, CM.B2})
U, V = nx.algorithms.bipartite.sets(g)
print(U, V)
print(len(U), len(V))
def main4():
g: nx.Graph = make_graph((1, 3, 2), {CM.R2, CM.L2, CM.B2})
# clauses = generate_clauses(g, 0, 1)
# print("Generando fórmulas en CNF")
# generate_cnf_file(g, RubikCube.from_dims((1, 3, 2)))
print("Resolviendo primera fórmula")
# model = solve_clause("clauses/rubik-1.cnf")
model = solve_clause_interpreted(g, "clauses/rubik-7.cnf")
print("Revisando parámetros")
for v in model:
print(v)
def main5():
# model = solve_clause("clauses/rubik-1.cnf")
model = solve_clause_interpreted("clauses/rubik-1.cnf")
for v in model:
print(v)
def main6():
g: nx.Graph = make_graph(
(1, 3, 3),
{CM.R2, CM.L2, CM.B2, CM.F2}
)
n: int = len(g)
m: int = g.number_of_edges()
print(f"{n = }, {m = }")
generate_file(g)
generate_cnf_file(g, RubikCube.from_dims((1, 3, 3)), "clauses_1_3_3", verbose=True)
for i, rc in enumerate(g.nodes):
print(f"Estado {i = }")
print(f'{rc = }')
print(f'{g.nodes[rc] = }')
print("Vecinos:")
neighbors = list(g[rc].keys())
neighbors.sort(key=lambda x: hash(x))
print(g[rc])
# gp = GraphPlotter(g)
# U, V = gp.compute_bipartite_layout(scale=1, aspect_ratio=2000000000)
# gp.compute_kamada_kawai_layout(scale=10)
# U, V = gp.find_bipartite()
# gp.draw()
# Dictionaries in the convention id - Rubik's Cube. Bipartition
# print({g.nodes[n]["id"]: n for n in U})
# print({g.nodes[n]["id"]: n for n in V})
# plt.show()
def main7():
g: nx.Graph = make_graph(
(1, 3, 3),
{CM.R2, CM.L2, CM.B2, CM.F2}
)
n: int = len(g)
m: int = g.number_of_edges()
print(f"{n = }, {m = }")
generate_file(g)
generate_cnf_file(g, RubikCube.from_dims((1, 3, 3)), "clauses_1_3_3", verbose=True)
if __name__ == '__main__':
main7()
# main5()