|
3 | 3 | This is [Problem 003](https://www.csplib.org/Problems/prob003/) at CSPLib. |
4 | 4 |
|
5 | 5 | An order n quasigroup is a Latin square of size n. |
6 | | -That is, a n×n multiplication table in which each element occurs once in every row and column. |
| 6 | +That is, an n×n multiplication table in which each element occurs once in every row and column. |
7 | 7 | A quasigroup can be specified by a set and a binary multiplication operator, ∗ defined over this set. |
8 | 8 | Quasigroup existence problems determine the existence or non-existence of quasigroups of |
9 | 9 | a given size with additional properties. For example: |
@@ -46,80 +46,6 @@ That is, a ∗ a = a for every element a. |
46 | 46 |
|
47 | 47 | ## Tags |
48 | 48 | academic, notebook, csplib, xcsp22 |
49 | | - """ |
50 | | - |
51 | | -from pycsp3 import * |
52 | | - |
53 | | -n = data or 8 |
54 | | - |
55 | | -pairs = [(i, j) for i in range(n) for j in range(n)] |
56 | | - |
57 | | -# x[i][j] is the value at row i and column j of the quasi-group |
58 | | -x = VarArray(size=[n, n], dom=range(n)) |
59 | | - |
60 | | -satisfy( |
61 | | - # ensuring a Latin square |
62 | | - AllDifferent(x, matrix=True), |
63 | | - |
64 | | - # ensuring idempotence tag(idempotence) |
65 | | - [x[i][i] == i for i in range(n)] |
66 | | -) |
67 | | - |
68 | | -if variant("base"): |
69 | | - if subvariant("v3"): |
70 | | - satisfy( |
71 | | - x[x[i][j], x[j][i]] == i for i, j in pairs |
72 | | - ) |
73 | | - elif subvariant("v4"): |
74 | | - satisfy( |
75 | | - x[x[j][i], x[i][j]] == i for i, j in pairs |
76 | | - ) |
77 | | - elif subvariant("v5"): |
78 | | - satisfy( |
79 | | - x[x[x[j][i], j], j] == i for i, j in pairs |
80 | | - ) |
81 | | - elif subvariant("v6"): |
82 | | - satisfy( |
83 | | - x[x[i][j], j] == x[i, x[i][j]] for i, j in pairs |
84 | | - ) |
85 | | - elif subvariant("v7"): |
86 | | - satisfy( |
87 | | - x[x[j][i], j] == x[i, x[j][i]] for i, j in pairs |
88 | | - ) |
89 | | -elif variant("aux"): |
90 | | - if subvariant("v3"): |
91 | | - y = VarArray(size=[n, n], dom=range(n * n)) |
92 | | - |
93 | | - satisfy( |
94 | | - [x[y[i][j]] == i for i, j in pairs if i != j], |
95 | | - [y[i][j] == x[i][j] * n + x[j][i] for i, j in pairs if i != j] |
96 | | - ) |
97 | | - elif subvariant("v4"): |
98 | | - y = VarArray(size=[n, n], dom=range(n * n)) |
99 | | - |
100 | | - satisfy( |
101 | | - [x[y[i][j]] == i for i, j in pairs if i != j], |
102 | | - [y[i][j] == x[j][i] * n + x[i][j] for i, j in pairs if i != j] |
103 | | - ) |
104 | | - elif subvariant("v5"): |
105 | | - y = VarArray(size=[n, n], dom=range(n)) |
106 | | - |
107 | | - satisfy( |
108 | | - [x[:, i][x[i][j]] == y[i][j] for i, j in pairs if i != j], |
109 | | - [x[:, i][y[i][j]] == j for i, j in pairs if i != j] |
110 | | - ) |
111 | | - elif subvariant("v7"): |
112 | | - y = VarArray(size=[n, n], dom=range(n)) |
113 | | - |
114 | | - satisfy( |
115 | | - ( |
116 | | - x[:, j][x[j][i]] == y[i][j], |
117 | | - x[i][x[j][i]] == y[i][j] |
118 | | - ) for i, j in pairs if i != j |
119 | | - ) |
120 | | - |
121 | | -""" Comments |
122 | | -1) note that we can post tuples of constraints instead of individually, as demonstrated in aux-v7 |
123 | 49 |
|
124 | 50 | <br /> |
125 | 51 |
|
|
0 commit comments