Skip to content

Aggregated graph backend does not update variables correctly #110

@dlcole3

Description

@dlcole3

Ran into this problem trying to implement a copy function for an OptiGraph, and it might be related to the way backends are set up. In the following code, the aggregated graph backend does not correctly record the variables:

using Plasmo

function build_partitioned_graph()
    g = OptiGraph()
    @optinode(g, nodes[1:4])

    for node in nodes
        @variable(node, 0 <= x)
        @objective(node, Min, x)
    end
    @linkconstraint(g, nodes[1][:x] + nodes[2][:x] >= 1)
    @linkconstraint(g, nodes[2][:x] + nodes[3][:x] >= 1)
    @linkconstraint(g, nodes[3][:x] + nodes[4][:x] >= 1)
    @linkconstraint(g, nodes[4][:x] + nodes[1][:x] >= 1)

    node_membership_vector = [1, 1, 2, 2]
    partition = Plasmo.Partition(g, node_membership_vector)

    apply_partition!(g, partition)
    return g
end
g1 = build_partitioned_graph()
g2 = build_partitioned_graph()

g0 = OptiGraph()
add_subgraph!(g0, g1)
add_subgraph!(g0, g2)

set_to_node_objectives(g0)

@optinode(g1, n_g1)
@optinode(g2, n_g2)
@optinode(g0, n_g)

agg_graph_layer1, ref_map_layer1 = aggregate_to_depth(g0, 1)

gb = graph_backend(g0)
gb_agg = graph_backend(agg_graph_layer1

If you look at graph backend of the original vs. aggregated graphs (gb vs. gb_agg), the latter reports 0 variables and constraints. In addition, the element_to_graph_map and graph_to_element_map are both empty and node_variables is missing nodes and variables. The all_variables function still correctly works though.

I looked into this a little deeper, and I think it may have to do with MOIU.pass_attributes in the aggregate.jl file here. In the source code for MOIU.pass_attributes here, it relies on the function MOI.get function to collect attributes of the MOI.ListOfModelAttributesSet() or MOI.ListOfVariableAttributesSet(). However, if I call either MOI.get(gb, MOI.ListOfVariableAttributesSet()) or MOI.get(gb.backend, MOI.ListOfVariableAttributesSet()), I get an empty vector returned. However, the vector is nonempty if I call it on the lowest level subgraph's backend (e.g., on graph_backend(getsubgraphs(g1)[1]). I think perhaps the MOI backend is not seeing the subgraph information correctly? Any thoughts on how best to address this? I think my knowledge on the MOI backend and graph backend interfaces is not yet good enough to know how to resolve this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions