Skip to content
This repository has been archived by the owner on Feb 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #40 from JuliaOpt/bl/moi0.4
Browse files Browse the repository at this point in the history
Updates to MOI 0.4
  • Loading branch information
blegat authored Jun 26, 2018
2 parents a3d2a6b + 1ca0753 commit a409190
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
julia 0.6
MathOptInterface 0.3 0.4
MathOptInterface 0.4 0.5
Mosek 0.8.3
70 changes: 35 additions & 35 deletions src/constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -537,21 +537,20 @@ end
## MODIFY #####################################################################
################################################################################

MOI.canmodifyconstraint(m::MosekModel, c::MOI.ConstraintIndex{F,D}, dom) where { F <: LinearFunction, D <: VectorCone } = false
MOI.canmodifyconstraint(m::MosekModel, c::MOI.ConstraintIndex{F,D}, dom) where { F <: LinearFunction, D <: PositiveSemidefiniteCone } = false
MOI.canmodifyconstraint(m::MosekModel, c::MOI.ConstraintIndex{F,D}, ::Type{D}) where { F <: LinearFunction, D <: LinearDomain } = haskey(select(m.constrmap,F,D),c.value)
MOI.canmodifyconstraint(m::MosekModel, c::MOI.ConstraintIndex{F,D}, ::Type{F}) where { F <: Union{MOI.SingleVariable,MOI.ScalarAffineFunction}, D <: ScalarLinearDomain } = haskey(select(m.constrmap,F,D),c.value)
MOI.canmodifyconstraint(m::MosekModel, c::MOI.ConstraintIndex{F,D}, ::Type{<:MOI.AbstractFunctionModification}) where { F <: AffineFunction, D <: MOI.AbstractSet } = haskey(select(m.constrmap,F,D),c.value)
MOI.canset(m::MosekModel, ::MOI.ConstraintSet, ::Type{MOI.ConstraintIndex{F,D}}) where { F <: LinearFunction, D <: LinearDomain } = true
MOI.canset(m::MosekModel, ::MOI.ConstraintFunction, ::Type{MOI.ConstraintIndex{F,D}}) where { F <: Union{MOI.SingleVariable,MOI.ScalarAffineFunction}, D <: ScalarLinearDomain } = true
MOI.canmodify(m::MosekModel, ::Type{MOI.ConstraintIndex{F,D}}, ::Type{<:MOI.AbstractFunctionModification}) where { F <: AffineFunction, D <: MOI.AbstractSet } = true

chgbound(bl::Float64,bu::Float64,k::Float64,dom :: MOI.LessThan{Float64}) = bl,dom.upper-k
chgbound(bl::Float64,bu::Float64,k::Float64,dom :: MOI.GreaterThan{Float64}) = dom.lower-k,bu
chgbound(bl::Float64,bu::Float64,k::Float64,dom :: MOI.EqualTo{Float64}) = dom.value-k,dom.value-k
chgbound(bl::Float64,bu::Float64,k::Float64,dom :: MOI.Interval{Float64}) = dom.lower-k,dom.upper-k

function MOI.modifyconstraint!(m::MosekModel,
xcref::MOI.ConstraintIndex{F,D},
dom::D) where { F <: MOI.SingleVariable,
D <: ScalarLinearDomain }
function MOI.set!(m::MosekModel,
::MOI.ConstraintSet,
xcref::MOI.ConstraintIndex{F,D},
dom::D) where { F <: MOI.SingleVariable,
D <: ScalarLinearDomain }
xcid = ref2id(xcref)
j = m.xc_idxs[getindexes(m.xc_block,xcid)[1]]
bk,bl,bu = getvarbound(m.task,j)
Expand All @@ -560,20 +559,21 @@ function MOI.modifyconstraint!(m::MosekModel,
end


function MOI.modifyconstraint!(m::MosekModel,
cref::MOI.ConstraintIndex{F,D},
dom::D) where { F <: MOI.ScalarAffineFunction,
D <: ScalarLinearDomain }
function MOI.set!(m::MosekModel,
::MOI.ConstraintSet,
cref::MOI.ConstraintIndex{F,D},
dom::D) where { F <: MOI.ScalarAffineFunction,
D <: ScalarLinearDomain }
cid = ref2id(cref)
i = getindexes(m.c_block,cid)[1] # since we are in a scalar domain
bk,bl,bu = getconbound(m.task,i)
bl,bu = chgbound(bl,bu,0.0,dom)
putconbound(m.task,i,bk,bl,bu)
end

function MOI.modifyconstraint!(m ::MosekModel,
c ::MOI.ConstraintIndex{MOI.ScalarAffineFunction{Float64},D},
func::MOI.ScalarConstantChange{Float64}) where {D <: MOI.AbstractSet}
function MOI.modify!(m ::MosekModel,
c ::MOI.ConstraintIndex{MOI.ScalarAffineFunction{Float64},D},
func::MOI.ScalarConstantChange{Float64}) where {D <: MOI.AbstractSet}

cid = ref2id(c)

Expand All @@ -585,9 +585,9 @@ function MOI.modifyconstraint!(m ::MosekModel,
putconbound(m.task,i,bk,bl,bu)
end

function MOI.modifyconstraint!(m ::MosekModel,
c ::MOI.ConstraintIndex{MOI.ScalarAffineFunction{Float64},D},
func::MOI.ScalarCoefficientChange{Float64}) where {D <: MOI.AbstractSet}
function MOI.modify!(m ::MosekModel,
c ::MOI.ConstraintIndex{MOI.ScalarAffineFunction{Float64},D},
func::MOI.ScalarCoefficientChange{Float64}) where {D <: MOI.AbstractSet}
cid = ref2id(c)
xid = ref2id(func.variable)

Expand All @@ -597,9 +597,9 @@ function MOI.modifyconstraint!(m ::MosekModel,
putaij(m.task,i,j,func.new_coefficient)
end

function MOI.modifyconstraint!(m::MosekModel,
c::MOI.ConstraintIndex{MOI.VectorAffineFunction{Float64},D},
func::MOI.VectorConstantChange{Float64}) where {D <: MOI.AbstractSet}
function MOI.modify!(m::MosekModel,
c::MOI.ConstraintIndex{MOI.VectorAffineFunction{Float64},D},
func::MOI.VectorConstantChange{Float64}) where {D <: MOI.AbstractSet}
cid = ref2id(c)
assert(cid > 0)

Expand All @@ -616,9 +616,9 @@ function MOI.modifyconstraint!(m::MosekModel,
putconboundlist(m.task,convert(Vector{Int32},subi),bk,bl,bu)
end

function MOI.modifyconstraint!(m::MosekModel,
c::MOI.ConstraintIndex{MOI.VectorAffineFunction{Float64},D},
func::MOI.MultirowChange{Float64}) where {D <: MOI.AbstractSet}
function MOI.modify!(m::MosekModel,
c::MOI.ConstraintIndex{MOI.VectorAffineFunction{Float64},D},
func::MOI.MultirowChange{Float64}) where {D <: MOI.AbstractSet}
cid = ref2id(c)
assert(cid > 0)

Expand All @@ -631,23 +631,23 @@ end



MOI.cantransformconstraint(m::MosekModel, c::MOI.ConstraintIndex{F,D1}, newdom::D2) where {F <: VariableFunction, D1, D2 } = false
MOI.cantransformconstraint(m::MosekModel, c::MOI.ConstraintIndex{MOI.VectorAffineFunction,D1}, newdom::D2) where {D1 <: VectorLinearDomain, D2 <: VectorLinearDomain} = false
function MOI.cantransformconstraint(m::MosekModel,
MOI.cantransform(m::MosekModel, c::MOI.ConstraintIndex{F,D1}, newdom::D2) where {F <: VariableFunction, D1, D2 } = false
MOI.cantransform(m::MosekModel, c::MOI.ConstraintIndex{MOI.VectorAffineFunction,D1}, newdom::D2) where {D1 <: VectorLinearDomain, D2 <: VectorLinearDomain} = false
function MOI.cantransform(m::MosekModel,
cref::MOI.ConstraintIndex{MOI.ScalarAffineFunction{Float64},D1},
newdom::D2) where {D1 <: ScalarLinearDomain,
D2 <: ScalarLinearDomain}
haskey(select(m.constrmap,MOI.ScalarAffineFunction{Float64},D1),cref.value)
end

function MOI.transformconstraint!(m::MosekModel,
cref::MOI.ConstraintIndex{F,D},
newdom::D) where {F <: MOI.AbstractFunction, D <: MOI.AbstractSet}
MOI.modifyconstraint(m,cref,newdom)
function MOI.transform!(m::MosekModel,
cref::MOI.ConstraintIndex{F,D},
newdom::D) where {F <: MOI.AbstractFunction, D <: MOI.AbstractSet}
MOI.modify!(m,cref,newdom)
cref
end

function MOI.transformconstraint!(m::MosekModel,
function MOI.transform!(m::MosekModel,
cref::MOI.ConstraintIndex{MOI.ScalarAffineFunction{Float64},D1},
newdom::D2) where {D1 <: ScalarLinearDomain,
D2 <: ScalarLinearDomain}
Expand All @@ -665,7 +665,7 @@ function MOI.transformconstraint!(m::MosekModel,
newcref
end

function MOI.transformconstraint!(m::MosekModel,
function MOI.transform!(m::MosekModel,
cref::MOI.ConstraintIndex{MOI.VectorAffineFunction{Float64},D1},
newdom::D2) where {D1 <: VectorLinearDomain,
D2 <: VectorLinearDomain}
Expand All @@ -683,7 +683,7 @@ function MOI.transformconstraint!(m::MosekModel,
newcref
end

#MOI.transformconstraint!(m::MosekModel, c::MOI.ConstraintIndex{F,D1}, newdom::D2) where {F <: MOI.VectorAffineFunction , D1 <: VectorLinearDomain, D2 <: VectorLinearDomain} = false
#MOI.transform!(m::MosekModel, c::MOI.ConstraintIndex{F,D1}, newdom::D2) where {F <: MOI.VectorAffineFunction , D1 <: VectorLinearDomain, D2 <: VectorLinearDomain} = false

################################################################################
## DELETE #####################################################################
Expand Down
8 changes: 4 additions & 4 deletions src/objective.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ function MOI.set!(m::MosekModel, ::MOI.ObjectiveFunction, func::MOI.ScalarAffine
putcfix(m.task,func.constant)
end

MOI.canmodifyobjective(m::MosekModel, change :: MOI.ScalarConstantChange) = true
MOI.canmodifyobjective(m::MosekModel, change :: MOI.ScalarCoefficientChange) = true
MOI.canmodify(m::MosekModel, ::MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}, change :: MOI.ScalarConstantChange) = true
MOI.canmodify(m::MosekModel, ::MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}, change :: MOI.ScalarCoefficientChange) = true

function MOI.modifyobjective!(m::MosekModel, change :: MOI.ScalarConstantChange)
function MOI.modify!(m::MosekModel, ::MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}, change :: MOI.ScalarConstantChange)
putcfix(m.task,change.new_constant)
end

function MOI.modifyobjective!(m::MosekModel, change :: MOI.ScalarCoefficientChange)
function MOI.modify!(m::MosekModel, ::MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}, change :: MOI.ScalarCoefficientChange)
vid = ref2id(change.variable)
subj = getindexes(m.x_block,vid)
putcj(m.task,Int32(subj[1]),change.new_coefficient)
Expand Down

0 comments on commit a409190

Please sign in to comment.