Skip to content

Commit d51d0ca

Browse files
authored
Add usual constraints from XCSP3 (#29) (#30)
* Add usual constraints from XCSP3 (#29) * Fix AllDifferent with param too * AllDiff and AllEq * Cardinality * Channel * Circuit * Count * Cumulative * Element * Extension * Instantiation * Intention (DistDifferent) * Maximum * Minimum * MDD * NValues * No Overlap * Ordered * Regular * Sum * Test items and fixes * Fix test items * Update Project.toml * Update Project.toml
1 parent c045470 commit d51d0ca

33 files changed

+1936
-504
lines changed

.JuliaFormatter.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
style = "sciml"

Project.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
name = "CBLS"
22
uuid = "a3809bfe-37bb-4d48-a667-bac4c6be8d90"
33
authors = ["Jean-Francois Baffier"]
4-
version = "0.1.13"
4+
version = "0.2.0"
55

66
[deps]
7+
ConstraintCommons = "e37357d9-0691-492f-a822-e5ea6a920954"
78
ConstraintDomains = "5800fd60-8556-4464-8d61-84ebf7a0bedb"
89
Constraints = "30f324ab-b02d-43f0-b619-e131c61659f7"
910
Intervals = "d8418881-c3e1-53bb-8760-2df7ec849ed5"
1011
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
1112
Lazy = "50d2b5c4-7a5e-59d5-8109-a42b560f39c0"
1213
LocalSearchSolvers = "2b10edaa-728d-4283-ac71-07e312d6ccf3"
1314
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
15+
TestItems = "1c621080-faea-4a02-84b6-bbd5e436b8fe"
1416

1517
[compat]
1618
ConstraintDomains = "0.3"
@@ -23,7 +25,9 @@ MathOptInterface = "1"
2325
julia = "1.6"
2426

2527
[extras]
28+
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
2629
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
30+
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
2731

2832
[targets]
29-
test = ["Test"]
33+
test = ["Aqua", "Test", "TestItemRunner"]

docs/make.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
using CBLS
22
using Documenter
33

4-
DocMeta.setdocmeta!(CBLS, :DocTestSetup, :(using CBLS); recursive=true)
4+
DocMeta.setdocmeta!(CBLS, :DocTestSetup, :(using CBLS); recursive = true)
55

66
makedocs(;
7-
modules=[CBLS],
8-
authors="Jean-Francois Baffier",
9-
repo="https://github.com/JuliaConstraints/CBLS.jl/blob/{commit}{path}#{line}",
10-
sitename="CBLS.jl",
11-
format=Documenter.HTML(;
12-
prettyurls=get(ENV, "CI", "false") == "true",
13-
canonical="https://JuliaConstraints.github.io/CBLS.jl",
14-
assets=String[],
7+
modules = [CBLS],
8+
authors = "Jean-Francois Baffier",
9+
repo = "https://github.com/JuliaConstraints/CBLS.jl/blob/{commit}{path}#{line}",
10+
sitename = "CBLS.jl",
11+
format = Documenter.HTML(;
12+
prettyurls = get(ENV, "CI", "false") == "true",
13+
canonical = "https://JuliaConstraints.github.io/CBLS.jl",
14+
assets = String[]
1515
),
16-
pages=[
17-
"Home" => "index.md",
18-
],
16+
pages = [
17+
"Home" => "index.md"
18+
]
1919
)
2020

2121
deploydocs(;
22-
repo="github.com/JuliaConstraints/CBLS.jl",
23-
devbranch="main",
22+
repo = "github.com/JuliaConstraints/CBLS.jl",
23+
devbranch = "main"
2424
)

src/CBLS.jl

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
module CBLS
22

3-
using Constraints
3+
using ConstraintCommons
44
using ConstraintDomains
5+
using Constraints
56
using Intervals
67
using JuMP
78
using Lazy
89
using LocalSearchSolvers
910
using MathOptInterface
11+
using TestItems
1012

1113
# Const
1214
const LS = LocalSearchSolvers
@@ -28,19 +30,27 @@ const VAR_TYPES = Union{MOI.ZeroOne, MOI.Integer}
2830
export DiscreteSet
2931

3032
# Export: Constraints
33+
export Error, Predicate
34+
3135
export AllDifferent
3236
export AllEqual
33-
export AllEqualParam
34-
export AlwaysTrue
35-
export DistDifferent
36-
export Eq
37-
export Error
38-
export LessThanParam
39-
export MinusEqualParam
37+
export Cardinality, CardinalityClosed, CardinalityOpen
38+
export Channel
39+
export Circuit
40+
export Count, AtLeast, AtMost, Exactly
41+
export Cumulative
42+
export Element
43+
export Extension, Supports, Conflicts
44+
export Instantiation
45+
export DistDifferent # Implementation of an intensional constraint
46+
export Maximum
47+
export MDDConstraint
48+
export Minimum
49+
export NValues
50+
export NoOverlap, NoOverlapNoZero, NoOverlapWithZero
4051
export Ordered
41-
export Predicate
42-
export SequentialTasks
43-
export SumEqualParam
52+
export Regular
53+
export Sum
4454

4555
#Export: Scalar objective function
4656
export ScalarFunction
@@ -49,7 +59,29 @@ export ScalarFunction
4959
include("MOI_wrapper.jl")
5060
include("attributes.jl")
5161
include("variables.jl")
62+
63+
## Constraints
5264
include("constraints.jl")
65+
include("constraints/all_different.jl")
66+
include("constraints/all_equal.jl")
67+
include("constraints/cardinality.jl")
68+
include("constraints/channel.jl")
69+
include("constraints/circuit.jl")
70+
include("constraints/count.jl")
71+
include("constraints/cumulative.jl")
72+
include("constraints/element.jl")
73+
include("constraints/extension.jl")
74+
include("constraints/instantiation.jl")
75+
include("constraints/intention.jl")
76+
include("constraints/maximum.jl")
77+
include("constraints/mdd.jl")
78+
include("constraints/minimum.jl")
79+
include("constraints/n_values.jl")
80+
include("constraints/no_overlap.jl")
81+
include("constraints/ordered.jl")
82+
include("constraints/regular.jl")
83+
include("constraints/sum.jl")
84+
5385
include("objectives.jl")
5486
include("results.jl")
5587

src/MOI_wrapper.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ DOCSTRING
99
- `set`: DESCRIPTION
1010
"""
1111
function JuMP.build_variable(
12-
::Function,
13-
info::JuMP.VariableInfo,
14-
set::T,
15-
) where {T<:MOI.AbstractScalarSet}
12+
::Function,
13+
info::JuMP.VariableInfo,
14+
set::T
15+
) where {T <: MOI.AbstractScalarSet}
1616
return JuMP.VariableConstrainedOnCreation(JuMP.ScalarVariable(info), set)
1717
end
1818

@@ -42,7 +42,7 @@ function Optimizer(model = model(); options = Options())
4242
solver(model, options = options),
4343
Set{Int}(),
4444
Set{Int}()
45-
)
45+
)
4646
end
4747

4848
# forward functions from Solver
@@ -102,7 +102,7 @@ struct DiscreteSet{T <: Number} <: MOI.AbstractScalarSet
102102
values::Vector{T}
103103
end
104104
DiscreteSet(values) = DiscreteSet(collect(values))
105-
DiscreteSet(values::T...) where {T<:Number} = DiscreteSet(collect(values))
105+
DiscreteSet(values::T...) where {T <: Number} = DiscreteSet(collect(values))
106106

107107
"""
108108
Base.copy(set::DiscreteSet) = begin
@@ -118,7 +118,9 @@ DOCSTRING
118118
"""
119119
MOI.empty!(opt) = empty!(opt)
120120

121-
122121
function MOI.is_valid(optimizer::Optimizer, index::CI{VI, MOI.Integer})
123122
return index.value optimizer.int_vars
124123
end
124+
125+
Base.copy(op::F) where {F <: Function} = op
126+
Base.copy(::Nothing) = nothing

src/attributes.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ MOI.supports(::Optimizer, ::MOI.NumberOfThreads) = true
88
MOI.set(model::Optimizer, ::MOI.TimeLimitSec, value::Union{Nothing,Float64})
99
Set the time limit
1010
"""
11-
function MOI.set(model::Optimizer, ::MOI.TimeLimitSec, value::Union{Nothing,Float64})
11+
function MOI.set(model::Optimizer, ::MOI.TimeLimitSec, value::Union{Nothing, Float64})
1212
set_option!(model, "time_limit", isnothing(value) ? Inf : value)
1313
end
1414
function MOI.get(model::Optimizer, ::MOI.TimeLimitSec)
@@ -20,14 +20,14 @@ end
2020
MOI.set(model::Optimizer, p::MOI.RawOptimizerAttribute, value)
2121
Set a RawOptimizerAttribute to `value`
2222
"""
23-
MOI.set(model::Optimizer, p::MOI.RawOptimizerAttribute, value) = set_option!(model, p.name, value)
23+
MOI.set(model::Optimizer, p::MOI.RawOptimizerAttribute, value) = set_option!(
24+
model, p.name, value)
2425
MOI.get(model::Optimizer, p::MOI.RawOptimizerAttribute) = get_option(model, p.name)
2526

26-
2727
function MOI.set(model::Optimizer, ::MOI.NumberOfThreads, value)
2828
set_option!(model, "threads", isnothing(value) ? typemax(0) : value)
2929
end
3030
function MOI.get(model::Optimizer, ::MOI.NumberOfThreads)
3131
nt = get_option(model, "threads")
3232
return nt == typemax(0) ? nothing : nt
33-
end
33+
end

0 commit comments

Comments
 (0)