Skip to content

Commit

Permalink
Basic update for MOI/JuMP v1 (#23)
Browse files Browse the repository at this point in the history
* Basic update for MOI/JuMP v1

* New version. Update CI.
  • Loading branch information
Azzaare authored Oct 8, 2023
1 parent 5b7f0a6 commit c045470
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 118 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: CI
on:
- push
- pull_request
jobs:
test:
Expand All @@ -10,7 +9,7 @@ jobs:
fail-fast: false
matrix:
version:
- "^1.6.0-0"
- "1.9"
- 'nightly'
os:
- ubuntu-latest
Expand Down Expand Up @@ -57,7 +56,7 @@ jobs:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: "^1.6.0-0"
version: "1"
- run: |
julia --project=docs -e '
using Pkg
Expand Down
14 changes: 8 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
name = "CBLS"
uuid = "a3809bfe-37bb-4d48-a667-bac4c6be8d90"
authors = ["Jean-Francois Baffier"]
version = "0.1.12"
version = "0.1.13"

[deps]
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"

[compat]
ConstraintDomains = "0.2"
Constraints = "0.2"
JuMP = "0.21"
ConstraintDomains = "0.3"
Constraints = "0.5"
Intervals = "1"
JuMP = "1"
Lazy = "0.15"
LocalSearchSolvers = "0.3"
MathOptInterface = "0.9"
LocalSearchSolvers = "0.4"
MathOptInterface = "1"
julia = "1.6"

[extras]
Expand Down
3 changes: 1 addition & 2 deletions src/CBLS.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module CBLS

using Constraints: sequential_tasks
using Constraints
using ConstraintDomains
using Intervals
using JuMP
using Lazy
using LocalSearchSolvers
Expand All @@ -14,7 +14,6 @@ const MOI = MathOptInterface
const MOIU = MOI.Utilities

# MOI functions
const SVF = MOI.SingleVariable
const VOV = MOI.VectorOfVariables
const OF = MOI.ObjectiveFunction

Expand Down
8 changes: 4 additions & 4 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ MOI.is_empty(model::Optimizer) = LS._is_empty(model.solver)
"""
Copy constructor for the optimizer
"""
MOIU.supports_default_copy_to(::Optimizer, copy_names::Bool) = false
function MOI.copy_to(model::Optimizer, src::MOI.ModelLike; kws...)
return MOIU.automatic_copy_to(model, src; kws...)
MOI.supports_incremental_interface(::Optimizer) = true
function MOI.copy_to(model::Optimizer, src::MOI.ModelLike)
return MOIU.default_copy_to(model, src)
end

"""
Expand Down Expand Up @@ -119,6 +119,6 @@ DOCSTRING
MOI.empty!(opt) = empty!(opt)


function MOI.is_valid(optimizer::Optimizer, index::CI{SVF, MOI.Integer})
function MOI.is_valid(optimizer::Optimizer, index::CI{VI, MOI.Integer})
return index.value optimizer.int_vars
end
10 changes: 5 additions & 5 deletions src/attributes.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
struct PrintLevel <: MOI.AbstractOptimizerAttribute end

MOI.supports(::Optimizer, ::MOI.RawParameter) = true
MOI.supports(::Optimizer, ::MOI.RawOptimizerAttribute) = true
MOI.supports(::Optimizer, ::MOI.TimeLimitSec) = true
MOI.supports(::Optimizer, ::MOI.NumberOfThreads) = true

Expand All @@ -17,11 +17,11 @@ function MOI.get(model::Optimizer, ::MOI.TimeLimitSec)
end

"""
MOI.set(model::Optimizer, p::MOI.RawParameter, value)
Set a RawParameter to `value`
MOI.set(model::Optimizer, p::MOI.RawOptimizerAttribute, value)
Set a RawOptimizerAttribute to `value`
"""
MOI.set(model::Optimizer, p::MOI.RawParameter, value) = set_option!(model, p.name, value)
MOI.get(model::Optimizer, p::MOI.RawParameter) = get_option(model, p.name)
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)
Expand Down
75 changes: 32 additions & 43 deletions src/constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,9 @@ struct MOIAllDifferent <: MOI.AbstractVectorSet
end
MOI.supports_constraint(::Optimizer, ::Type{VOV}, ::Type{MOIAllDifferent}) = true
function MOI.add_constraint(optimizer::Optimizer, vars::MOI.VectorOfVariables, ::MOIAllDifferent)
max_dom_size = max_domains_size(optimizer, map(x -> x.value, vars.variables))
e = (x; param=nothing, dom_size=max_dom_size) -> error_f(
usual_constraints[:all_different])(x; param=param, dom_size=dom_size
)
#max_dom_size = max_domains_size(optimizer, map(x -> x.value, vars.variables))
e = (x; kargs...) -> error_f(
USUAL_CONSTRAINTS[:all_different])(x; kargs...)
cidx = constraint!(optimizer, e, map(x -> x.value, vars.variables))
return CI{VOV, MOIAllDifferent}(cidx)
end
Expand Down Expand Up @@ -159,10 +158,9 @@ struct MOIAllEqual <: MOI.AbstractVectorSet
end
MOI.supports_constraint(::Optimizer, ::Type{VOV}, ::Type{MOIAllEqual}) = true
function MOI.add_constraint(optimizer::Optimizer, vars::MOI.VectorOfVariables, ::MOIAllEqual)
max_dom_size = max_domains_size(optimizer, map(x -> x.value, vars.variables))
e = (x; param=nothing, dom_size=max_dom_size) -> error_f(
usual_constraints[:all_equal])(x; param=param, dom_size=dom_size
)
#max_dom_size = max_domains_size(optimizer, map(x -> x.value, vars.variables))
e = (x; kargs...) -> error_f(
USUAL_CONSTRAINTS[:all_equal])(x; kargs...)
cidx = constraint!(optimizer, e, map(x -> x.value, vars.variables))
return CI{VOV, MOIAllEqual}(cidx)
end
Expand Down Expand Up @@ -191,10 +189,9 @@ struct MOIEq <: MOI.AbstractVectorSet
end
MOI.supports_constraint(::Optimizer, ::Type{VOV}, ::Type{MOIEq}) = true
function MOI.add_constraint(optimizer::Optimizer, vars::MOI.VectorOfVariables, ::MOIEq)
max_dom_size = max_domains_size(optimizer, map(x -> x.value, vars.variables))
e = (x; param=nothing, dom_size=max_dom_size) -> error_f(
usual_constraints[:eq])(x; param=param, dom_size=dom_size
)
#max_dom_size = max_domains_size(optimizer, map(x -> x.value, vars.variables))
e = (x; kargs...) -> error_f(
USUAL_CONSTRAINTS[:eq])(x; kargs...)
cidx = constraint!(optimizer, e, map(x -> x.value, vars.variables))
return CI{VOV, MOIEq}(cidx)
end
Expand Down Expand Up @@ -223,10 +220,8 @@ struct MOIAlwaysTrue <: MOI.AbstractVectorSet
end
MOI.supports_constraint(::Optimizer, ::Type{VOV}, ::Type{MOIAlwaysTrue}) = true
function MOI.add_constraint(optimizer::Optimizer, vars::MOI.VectorOfVariables, ::MOIAlwaysTrue)
max_dom_size = max_domains_size(optimizer, map(x -> x.value, vars.variables))
e = (x; param=nothing, dom_size=max_dom_size) -> error_f(
usual_constraints[:always_true])(x; param=param, dom_size=dom_size
)
#max_dom_size = max_domains_size(optimizer, map(x -> x.value, vars.variables))
e = (x; kargs...) -> error_f(USUAL_CONSTRAINTS[:always_true])(x; kargs...)
cidx = constraint!(optimizer, e, map(x -> x.value, vars.variables))
return CI{VOV, MOIAlwaysTrue}(cidx)
end
Expand Down Expand Up @@ -255,10 +250,9 @@ struct MOIOrdered <: MOI.AbstractVectorSet
end
MOI.supports_constraint(::Optimizer, ::Type{VOV}, ::Type{MOIOrdered}) = true
function MOI.add_constraint(optimizer::Optimizer, vars::MOI.VectorOfVariables, ::MOIOrdered)
max_dom_size = max_domains_size(optimizer, map(x -> x.value, vars.variables))
e = (x; param=nothing, dom_size=max_dom_size) -> error_f(
usual_constraints[:ordered])(x; param=param, dom_size=dom_size
)
#max_dom_size = max_domains_size(optimizer, map(x -> x.value, vars.variables))
e = (x; kargs...) -> error_f(
USUAL_CONSTRAINTS[:ordered])(x; kargs...)
cidx = constraint!(optimizer, e, map(x -> x.value, vars.variables))
return CI{VOV, MOIOrdered}(cidx)
end
Expand Down Expand Up @@ -288,10 +282,9 @@ struct MOIDistDifferent <: MOI.AbstractVectorSet
end
MOI.supports_constraint(::Optimizer, ::Type{VOV}, ::Type{MOIDistDifferent}) = true
function MOI.add_constraint(optimizer::Optimizer, vars::MOI.VectorOfVariables, ::MOIDistDifferent)
max_dom_size = max_domains_size(optimizer, map(x -> x.value, vars.variables))
e = (x; param=nothing, dom_size=max_dom_size) -> error_f(
usual_constraints[:dist_different])(x; param=param, dom_size=dom_size
)
#max_dom_size = max_domains_size(optimizer, map(x -> x.value, vars.variables))
e = (x; kargs...) -> error_f(
USUAL_CONSTRAINTS[:dist_different])(x; kargs...)
cidx = constraint!(optimizer, e, map(x -> x.value, vars.variables))
return CI{VOV, MOIDistDifferent}(cidx)
end
Expand Down Expand Up @@ -332,9 +325,9 @@ function MOI.supports_constraint(::Optimizer, ::Type{VOV}, ::Type{MOIAllEqualPar
end
function MOI.add_constraint(optimizer::Optimizer, vars::MOI.VectorOfVariables, set::MOIAllEqualParam{T}
) where T <: Number
max_dom_size = max_domains_size(optimizer, map(x -> x.value, vars.variables))
e = (x; param=set.param, dom_size=max_dom_size) -> error_f(
usual_constraints[:all_equal_param])(x; param=param, dom_size=dom_size
# max_dom_size = max_domains_size(optimizer, map(x -> x.value, vars.variables))
e = (x; kargs...) -> error_f(
USUAL_CONSTRAINTS[:all_equal_param])(x; param=param, dom_size=dom_size
)
cidx = constraint!(optimizer, e, map(x -> x.value, vars.variables))
return CI{VOV, MOIAllEqualParam{T}}(cidx)
Expand Down Expand Up @@ -379,10 +372,9 @@ function MOI.supports_constraint(::Optimizer, ::Type{VOV}, ::Type{MOISumEqualPar
end
function MOI.add_constraint(optimizer::Optimizer, vars::MOI.VectorOfVariables, set::MOISumEqualParam{T}
) where {T <: Number}
max_dom_size = max_domains_size(optimizer, map(x -> x.value, vars.variables))
e = (x; param=set.param, dom_size=max_dom_size) -> error_f(
usual_constraints[:sum_equal_param])(x; param=param, dom_size=dom_size
)
#max_dom_size = max_domains_size(optimizer, map(x -> x.value, vars.variables))
e = (x; kargs...) -> error_f(
USUAL_CONSTRAINTS[:sum_equal_param])(x; kargs...)
cidx = constraint!(optimizer, e, map(x -> x.value, vars.variables))
return CI{VOV, MOISumEqualParam{T}}(cidx)
end
Expand Down Expand Up @@ -427,10 +419,9 @@ function MOI.supports_constraint(::Optimizer, ::Type{VOV}, ::Type{MOILessThanPar
end
function MOI.add_constraint(optimizer::Optimizer, vars::MOI.VectorOfVariables, set::MOILessThanParam{T}
) where {T <: Number}
max_dom_size = max_domains_size(optimizer, map(x -> x.value, vars.variables))
e = (x; param=set.param, dom_size=max_dom_size) -> error_f(
usual_constraints[:less_than_param])(x; param=param, dom_size=dom_size
)
#max_dom_size = max_domains_size(optimizer, map(x -> x.value, vars.variables))
e = (x; kargs...) -> error_f(
USUAL_CONSTRAINTS[:less_than_param])(x; kargs...)
cidx = constraint!(optimizer, e, map(x -> x.value, vars.variables))
return CI{VOV, MOILessThanParam{T}}(cidx)
end
Expand Down Expand Up @@ -475,10 +466,9 @@ function MOI.supports_constraint(::Optimizer, ::Type{VOV}, ::Type{MOIMinusEqualP
end
function MOI.add_constraint(optimizer::Optimizer, vars::MOI.VectorOfVariables, set::MOIMinusEqualParam{T}
) where {T <: Number}
max_dom_size = max_domains_size(optimizer, map(x -> x.value, vars.variables))
e = (x; param=set.param, dom_size=max_dom_size) -> error_f(
usual_constraints[:minus_equal_param])(x; param=param, dom_size=dom_size
)
#max_dom_size = max_domains_size(optimizer, map(x -> x.value, vars.variables))
e = (x; kargs...) -> error_f(
USUAL_CONSTRAINTS[:minus_equal_param])(x; kargs...)
cidx = constraint!(optimizer, e, map(x -> x.value, vars.variables))
return CI{VOV, MOIMinusEqualParam{T}}(cidx)
end
Expand Down Expand Up @@ -511,10 +501,9 @@ struct MOISequentialTasks <: MOI.AbstractVectorSet
end
MOI.supports_constraint(::Optimizer, ::Type{VOV}, ::Type{MOISequentialTasks}) = true
function MOI.add_constraint(optimizer::Optimizer, vars::MOI.VectorOfVariables, ::MOISequentialTasks)
max_dom_size = max_domains_size(optimizer, map(x -> x.value, vars.variables))
e = (x; param=nothing, dom_size=max_dom_size) -> error_f(
usual_constraints[:sequential_tasks])(x; param=param, dom_size=dom_size
)
#max_dom_size = max_domains_size(optimizer, map(x -> x.value, vars.variables))
e = (x; kargs...) -> error_f(
USUAL_CONSTRAINTS[:sequential_tasks])(x; kargs...)
cidx = constraint!(optimizer, e, map(x -> x.value, vars.variables))
return CI{VOV, MOISequentialTasks}(cidx)
end
Expand Down
2 changes: 1 addition & 1 deletion src/objectives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ScalarFunction(f, x::VI) = ScalarFunction(f, VOV([x]))
Base.copy(func::ScalarFunction) = ScalarFunction(func.f, func.X)

# supports
MOI.supports(::Optimizer, ::OF{ScalarFunction{F, V}}) where {F <: Function, V <: Union{Nothing, SVF,VOV}} = true
MOI.supports(::Optimizer, ::OF{ScalarFunction{F, V}}) where {F <: Function, V <: Union{Nothing, VI,VOV}} = true

# set
function MOI.set(optimizer::Optimizer, ::OF, func::ScalarFunction{F, Nothing}
Expand Down
2 changes: 1 addition & 1 deletion src/results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function MOI.get(optimizer::Optimizer, ::MOI.VariablePrimal, vi::MOI.VariableInd
end


MOI.get(optimizer::Optimizer, ::MOI.SolveTime) = time_info(optimizer)[:total_run]
MOI.get(optimizer::Optimizer, ::MOI.SolveTimeSec) = time_info(optimizer)[:total_run]

function MOI.get(optimizer::Optimizer, ::MOI.RawStatusString)
return has_solution(optimizer) ? "Satisfying solution" : "No solutions"
Expand Down
Loading

0 comments on commit c045470

Please sign in to comment.