Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add usual constraints from XCSP3 (#29) #30

Merged
merged 3 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
style = "sciml"
8 changes: 6 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
name = "CBLS"
uuid = "a3809bfe-37bb-4d48-a667-bac4c6be8d90"
authors = ["Jean-Francois Baffier"]
version = "0.1.13"
version = "0.2.0"

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

[compat]
ConstraintDomains = "0.3"
Expand All @@ -23,7 +25,9 @@ MathOptInterface = "1"
julia = "1.6"

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

[targets]
test = ["Test"]
test = ["Aqua", "Test", "TestItemRunner"]
28 changes: 14 additions & 14 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
using CBLS
using Documenter

DocMeta.setdocmeta!(CBLS, :DocTestSetup, :(using CBLS); recursive=true)
DocMeta.setdocmeta!(CBLS, :DocTestSetup, :(using CBLS); recursive = true)

makedocs(;
modules=[CBLS],
authors="Jean-Francois Baffier",
repo="https://github.com/JuliaConstraints/CBLS.jl/blob/{commit}{path}#{line}",
sitename="CBLS.jl",
format=Documenter.HTML(;
prettyurls=get(ENV, "CI", "false") == "true",
canonical="https://JuliaConstraints.github.io/CBLS.jl",
assets=String[],
modules = [CBLS],
authors = "Jean-Francois Baffier",
repo = "https://github.com/JuliaConstraints/CBLS.jl/blob/{commit}{path}#{line}",
sitename = "CBLS.jl",
format = Documenter.HTML(;
prettyurls = get(ENV, "CI", "false") == "true",
canonical = "https://JuliaConstraints.github.io/CBLS.jl",
assets = String[]
),
pages=[
"Home" => "index.md",
],
pages = [
"Home" => "index.md"
]
)

deploydocs(;
repo="github.com/JuliaConstraints/CBLS.jl",
devbranch="main",
repo = "github.com/JuliaConstraints/CBLS.jl",
devbranch = "main"
)
54 changes: 43 additions & 11 deletions src/CBLS.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
module CBLS

using Constraints
using ConstraintCommons
using ConstraintDomains
using Constraints
using Intervals
using JuMP
using Lazy
using LocalSearchSolvers
using MathOptInterface
using TestItems

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

# Export: Constraints
export Error, Predicate

export AllDifferent
export AllEqual
export AllEqualParam
export AlwaysTrue
export DistDifferent
export Eq
export Error
export LessThanParam
export MinusEqualParam
export Cardinality, CardinalityClosed, CardinalityOpen
export Channel
export Circuit
export Count, AtLeast, AtMost, Exactly
export Cumulative
export Element
export Extension, Supports, Conflicts
export Instantiation
export DistDifferent # Implementation of an intensional constraint
export Maximum
export MDDConstraint
export Minimum
export NValues
export NoOverlap, NoOverlapNoZero, NoOverlapWithZero
export Ordered
export Predicate
export SequentialTasks
export SumEqualParam
export Regular
export Sum

#Export: Scalar objective function
export ScalarFunction
Expand All @@ -49,7 +59,29 @@ export ScalarFunction
include("MOI_wrapper.jl")
include("attributes.jl")
include("variables.jl")

## Constraints
include("constraints.jl")
include("constraints/all_different.jl")
include("constraints/all_equal.jl")
include("constraints/cardinality.jl")
include("constraints/channel.jl")
include("constraints/circuit.jl")
include("constraints/count.jl")
include("constraints/cumulative.jl")
include("constraints/element.jl")
include("constraints/extension.jl")
include("constraints/instantiation.jl")
include("constraints/intention.jl")
include("constraints/maximum.jl")
include("constraints/mdd.jl")
include("constraints/minimum.jl")
include("constraints/n_values.jl")
include("constraints/no_overlap.jl")
include("constraints/ordered.jl")
include("constraints/regular.jl")
include("constraints/sum.jl")

include("objectives.jl")
include("results.jl")

Expand Down
16 changes: 9 additions & 7 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ DOCSTRING
- `set`: DESCRIPTION
"""
function JuMP.build_variable(
::Function,
info::JuMP.VariableInfo,
set::T,
) where {T<:MOI.AbstractScalarSet}
::Function,
info::JuMP.VariableInfo,
set::T
) where {T <: MOI.AbstractScalarSet}
return JuMP.VariableConstrainedOnCreation(JuMP.ScalarVariable(info), set)
end

Expand Down Expand Up @@ -42,7 +42,7 @@ function Optimizer(model = model(); options = Options())
solver(model, options = options),
Set{Int}(),
Set{Int}()
)
)
end

# forward functions from Solver
Expand Down Expand Up @@ -102,7 +102,7 @@ struct DiscreteSet{T <: Number} <: MOI.AbstractScalarSet
values::Vector{T}
end
DiscreteSet(values) = DiscreteSet(collect(values))
DiscreteSet(values::T...) where {T<:Number} = DiscreteSet(collect(values))
DiscreteSet(values::T...) where {T <: Number} = DiscreteSet(collect(values))

"""
Base.copy(set::DiscreteSet) = begin
Expand All @@ -118,7 +118,9 @@ DOCSTRING
"""
MOI.empty!(opt) = empty!(opt)


function MOI.is_valid(optimizer::Optimizer, index::CI{VI, MOI.Integer})
return index.value ∈ optimizer.int_vars
end

Base.copy(op::F) where {F <: Function} = op
Base.copy(::Nothing) = nothing
8 changes: 4 additions & 4 deletions src/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ MOI.supports(::Optimizer, ::MOI.NumberOfThreads) = true
MOI.set(model::Optimizer, ::MOI.TimeLimitSec, value::Union{Nothing,Float64})
Set the time limit
"""
function MOI.set(model::Optimizer, ::MOI.TimeLimitSec, value::Union{Nothing,Float64})
function MOI.set(model::Optimizer, ::MOI.TimeLimitSec, value::Union{Nothing, Float64})
set_option!(model, "time_limit", isnothing(value) ? Inf : value)
end
function MOI.get(model::Optimizer, ::MOI.TimeLimitSec)
Expand All @@ -20,14 +20,14 @@ end
MOI.set(model::Optimizer, p::MOI.RawOptimizerAttribute, value)
Set a RawOptimizerAttribute to `value`
"""
MOI.set(model::Optimizer, p::MOI.RawOptimizerAttribute, value) = set_option!(model, p.name, value)
MOI.set(model::Optimizer, p::MOI.RawOptimizerAttribute, value) = set_option!(
model, p.name, value)
MOI.get(model::Optimizer, p::MOI.RawOptimizerAttribute) = get_option(model, p.name)


function MOI.set(model::Optimizer, ::MOI.NumberOfThreads, value)
set_option!(model, "threads", isnothing(value) ? typemax(0) : value)
end
function MOI.get(model::Optimizer, ::MOI.NumberOfThreads)
nt = get_option(model, "threads")
return nt == typemax(0) ? nothing : nt
end
end
Loading
Loading