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

Commit

Permalink
Merge remote-tracking branch 'origin/master' into jg/addsinvar_slow
Browse files Browse the repository at this point in the history
# Conflicts:
#	test/runtests.jl
  • Loading branch information
joaquimg committed Jun 26, 2018
2 parents 6401eb6 + 7a160dc commit bee0606
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 25 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
julia 0.6
MathOptInterface 0.3 0.4
MathOptInterface 0.4 0.5
22 changes: 11 additions & 11 deletions src/constraints/scalaraffine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ end
Scalar Coefficient Change of Linear Constraint
=#

MOI.canmodifyconstraint(m::LinQuadOptimizer, c::LCI{<: LinSets}, ::Type{MOI.ScalarCoefficientChange{Float64}}) = true
function MOI.modifyconstraint!(m::LinQuadOptimizer, c::LCI{<: LinSets}, chg::MOI.ScalarCoefficientChange{Float64})
MOI.canmodify(m::LinQuadOptimizer, ::Type{LCI{S}}, ::Type{MOI.ScalarCoefficientChange{Float64}}) where S <: LinSets = true
function MOI.modify!(m::LinQuadOptimizer, c::LCI{S}, chg::MOI.ScalarCoefficientChange{Float64}) where S <: LinSets
col = m.variable_mapping[chg.variable]
change_matrix_coefficient!(m, m[c], col, chg.new_coefficient)
end
Expand All @@ -173,13 +173,13 @@ end
Change RHS of linear constraint without modifying sense
=#

MOI.canmodifyconstraint(m::LinQuadOptimizer, c::LCI{S}, ::Type{S}) where S <: Union{LE, GE, EQ} = true
function MOI.modifyconstraint!(m::LinQuadOptimizer, c::LCI{S}, newset::S) where S <: Union{LE, GE, EQ}
MOI.canset(m::LinQuadOptimizer, ::MOI.ConstraintSet, ::Type{LCI{S}}) where S <: Union{LE, GE, EQ} = true
function MOI.set!(m::LinQuadOptimizer, ::MOI.ConstraintSet, c::LCI{S}, newset::S) where S <: Union{LE, GE, EQ}
change_rhs_coefficient!(m, m[c], _getrhs(newset))
end

MOI.canmodifyconstraint(m::LinQuadOptimizer, c::LCI{IV}, ::Type{IV}) = true
function MOI.modifyconstraint!(m::LinQuadOptimizer, c::LCI{IV}, set::IV)
MOI.canset(m::LinQuadOptimizer, ::MOI.ConstraintSet, ::Type{LCI{IV}}) = true
function MOI.set!(m::LinQuadOptimizer, ::MOI.ConstraintSet, c::LCI{IV}, set::IV)
modify_ranged_constraints!(m, [m[c]], [set.lower], [set.upper])
end

Expand All @@ -205,17 +205,17 @@ end
Transform scalar constraint
=#

function MOI.cantransformconstraint(m::LinQuadOptimizer, ref::LCI{S}, newset::S) where S
function MOI.cantransform(m::LinQuadOptimizer, ref::LCI{S}, newset::S) where S
false
end
function MOI.transformconstraint!(m::LinQuadOptimizer, ref::LCI{S}, newset::S) where S
error("Cannot transform constraint of same set. use `modifyconstraint!` instead.")
function MOI.transform!(m::LinQuadOptimizer, ::LCI{S}, newset::S) where S
error("Cannot transform constraint of same set. use `set!` instead.")
end

function MOI.cantransformconstraint(m::LinQuadOptimizer, ref::LCI{S1}, newset::S2) where S1 where S2 <: Union{LE, GE, EQ}
function MOI.cantransform(m::LinQuadOptimizer, ref::LCI{S1}, newset::S2) where S1 where S2 <: Union{LE, GE, EQ}
true
end
function MOI.transformconstraint!(m::LinQuadOptimizer, ref::LCI{S1}, newset::S2) where S1 where S2 <: Union{LE, GE, EQ}
function MOI.transform!(m::LinQuadOptimizer, ref::LCI{S1}, newset::S2) where S1 where S2 <: Union{LE, GE, EQ}
dict = constrdict(m, ref)
row = dict[ref]
change_linear_constraint_sense!(m, [row], [backend_type(m,newset)])
Expand Down
4 changes: 2 additions & 2 deletions src/constraints/singlevariable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ function MOI.get(m::LinQuadOptimizer, ::MOI.ConstraintFunction, c::SVCI{<: LinSe
end

# modify
MOI.canmodifyconstraint(::LinQuadOptimizer, ::SVCI{S}, ::Type{S}) where S <: LinSets = true
function MOI.modifyconstraint!(m::LinQuadOptimizer, c::SVCI{S}, newset::S) where S <: LinSets
MOI.canset(::LinQuadOptimizer, ::MOI.ConstraintSet, ::Type{SVCI{S}}) where S <: LinSets = true
function MOI.set!(m::LinQuadOptimizer, ::MOI.ConstraintSet, c::SVCI{S}, newset::S) where S <: LinSets
setvariablebound!(m, SinVar(m[c]), newset)
end

Expand Down
12 changes: 10 additions & 2 deletions src/constraints/vectoraffine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,23 @@ function addlinearconstraint!(m::LinQuadOptimizer, func::VecLin, sense::Cchar)
add_linear_constraints!(m, A, fill(sense, length(func.constants)), -func.constants)
end

MOI.canmodifyconstraint(m::LinQuadOptimizer, ::VLCI{<: VecLinSets}, ::Type{MOI.VectorConstantChange{Float64}}) = true
function MOI.modifyconstraint!(m::LinQuadOptimizer, ref::VLCI{<: VecLinSets}, chg::MOI.VectorConstantChange{Float64})
MOI.canmodify(m::LinQuadOptimizer, ::Type{VLCI{S}}, ::Type{MOI.VectorConstantChange{Float64}}) where S <: VecLinSets = true
function MOI.modify!(m::LinQuadOptimizer, ref::VLCI{<: VecLinSets}, chg::MOI.VectorConstantChange{Float64})
@assert length(chg.new_constant) == length(m[ref])
for (r, v) in zip(m[ref], chg.new_constant)
change_rhs_coefficient!(m, r, -v)
m.constraint_constant[r] = v
end
end

MOI.canmodify(m::LinQuadOptimizer, ::Type{VLCI{S}}, ::Type{MOI.MultirowChange{Float64}}) where S <: VecLinSets = true
function MOI.modify!(m::LinQuadOptimizer, ref::VLCI{<: VecLinSets}, chg::MOI.MultirowChange{Float64})
col = m.variable_mapping[chg.variable]
for (row, coef) in chg.new_coefficients
change_matrix_coefficient!(m, row, col, coef)
end
end

MOI.candelete(m::LinQuadOptimizer, c::VLCI{<:VecLinSets}) = MOI.isvalid(m, c)
function MOI.delete!(m::LinQuadOptimizer, c::VLCI{<:VecLinSets})
deleteconstraintname!(m, c)
Expand Down
19 changes: 16 additions & 3 deletions src/objective.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,26 @@ end
Modify objective function
=#

MOI.canmodifyobjective(m::LinQuadOptimizer, ::Type{MOI.ScalarCoefficientChange{Float64}}) = true
function MOI.modifyobjective!(m::LinQuadOptimizer, chg::MOI.ScalarCoefficientChange{Float64})
function MOI.canmodify(m::LinQuadOptimizer, ::MOI.ObjectiveFunction{F}, ::Type{MOI.ScalarCoefficientChange{Float64}}) where F
if F <: MOI.ScalarQuadraticFunction
return m.obj_type == QuadraticObjective
elseif F <: MOI.ScalarAffineFunction
return m.obj_type == AffineObjective
end
return false
end
function MOI.modify!(m::LinQuadOptimizer, ::MOI.ObjectiveFunction{F}, chg::MOI.ScalarCoefficientChange{Float64}) where F
if m.obj_type == SingleVariableObjective
m.obj_type = AffineObjective
m.single_obj_var = nothing
end
col = m.variable_mapping[chg.variable]
# 0 row is the objective
change_objective_coefficient!(m, col, chg.new_coefficient)
end

function MOI.canmodify(m::LinQuadOptimizer, ::MOI.ObjectiveFunction{F}, ::Type{MOI.ScalarConstantChange{Float64}}) where F
return !(F == MOI.SingleVariable)
end
function MOI.modify!(m::LinQuadOptimizer, ::MOI.ObjectiveFunction{F}, chg::MOI.ScalarConstantChange{Float64}) where F
m.objective_constant = chg.new_constant
end
12 changes: 6 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
push!(Base.LOAD_PATH,joinpath(dirname(@__FILE__),"..",".."))

using Base.Test, MathOptInterface
using LinQuadOptInterface

const MOI= MathOptInterface
const MOIT = MathOptInterface.Test
const LQOI = LinQuadOptInterface


@testset "LinQuadOptInterface" begin
@testset "Unit Tests" begin
config = MOIT.TestConfig(solve = false)
Expand All @@ -22,9 +19,13 @@ const LQOI = LinQuadOptInterface
]
)
MOIT.unittest(solver, config, [
"solve_affine_interval"
"solve_affine_interval",
"solve_qp_edge_cases",
"solve_qcp_edge_cases",
"solve_affine_deletion_edge_cases"
])
end

@testset "Linear tests" begin
linconfig = MOIT.TestConfig(solve = false)
solver = LQOI.MockLinQuadOptimizer()
Expand Down Expand Up @@ -60,7 +61,7 @@ const LQOI = LinQuadOptInterface
MOIT.emptytest(solver)
end
@testset "orderedindicestest" begin
MOIT.orderedindicestest(solver)
# MOIT.orderedindicestest(solver)
end
@testset "canaddconstrainttest" begin
MOIT.canaddconstrainttest(solver, Float64, Complex{Float64})
Expand All @@ -71,4 +72,3 @@ const LQOI = LinQuadOptInterface
end
end
end
;

0 comments on commit bee0606

Please sign in to comment.