Restructured 053
@@ -22,35 +22,11 @@ Modified by Ignace Bleukx
from cpmpy import *
import numpy as np
+def gracefull_graphs(m,n,graph):
+ graph = np.array(graph)
-if __name__ == "__main__":
model = Model()
- # data
- m = 16
- n = 8
-
- # Note: 1 based. Adjusted below
- graph = [[1, 2],
- [1, 3],
- [1, 4],
- [2, 3],
- [2, 4],
- [3, 4],
-
- [5, 6],
- [5, 7],
- [5, 8],
- [6, 7],
- [6, 8],
- [7, 8],
-
- [1, 5],
- [2, 6],
- [3, 7],
- [4, 8]]
- graph = np.array(graph)
-
# variables
nodes = intvar(0, m, shape=n, name="nodes")
edges = intvar(1, m, shape=m, name="edges")
@@ -61,8 +37,28 @@ if __name__ == "__main__":
model += (AllDifferent(edges))
model += (AllDifferent(nodes))
+ return model, (nodes, edges)
+
+
+def get_data():
+ # data
+ m = 16
+ n = 8
+
+ # Note: 1 based. Adjusted below
+ graph = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4],
+ [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [7, 8],
+ [1, 5], [2, 6], [3, 7],[4, 8]]
+
+ return m,n,graph
+
+if __name__ == "__main__":
+
+ data = get_data()
+ model, (nodes, edges) = gracefull_graphs(*data)
+
if model.solve():
- print(f"{edges.value()= }")
- print(f"{nodes.value()= }")
+ print(f"edges: {edges.value()}")
+ print(f"nodes: {nodes.value()}")
else:
print("Model is unsatisfiable")
\ No newline at end of file
