Skip to content

Commit 2fb38a2

Browse files
authored
Use MOI.CountDistinct (#38)
1 parent 71ca3c7 commit 2fb38a2

File tree

5 files changed

+7
-36
lines changed

5 files changed

+7
-36
lines changed

docs/src/mappings/hakank.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ All the constraints that are currently defined in [hakank's constraints_utils.jl
88
* `decreasing_strict`: `Strictly(Decreasing)`
99
* `all_different_except_c`: `AllDifferentExceptConstants`
1010
* `count_ctr`: `Count` (except for operators)
11-
* `count_ctr2`: `CountDistinct` (except for operators)
11+
* `count_ctr2`: `MOI.CountDistinct` (except for operators)
1212
* `global_cardinality_count`: `Count`
1313
* `either_eq`: `Disjunction`
1414
* `is_member_of`: `Domain` and `Membership`
@@ -29,4 +29,4 @@ All the constraints that are currently defined in [hakank's constraints_utils.jl
2929
* `lex_less_eq`: `LexicographicallyLessThan`
3030
* `among`: `Count`
3131

32-
Functions: TODO
32+
Functions: TODO

docs/src/reference/sets.md

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ KnapsackValueType
6464
```@docs
6565
Count
6666
CountCompare
67-
CountDistinct
6867
```
6968

7069
### Global cardinality

src/Test/test_countdistinct.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function test_countdistinct_vectorofvariables(
44
) where {T <: Real}
55
@MOIT.requires MOI.supports_constraint(model, MOI.VariableIndex, MOI.Integer) # x1, x2, x3, x4
66
@MOIT.requires MOI.supports_constraint(model, MOI.VariableIndex, MOI.EqualTo{T}) # c1, c2, c3
7-
@MOIT.requires MOI.supports_constraint(model, MOI.VectorOfVariables, CP.CountDistinct) # c4
7+
@MOIT.requires MOI.supports_constraint(model, MOI.VectorOfVariables, MOI.CountDistinct) # c4
88

99
x1, _ = MOI.add_constrained_variable(model, MOI.Integer())
1010
x2, _ = MOI.add_constrained_variable(model, MOI.Integer())
@@ -15,7 +15,7 @@ function test_countdistinct_vectorofvariables(
1515
c2 = MOI.add_constraint(model, x2, MOI.EqualTo(1))
1616
c3 = MOI.add_constraint(model, x3, MOI.EqualTo(2))
1717

18-
c4 = MOI.add_constraint(model, MOI.VectorOfVariables([x4, x1, x2, x3]), CP.CountDistinct(3))
18+
c4 = MOI.add_constraint(model, MOI.VectorOfVariables([x4, x1, x2, x3]), MOI.CountDistinct(4))
1919

2020
@test MOI.is_valid(model, x1)
2121
@test MOI.is_valid(model, x2)
@@ -57,7 +57,7 @@ function test_countdistinct_vectoraffinefunction(
5757
) where {T <: Real}
5858
@MOIT.requires MOI.supports_constraint(model, MOI.VariableIndex, MOI.Integer) # x1, x2, x3, x4
5959
@MOIT.requires MOI.supports_constraint(model, MOI.ScalarAffineFunction{T}, MOI.EqualTo{T}) # c1, c2, c3
60-
@MOIT.requires MOI.supports_constraint(model, MOI.VectorAffineFunction{T}, CP.CountDistinct) # c4
60+
@MOIT.requires MOI.supports_constraint(model, MOI.VectorAffineFunction{T}, MOI.CountDistinct) # c4
6161

6262
x1, _ = MOI.add_constrained_variable(model, MOI.Integer())
6363
x2, _ = MOI.add_constrained_variable(model, MOI.Integer())
@@ -68,7 +68,7 @@ function test_countdistinct_vectoraffinefunction(
6868
c2 = MOI.add_constraint(model, one(T) * x2, MOI.EqualTo(1))
6969
c3 = MOI.add_constraint(model, one(T) * x3, MOI.EqualTo(2))
7070

71-
c4 = MOI.add_constraint(model, MOIU.vectorize(one(T) .* [x4, x1, x2, x3]), CP.CountDistinct(3))
71+
c4 = MOI.add_constraint(model, MOIU.vectorize(one(T) .* [x4, x1, x2, x3]), MOI.CountDistinct(4))
7272

7373
@test MOI.is_valid(model, x1)
7474
@test MOI.is_valid(model, x2)

src/sets_count.jl

+1-25
Original file line numberDiff line numberDiff line change
@@ -253,31 +253,7 @@ end
253253

254254
MOI.dimension(set::CountCompare) = 2 * set.dimension + 1
255255

256-
"""
257-
CountDistinct(dimension::Int)
258-
259-
The first variable in the set is forced to be the number of distinct values in
260-
the rest of the expressions.
261-
262-
This is a relaxed version of `MOI.AllDifferent`; it encodes an `MOI.AllDifferent`
263-
constraint when the first variable is the number of variables in the set.
264-
265-
Also called `nvalues`.
266-
267-
## Example
268-
269-
[x, y, z] in CountDistinct(3)
270-
# x = 1 if y == z, x = 2 if y != z
271-
"""
272-
struct CountDistinct <: MOI.AbstractVectorSet
273-
dimension::Int
274-
end
275-
276-
MOI.dimension(set::CountDistinct) = set.dimension + 1
277-
278256
# isbits types, nothing to copy
279-
function copy(
280-
set::Union{CountCompare, CountDistinct},
281-
)
257+
function copy(set::CountCompare)
282258
return set
283259
end

test/sets.jl

-4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@
2424
# Just a dimension.
2525
@testset "$(S)" for S in [
2626
CP.AllEqual,
27-
MOI.AllDifferent,
2827
CP.SymmetricAllDifferent,
2928
CP.Membership,
3029
CP.ElementVariableArray,
31-
CP.CountDistinct,
3230
CP.Inverse,
3331
CP.Contiguity,
3432
CP.LexicographicallyLessThan,
@@ -54,7 +52,6 @@
5452

5553
if S in [
5654
CP.AllEqual,
57-
MOI.AllDifferent,
5855
CP.SymmetricAllDifferent,
5956
CP.Membership,
6057
CP.Contiguity,
@@ -64,7 +61,6 @@
6461
@test MOI.dimension(S(2)) == 2
6562
@test MOI.dimension(S(3)) == 3
6663
elseif S in [
67-
CP.CountDistinct,
6864
CP.MinimumAmong,
6965
CP.MaximumAmong,
7066
CP.ArgumentMinimumAmong,

0 commit comments

Comments
 (0)