Skip to content

Commit

Permalink
support lazy constraints in plasmo
Browse files Browse the repository at this point in the history
  • Loading branch information
jalving committed Oct 10, 2023
1 parent 8592344 commit 8f44aa3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/moi_backend_graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,18 @@ function MOI.set(graph_backend::GraphBackend, attr::MOI.AbstractOptimizerAttribu
return nothing
end

# TODO: properly support variable and constraint attributes
function MOI.get(
graph_backend::GraphBackend, attr::MOI.VariablePrimalStart, idx::MOI.VariableIndex
)
return MOI.get(graph_backend.model_cache, attr, idx)
end

#TODO: properly support variable and constraint attributes
#MOI.set(graph_backend::GraphBackend,attr::MOI.AnyAttribute,args...) = MOI.set(graph_backend.optimizer,attr,args...)

MOIU.state(graph_backend::GraphBackend) = graph_backend.state

# TODO: decide whether we support graph modes
#MOIU.mode(graph_backend::GraphBackend) = graph_backend.mode

"""
Expand Down
40 changes: 40 additions & 0 deletions src/optigraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ function add_node!(graph::OptiGraph, optinode::OptiNode)
return optinode
end

function add_node!(graph::OptiGraph, m::JuMP.Model, label::String)
optinode = add_node!(graph)
set_model(optinode, m)
optinode.label = label
return optinode
end

"""
optinodes(graph::OptiGraph)::Vector{OptiNode}
Expand Down Expand Up @@ -927,6 +934,19 @@ function JuMP.start_value(graph::OptiGraph, variable::JuMP.VariableRef)
return MOI.get(backend(graph), MOI.VariablePrimalStart(), var_idx)
end

function JuMP.set_attribute(
graph::OptiGraph,
attr::MOI.AbstractModelAttribute,
value
)
MOI.set(graph, attr, value)
return
end

function JuMP.solver_name(graph::OptiGraph)
return MOI.get(graph.moi_backend, MOI.SolverName())
end

"""
JuMP.termination_status(graph::OptiGraph)
Expand All @@ -936,6 +956,26 @@ function JuMP.termination_status(graph::OptiGraph)
return MOI.get(graph.moi_backend, MOI.TerminationStatus())
end

function JuMP.primal_status(graph::OptiGraph)
return MOI.get(graph.moi_backend, MOI.PrimalStatus())
end

function JuMP.dual_status(graph::OptiGraph)
return MOI.get(graph.moi_backend, MOI.DualStatus())
end

function JuMP.callback_value(cb_data, x::GenericVariableRef, graph::OptiGraph)
return MOI.get(
graph.moi_backend.optimizer,
MOI.CallbackVariablePrimal(cb_data),
index(x),
)
end

function JuMP.callback_node_status(cb_data, graph::OptiGraph)
return MOI.get(graph.moi_backend.optimizer, MOI.CallbackNodeStatus(cb_data))
end

####################################
#Print Functions
####################################
Expand Down
8 changes: 8 additions & 0 deletions src/optimizer_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,14 @@ function MOI.set(graph::OptiGraph, attr::MOI.AbstractModelAttribute, value)
return MOI.set(backend(graph), attr, value)
end

function MOI.submit(
graph::OptiGraph,
cb::MOI.LazyConstraint,
con::ScalarConstraint,
)
return MOI.submit(graph.moi_backend.optimizer, cb, moi_function(con.func), con.set)
end

#######################################################
#Optinode optimizer interface
#######################################################
Expand Down

0 comments on commit 8f44aa3

Please sign in to comment.