Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support parameters and make performance updates #128

Merged
merged 6 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "Plasmo"
uuid = "d3f7391f-f14a-50cc-bbe4-76a32d1bad3c"
authors = ["Jordan Jalving <[email protected]>"]
repo = "https://github.com/plasmo-dev/Plasmo.jl.git"
version = "0.6.3"
version = "0.6.4"

[deps]
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
[![](https://img.shields.io/badge/docs-dev-blue.svg)](https://plasmo-dev.github.io/Plasmo.jl/dev/)
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://plasmo-dev.github.io/Plasmo.jl/stable/)
[![DOI](https://zenodo.org/badge/96967382.svg)](https://zenodo.org/badge/latestdoi/96967382)
[![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle)


# Plasmo.jl

Expand Down
8 changes: 7 additions & 1 deletion src/Plasmo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export OptiGraph,
OptiNode,
OptiEdge,
NodeVariableRef,
EdgeConstraintRef,
direct_moi_graph,
graph_backend,
graph_index,
Expand Down Expand Up @@ -108,7 +109,10 @@ export OptiGraph,

# other functions

set_jump_model
set_jump_model,
extract_variables,
is_separable,
extract_separable_terms

include("core_types.jl")

Expand Down Expand Up @@ -138,6 +142,8 @@ include("graph_functions/topology.jl")

include("graph_functions/partition.jl")

include("utils.jl")

# extensions
function __init__()
@require KaHyPar = "2a6221f6-aa48-11e9-3542-2d9e0ef01880" include(
Expand Down
57 changes: 46 additions & 11 deletions src/backends/moi_backend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,13 @@ function _add_edge(backend::GraphMOIBackend, edge::OptiEdge)
return nothing
end

#
# MOI Methods
#

### graph attributes
## graph attributes

function MOI.supports(backend::GraphMOIBackend, attr::MOI.AnyAttribute, args...)
return MOI.supports(JuMP.backend(backend), attr, args...)
end

function MOI.get(
backend::GraphMOIBackend, attr::AT
Expand Down Expand Up @@ -528,22 +530,54 @@ end
# MOI variables and constraints
#

function MOI.add_variable(graph_backend::GraphMOIBackend, vref::NodeVariableRef)
function MOI.add_variable(backend::GraphMOIBackend, vref::NodeVariableRef)
# return if variable already exists in backend
vref in keys(graph_backend.element_to_graph_map.var_map) && return nothing
vref in keys(backend.element_to_graph_map.var_map) && return nothing

# add the variable
graph_var_index = MOI.add_variable(graph_backend.moi_backend)
graph_var_index = MOI.add_variable(backend.moi_backend)

# map reference to index
backend.element_to_graph_map[vref] = graph_var_index
backend.graph_to_element_map[graph_var_index] = vref

# create key for node if necessary
if !haskey(backend.node_variables, vref.node)
backend.node_variables[vref.node] = MOI.VariableIndex[]
end
push!(backend.node_variables[vref.node], graph_var_index)
return graph_var_index
end

function MOI.add_constrained_variable(
backend::GraphMOIBackend,
vref::NodeVariableRef,
cref::NodeConstraintRef,
set::MOI.AbstractScalarSet,
)
# return if variable already exists in backend
vref in keys(backend.element_to_graph_map.var_map) && return nothing

# add the variable and parameter constraint
graph_var_index, graph_con_index = MOI.add_constrained_variable(
backend.moi_backend, set
)

# map reference to index
graph_backend.element_to_graph_map[vref] = graph_var_index
graph_backend.graph_to_element_map[graph_var_index] = vref
backend.element_to_graph_map[vref] = graph_var_index
backend.graph_to_element_map[graph_var_index] = vref
backend.element_to_graph_map[cref] = graph_con_index
backend.graph_to_element_map[graph_con_index] = cref

# create key for node if necessary
if !haskey(graph_backend.node_variables, vref.node)
graph_backend.node_variables[vref.node] = MOI.VariableIndex[]
if !haskey(backend.node_variables, vref.node)
backend.node_variables[vref.node] = MOI.VariableIndex[]
end
if !haskey(backend.element_constraints, vref.node)
graph_backend.element_constraints[vref.node] = MOI.ConstraintIndex[]
end
push!(graph_backend.node_variables[vref.node], graph_var_index)
push!(backend.node_variables[vref.node], graph_var_index)
push!(backend.element_constraints[vref.node], graph_con_index)
return graph_var_index
end

Expand Down Expand Up @@ -879,6 +913,7 @@ function _copy_node_variables(

# map existing variables in the index_map
# existing variables may come from linking constraints added between graphs
# TODO: could be slow...
existing_vars = intersect(node_variables, keys(dest.element_to_graph_map.var_map))
for var in existing_vars
src_graph_index = graph_index(var)
Expand Down
2 changes: 0 additions & 2 deletions src/core_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ struct ElementData{GT<:AbstractOptiGraph}
# track constraint indices
last_constraint_index::OrderedDict{OptiElement,Int}
end

# default is OptiGraph
function ElementData(GT::Type{<:AbstractOptiGraph})
return ElementData{GT}(
OrderedDict{OptiNode{GT},Vector{GT}}(),
Expand Down
Loading
Loading