Skip to content

Commit

Permalink
Merge pull request #95 from jalving/issue-89
Browse files Browse the repository at this point in the history
support lazy constraints in plasmo
  • Loading branch information
jalving authored Oct 10, 2023
2 parents 8592344 + 8f44aa3 commit 42f3242
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

2 comments on commit 42f3242

@jalving
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/93138

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.4 -m "<description of version>" 42f3242182d8492b58bad9de01aba53768b0f11c
git push origin v0.5.4

Please sign in to comment.