Restructured 049
@@ -9,13 +9,7 @@ import sys
import numpy as np
from cpmpy import *
-
-if __name__ == "__main__":
- if len(sys.argv) > 1:
- n = sys.argv[1]
- else:
- n = 8
-
+def number_partitioning(n=8):
assert n % 2 == 0, "The value of n must be even"
# x[i] is the ith value of the first set
@@ -38,9 +32,17 @@ if __name__ == "__main__":
model += x[:-1] <= x[1:]
model += y[:-1] <= x[1:]
+ return model, (x,y)
+
+if __name__ == "__main__":
+ n = 8
+ if len(sys.argv) > 1:
+ n = sys.argv[1]
+
+ model, (x,y) = number_partitioning(n)
+
if model.solve():
print(f"x: {x.value()}")
print(f"y: {y.value()}")
-
else:
print("Model is unsatisfiable")
\ No newline at end of file
