Skip to content

Commit 6ea06ab

Browse files
committed
Refactoring
1 parent 51a0ad9 commit 6ea06ab

File tree

61 files changed

+220
-146
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+220
-146
lines changed

academic/BIBD/BIBD.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050

5151
from pycsp3 import *
5252

53+
assert not variant() or variant("aux")
54+
5355
v, b, r, k, ld = data or (6, 0, 0, 3, 8)
5456
b = (ld * v * (v - 1)) // (k * (k - 1)) if b == 0 else b # when specified at 0, b is automatically computed
5557
r = (ld * (v - 1)) // (k - 1) if r == 0 else r # when specified at 0, r is automatically computed

academic/ChainReaction/ChainReaction.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
from pycsp3 import *
2929

30+
assert not variant() or variant("opt") or variant("mini")
31+
3032
n, k = data or (20, 100)
3133

3234
# x[i] is the ith value of the chain

academic/ChangeMaking/ChangeMaking.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
from pycsp3 import *
3333

34+
assert not variant() or variant("compact")
35+
3436
k = data or 13
3537

3638
if not variant():

academic/Charlotte/Charlotte.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
from pycsp3 import *
2323
import random
2424

25+
assert not variant() or variant("mini")
26+
2527
nWeeks, seed = data or (6, 0)
28+
2629
nNurses = 3
2730
assert nWeeks % nNurses == 0
2831
nDays = nWeeks * 7

academic/ClockTriplet/ClockTriplet.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from pycsp3 import *
3636

3737
r, n = data or (3, 12)
38+
3839
ub = sum(n - v for v in range(r))
3940

4041
# x[i] is the ith number in the circle

academic/Coprime/Coprime.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,12 @@
2222
## Tags
2323
academic, xcsp25
2424
"""
25-
from reportlab.lib.pagesizes import elevenSeventeen
2625

2726
from pycsp3 import *
2827

29-
n = data
30-
D = range(2, n * n + 1)
31-
32-
cache = {}
33-
34-
35-
def T(d):
36-
if d not in cache:
37-
cache[d] = [(u, v) for u in D for v in D if u % d != 0 or v % d != 0]
38-
return cache[d]
28+
n = data or 10
3929

30+
D = range(2, n * n + 1)
4031

4132
# x[i] is the value of the ith element of the coprime set
4233
x = VarArray(size=n, dom=D)
@@ -45,18 +36,34 @@ def T(d):
4536
# setting a lower-bound
4637
[x[i] >= x[-1] // 2 for i in range(n - 1)],
4738

48-
# ensuring that we have coprime integers
49-
[(x[i], x[j]) in T(d) for i, j in combinations(n, 2) for d in D] if variant("table") else
50-
[
39+
# tag(symmetry-breaking)
40+
Increasing(x, strict=True)
41+
)
42+
43+
if variant("table"):
44+
cache = {}
45+
46+
47+
def T(d):
48+
if d not in cache:
49+
cache[d] = [(u, v) for u in D for v in D if u % d != 0 or v % d != 0]
50+
return cache[d]
51+
52+
53+
satisfy(
54+
# ensuring that we have coprime integers
55+
(x[i], x[j]) in T(d) for i, j in combinations(n, 2) for d in D
56+
)
57+
58+
else:
59+
satisfy(
60+
# ensuring that we have coprime integers
5161
either(
5262
x[i] % d != 0,
5363
x[j] % d != 0
5464
) for i, j in combinations(n, 2) for d in D
55-
],
5665

57-
# tag(symmetry-breaking)
58-
Increasing(x, strict=True)
59-
)
66+
)
6067

6168
minimize(
6269
# minimizing the highest value of the set

academic/CostasArray/CostasArray_z.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
1919
## Links
2020
- https://mathworld.wolfram.com/CostasArray.html
21-
- https://www.minizinc.org/challenge2015/results2015.html
21+
- https://www.minizinc.org/challenge/2015/results/
2222
2323
## Tags
2424
academic, mzn10, mzn11, mzn15
2525
"""
2626
from pycsp3 import *
2727

28-
n = data
28+
n = data or 15
2929

3030
# x[i] is the ith value of the Costas array
3131
x = VarArray(size=n, dom=range(1, n + 1))

academic/CryptoPuzzle/CryptoPuzzle.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@
3838

3939
from pycsp3 import *
4040

41+
assert not variant() or variant("carry")
42+
4143
word1, word2, word3 = words = [w.lower() for w in data] if data else ("no", "no", "yes")
44+
4245
n = len(word1)
4346
assert len(word2) == n and len(word3) in {n, n + 1}
4447

academic/DeBruijn/DeBruijn.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@
2121
- https://en.wikipedia.org/wiki/De_Bruijn_sequence
2222
- https://mathworld.wolfram.com/deBruijnSequence.html
2323
- http://www.hakank.org/common_cp_models/#debruijn
24-
- https://www.minizinc.org/challenge2008/results2008.html
24+
- https://www.minizinc.org/challenge/2008/results/
2525
2626
## Tags
2727
academic, mzn08
2828
"""
2929

3030
from pycsp3 import *
3131

32-
b, n = data
32+
b, n = data or (3, 6)
33+
3334
m = b ** n
3435
powers = [b ** i for i in range(n - 1, -1, -1)]
3536

academic/Domino/Domino.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
from pycsp3 import *
2626

27-
n, d = data # number of dominoes and number of values
27+
n, d = data or (100, 6) # number of dominoes and number of values
2828

2929
# x[i] is the value of the ith domino
3030
x = VarArray(size=n, dom=range(d))

0 commit comments

Comments
 (0)