Skip to content

Commit

Permalink
remove diffopt from poi
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquimg committed Dec 27, 2024
1 parent 9bafba7 commit dc093bf
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 987 deletions.
4 changes: 1 addition & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ version = "0.7.0"

[deps]
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
DiffOpt = "930fe3bc-9c6b-11ea-2d94-6184641e85e7"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"

[compat]
Expand All @@ -18,12 +17,11 @@ julia = "1.6"

[extras]
GLPK = "60bf3e95-4087-53dc-ae20-288a0d20c6a6"
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
SCS = "c946c3f1-0d1f-5ce8-9dea-7daa1f7e2d13"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["GLPK", "HiGHS", "Ipopt", "JuMP", "LinearAlgebra", "SCS", "Test"]
test = ["GLPK", "Ipopt", "JuMP", "LinearAlgebra", "SCS", "Test"]
77 changes: 75 additions & 2 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,12 @@ end
# Variables
#

# TODO: This is not correct
function MOI.is_valid(model::Optimizer, vi::MOI.VariableIndex)
return MOI.is_valid(model.optimizer, vi)
return haskey(model.variables, vi) || haskey(model.parameters, p_idx(vi))
end

function MOI.is_valid(model::Optimizer, ci::MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter{T}}) where {T}
return haskey(model.parameters, p_idx(MOI.VariableIndex(ci.value)))
end

function MOI.supports(
Expand Down Expand Up @@ -1127,6 +1130,76 @@ end
# Special Attributes
#

struct ParametricObjectiveType <: MOI.AbstractModelAttribute end

function MOI.get(model::Optimizer{T}, ::ParametricObjectiveType) where {T}
if model.quadratic_objective_cache !== nothing
return ParametricQuadraticFunction{T}
elseif model.affine_objective_cache !== nothing
return ParametricAffineFunction{T}
end
return Nothing
end

struct ParametricObjectiveFunction{T} <: MOI.AbstractModelAttribute end

function MOI.get(model::Optimizer{T}, ::ParametricObjectiveFunction{ParametricQuadraticFunction{T}}) where {T}
if model.quadratic_objective_cache === nothing
error("
There is no parametric quadratic objective function in the model.
")
end
return model.quadratic_objective_cache
end

function MOI.get(model::Optimizer{T}, ::ParametricObjectiveFunction{ParametricAffineFunction{T}}) where {T}
if model.affine_objective_cache === nothing
error("
There is no parametric affine objective function in the model.
")
end
return model.affine_objective_cache
end

struct ListOfParametricConstraintTypesPresent <: MOI.AbstractModelAttribute end

function MOI.get(model::Optimizer{T}, ::ListOfParametricConstraintTypesPresent) where {T}
output = Set{Tuple{DataType,DataType,DataType}}()
for (F, S) in MOI.Utilities.DoubleDicts.nonempty_outer_keys(model.affine_constraint_cache)
push!(output, (F, S, ParametricAffineFunction{T}))
end
for (F, S) in MOI.Utilities.DoubleDicts.nonempty_outer_keys(model.vector_affine_constraint_cache)
push!(output, (F, S, ParametricVectorAffineFunction{T}))
end
for (F, S) in MOI.Utilities.DoubleDicts.nonempty_outer_keys(model.quadratic_constraint_cache)
push!(output, (F, S, ParametricQuadraticFunction{T}))
end
return collect(output)
end

struct DictOfParametricConstraintIndicesAndFunctions{F,S,P} <: MOI.AbstractModelAttribute end

function MOI.get(
model::Optimizer,
::DictOfParametricConstraintIndicesAndFunctions{F,S,P},
) where {F,S,P <: ParametricAffineFunction}
return model.affine_constraint_cache[F, S]
end

function MOI.get(
model::Optimizer,
::DictOfParametricConstraintIndicesAndFunctions{F,S,P},
) where {F,S,P <: ParametricVectorAffineFunction}
return model.vector_affine_constraint_cache[F, S]
end

function MOI.get(
model::Optimizer,
::DictOfParametricConstraintIndicesAndFunctions{F,S,P},
) where {F,S, P <: ParametricQuadraticFunction}
return model.quadratic_constraint_cache[F, S]
end

struct ListOfPureVariableIndices <: MOI.AbstractModelAttribute end

function MOI.get(model::Optimizer, ::ListOfPureVariableIndices)
Expand Down
1 change: 0 additions & 1 deletion src/ParametricOptInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,5 @@ end
include("duals.jl")
include("update_parameters.jl")
include("MOI_wrapper.jl")
include("diff.jl")

end # module
Loading

0 comments on commit dc093bf

Please sign in to comment.