Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
Yan Georget committed Jan 8, 2025
1 parent 0b88cca commit dfe50d2
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions nucs/examples/quasigroup/quasigroup_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Copyright 2024-2025 - Yan Georget
###############################################################################
from nucs.problems.latin_square_problem import M_COLOR, M_COLUMN, M_ROW, LatinSquareProblem, LatinSquareRCProblem
from nucs.propagators.propagators import ALG_ELEMENT_LIC, ALG_ELEMENT_LIV
from nucs.propagators.propagators import ALG_ELEMENT_LIC, ALG_ELEMENT_LIV, ALG_ELEMENT_LIV_ALLDIFFERENT


class QuasigroupProblem(LatinSquareProblem):
Expand Down Expand Up @@ -75,6 +75,10 @@ def __init__(self, kind: int, n: int, idempotent: bool, symmetry_breaking: bool
for model in [M_COLOR, M_ROW, M_COLUMN]:
for i in range(n):
self.shr_domains_lst[self.cell(i, i, model)] = [i, i]
for i in range(1, n):
self.shr_domains_lst[self.cell(0, i, model)] = [1, n - 1]
for i in range(0, n - 1):
self.shr_domains_lst[self.cell(n - 1, i, model)] = [0, n - 2]
for i in range(n):
for j in range(n):
if not idempotent or j != i:
Expand All @@ -84,7 +88,7 @@ def __init__(self, kind: int, n: int, idempotent: bool, symmetry_breaking: bool
self.add_propagator(
(
[*self.column(i, M_COLUMN), self.cell(i, j, M_COLOR), self.cell(j, i, M_COLOR)],
ALG_ELEMENT_LIV,
ALG_ELEMENT_LIV_ALLDIFFERENT,
[],
)
)
Expand All @@ -94,7 +98,7 @@ def __init__(self, kind: int, n: int, idempotent: bool, symmetry_breaking: bool
self.add_propagator(
(
[*self.column(i, M_COLUMN), self.cell(j, i, M_COLOR), self.cell(i, j, M_COLOR)],
ALG_ELEMENT_LIV,
ALG_ELEMENT_LIV_ALLDIFFERENT,
[],
)
)
Expand All @@ -104,25 +108,33 @@ def __init__(self, kind: int, n: int, idempotent: bool, symmetry_breaking: bool
self.add_propagator(
(
[*self.column(j, M_COLOR), self.cell(j, i, M_COLOR), self.cell(i, j, M_ROW)],
ALG_ELEMENT_LIV,
ALG_ELEMENT_LIV_ALLDIFFERENT,
[],
)
)
elif kind == 6: # (a∗b)∗b = a*(a*b)
# color[color[i, j], j] = color[i, color[i, j]]
ijj = self.add_variable((0, n - 1))
self.add_propagator(
([*self.column(j, M_COLOR), self.cell(i, j, M_COLOR), ijj], ALG_ELEMENT_LIV, [])
(
[*self.column(j, M_COLOR), self.cell(i, j, M_COLOR), ijj],
ALG_ELEMENT_LIV_ALLDIFFERENT,
[],
)
)
self.add_propagator(
([*self.row(i, M_COLOR), self.cell(i, j, M_COLOR), ijj], ALG_ELEMENT_LIV, [])
([*self.row(i, M_COLOR), self.cell(i, j, M_COLOR), ijj], ALG_ELEMENT_LIV_ALLDIFFERENT, [])
)
elif kind == 7: # (b∗a)∗b = a*(b*a)
# color[color[j, i], j] = color[i, color[j, i]]
jij = self.add_variable((0, n - 1))
self.add_propagator(
([*self.column(j, M_COLOR), self.cell(j, i, M_COLOR), jij], ALG_ELEMENT_LIV, [])
(
[*self.column(j, M_COLOR), self.cell(j, i, M_COLOR), jij],
ALG_ELEMENT_LIV_ALLDIFFERENT,
[],
)
)
self.add_propagator(
([*self.row(i, M_COLOR), self.cell(j, i, M_COLOR), jij], ALG_ELEMENT_LIV, [])
([*self.row(i, M_COLOR), self.cell(j, i, M_COLOR), jij], ALG_ELEMENT_LIV_ALLDIFFERENT, [])
)

0 comments on commit dfe50d2

Please sign in to comment.