Skip to content

Commit 9830f7d

Browse files
authored
Constraint programming extensions (#270)
* CPE for AllDifferent and AllEqual * deprecation warning for AllDifferentSet and EqualSet * v0.7
1 parent 63af545 commit 9830f7d

Some content is hidden

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

50 files changed

+243
-710
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ literature/
88
extra/
99
test/logs/
1010
docs/build/
11+
docs/Manifest.toml
1112
benchmark/**/results
1213
instances
1314
**/nohup.out

CHANGELOG.md

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
# ConstrainSolver.jl - Changelog
22

3+
## v0.7.0 (7th of August 2021)
4+
- Using [ConstraintProgrammingExtensions.jl](https://github.com/dourouc05/ConstraintProgrammingExtensions.jl)
5+
- `AllDifferent` instead of `AllDifferentSet`
6+
- `AllEqual` instead of `EqualSet`
7+
38
## v0.6.10 (26th of July 2021)
49
- Allow variables as constraint like `a || !b` instead of `a == 1 || b == 0`. [PR #267](https://github.com/Wikunia/ConstraintSolver.jl/pull/267)
510
- **Attention** Does not check if variable is a binary variable
611
- Support for indicator/reified in indicator/reified (without bridges) [PR #251](https://github.com/Wikunia/ConstraintSolver.jl/pull/251)
712
- Support for VectorAffineFunction in TableSet/AllDifferentSet
8-
- i.e `[x[i]+i for i in 1:n] in CS.AllDifferentSet()`
13+
- i.e `[x[i]+i for i in 1:n] in CS.AllDifferent()`
914
- `[x,y,10] in CS.TableSet(...)`
1015
- see [issue #235](https://github.com/Wikunia/ConstraintSolver.jl/issues/235) for in-depth examples
1116

@@ -32,11 +37,11 @@
3237
- Bugfix in reified `still_feasible` when setting to inactive
3338
- Bugfix in alldifferent constraint when there is a gap in the values
3439
- Support for `And` constraints in the inner constraints of `Indicator` and `Reified`:
35-
i.e `b := { sum(x) >= 10 && x in CS.AllDifferentSet() }`
40+
i.e `b := { sum(x) >= 10 && x in CS.AllDifferent() }`
3641
- Support for `Or` constraints in the inner constraints of `Indicator` and `Reified`:
37-
i.e `b := { sum(x) >= 10 || x in CS.AllDifferentSet() }`
42+
i.e `b := { sum(x) >= 10 || x in CS.AllDifferent() }`
3843
- Support for `&&` and `||` outside of `Indicator` and `Reified`
39-
- i.e `sum(x) >= 10 || x in CS.AllDifferentSet()`
44+
- i.e `sum(x) >= 10 || x in CS.AllDifferent()`
4045
- Basic support for `Indicator` inside of reified:
4146
- i.e `@constraint(model, b1 := {b2 => { v == 1 }})`
4247
- currently lacks support for bridges such that `v > 1` in the inner constraint will fail
@@ -120,17 +125,17 @@
120125
## v0.1.7 (22nd of May 2020)
121126
- Better feasibility and pruning in `==`
122127
- **Bugfixes:**
123-
- Correct set of change ptr in `EqualSet` for faster/correct pruning
128+
- Correct set of change ptr in `AllEqual` for faster/correct pruning
124129
- Call to `isapprox_discrete` in `eq_sum`
125130
- Fixed threshold rounding
126131

127132
## v0.1.6 (11th of May 2020)
128133
- Reduction of memory allocations in `TableConstraint`
129-
- Pruning in `EqualSet`
134+
- Pruning in `AllEqual`
130135

131136
## v0.1.5 (6th of May 2020)
132137
- **Bugfixes:**
133-
- EqualSet feasibility: Check if other vars have value + no memory allocation
138+
- AllEqual feasibility: Check if other vars have value + no memory allocation
134139
- Call `call_finished_pruning!(com)` after second `prune!` before backtracking
135140

136141
## v0.1.4 (6th of May 2020)

Project.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
name = "ConstraintSolver"
22
uuid = "e0e52ebd-5523-408d-9ca3-7641f1cd1405"
33
authors = ["Ole Kröger <[email protected]>"]
4-
version = "0.6.10"
4+
version = "0.7.0"
55

66
[deps]
7+
ConstraintProgrammingExtensions = "b65d079e-ed98-51d9-b0db-edee61a5c5f8"
78
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
89
Formatting = "59287772-0a20-5a39-b81b-1366585eb4c0"
910
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
@@ -17,6 +18,7 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
1718
StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
1819

1920
[compat]
21+
ConstraintProgrammingExtensions = "^0.3"
2022
DataStructures = "~0.11, ~0.12, ~0.13, ~0.14, ~0.15, ~0.16, ~0.17, ~0.18"
2123
Formatting = "^0.4.1"
2224
JSON = "~0.18, ~0.19, ~0.20, ~0.21"

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ for r=1:9, c=1:9
5353
end
5454

5555
for rc = 1:9
56-
@constraint(m, x[rc,:] in CS.AllDifferentSet())
57-
@constraint(m, x[:,rc] in CS.AllDifferentSet())
56+
@constraint(m, x[rc,:] in CS.AllDifferent())
57+
@constraint(m, x[:,rc] in CS.AllDifferent())
5858
end
5959

6060
for br=0:2
6161
for bc=0:2
62-
@constraint(m, vec(x[br*3+1:(br+1)*3,bc*3+1:(bc+1)*3]) in CS.AllDifferentSet())
62+
@constraint(m, vec(x[br*3+1:(br+1)*3,bc*3+1:(bc+1)*3]) in CS.AllDifferent())
6363
end
6464
end
6565

benchmark/eternity/benchmark.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function solve_eternity(
7373
@variable(m, b[1:height, 1:width], Bin)
7474
end
7575

76-
@constraint(m, p[:] in CS.AllDifferentSet())
76+
@constraint(m, p[:] in CS.AllDifferent())
7777
for i in 1:height, j in 1:width
7878
if indicator
7979
@constraint(

benchmark/eternity/cs.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function main(pname; time_limit = 1800)
4646
@variable(m, 0 <= pd[1:height, 1:width] <= ncolors, Int)
4747
@variable(m, 0 <= pl[1:height, 1:width] <= ncolors, Int)
4848

49-
@constraint(m, p[:] in CS.AllDifferentSet())
49+
@constraint(m, p[:] in CS.AllDifferent())
5050
for i in 1:height, j in 1:width
5151
@constraint(
5252
m,

benchmark/graph_color/benchmark.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ function solve_us_graph_coloring(; num_colors = 8, equality = false, branch_stra
166166
@constraint(m, south_carolina != georgia)
167167
@constraint(m, georgia != florida)
168168

169-
# test for EqualSet constraint
169+
# test for AllEqual constraint
170170
if equality
171-
@constraint(m, [california, new_york, florida] in CS.EqualSet())
172-
@constraint(m, [maryland, alabama, wisconsin, south_carolina] in CS.EqualSet())
171+
@constraint(m, [california, new_york, florida] in CS.AllEqual())
172+
@constraint(m, [maryland, alabama, wisconsin, south_carolina] in CS.AllEqual())
173173
end
174174

175175
@constraint(m, max_color .>= states)

benchmark/killer_sudoku/benchmark.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function solve_killer_sudoku(filename; special = false, branch_strategy=:Auto)
3434
MOI.add_constraint(
3535
m,
3636
[x[ind[1]][ind[2]][1] for ind in s.indices],
37-
CS.AllDifferentSetInternal(length(s.indices)),
37+
CS.CPE.AllDifferent(length(s.indices)),
3838
)
3939
end
4040
end
@@ -44,14 +44,14 @@ function solve_killer_sudoku(filename; special = false, branch_strategy=:Auto)
4444
MOI.add_constraint(
4545
m,
4646
MOI.VectorOfVariables([x[r][c][1] for c in 1:9]),
47-
CS.AllDifferentSetInternal(9),
47+
CS.CPE.AllDifferent(9),
4848
)
4949
end
5050
for c in 1:9
5151
MOI.add_constraint(
5252
m,
5353
MOI.VectorOfVariables([x[r][c][1] for r in 1:9]),
54-
CS.AllDifferentSetInternal(9),
54+
CS.CPE.AllDifferent(9),
5555
)
5656
end
5757
variables = [MOI.VariableIndex(0) for _ in 1:9]
@@ -62,7 +62,7 @@ function solve_killer_sudoku(filename; special = false, branch_strategy=:Auto)
6262
variables[variables_i] = x[i][j][1]
6363
variables_i += 1
6464
end
65-
MOI.add_constraint(m, variables, CS.AllDifferentSetInternal(9))
65+
MOI.add_constraint(m, variables, CS.CPE.AllDifferent(9))
6666
end
6767
end
6868

benchmark/killer_sudoku/cs.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function solve_all(filenames; benchmark = false, single_times = true)
4343
0.0,
4444
)
4545
MOI.add_constraint(m, saf, MOI.EqualTo(convert(Float64, s.result)))
46-
# MOI.add_constraint(m, [x[ind[1]][ind[2]][1] for ind in s.indices], CS.AllDifferentSetInternal(length(s.indices)))
46+
# MOI.add_constraint(m, [x[ind[1]][ind[2]][1] for ind in s.indices], CS.CPE.AllDifferent(length(s.indices)))
4747
end
4848

4949
# sudoku constraints

benchmark/sudoku/benchmark.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ function solve_sudoku(grid)
4242
MOI.add_constraint(
4343
m,
4444
MOI.VectorOfVariables([x[r][c][1] for c in 1:side_len]),
45-
CS.AllDifferentSetInternal(side_len),
45+
CS.CPE.AllDifferent(side_len),
4646
)
4747
end
4848
for c in 1:side_len
4949
MOI.add_constraint(
5050
m,
5151
MOI.VectorOfVariables([x[r][c][1] for r in 1:side_len]),
52-
CS.AllDifferentSetInternal(side_len),
52+
CS.CPE.AllDifferent(side_len),
5353
)
5454
end
5555
variables = [MOI.VariableIndex(0) for _ in 1:side_len]
@@ -60,7 +60,7 @@ function solve_sudoku(grid)
6060
variables[variables_i] = x[i][j][1]
6161
variables_i += 1
6262
end
63-
MOI.add_constraint(m, variables, CS.AllDifferentSetInternal(side_len))
63+
MOI.add_constraint(m, variables, CS.CPE.AllDifferent(side_len))
6464
end
6565
end
6666

0 commit comments

Comments
 (0)