Skip to content

Commit

Permalink
fix multiple graph dual
Browse files Browse the repository at this point in the history
  • Loading branch information
jalving committed Oct 8, 2023
1 parent 51bb4c6 commit 0d52c94
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/optigraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ Retrieve the dual value of `linkref` on optigraph `graph`.
function JuMP.dual(graph::OptiGraph, linkref::LinkConstraintRef)
optiedge = JuMP.owner_model(linkref)
edge_pointer = optiedge.backend.optimizers[graph.id]
dual_value = MOI.get(optiedge.backend, MOI.ConstraintDual(), linkref)
dual_value = MOI.get(edge_pointer, MOI.ConstraintDual(), linkref)
return dual_value
end

Expand Down
38 changes: 38 additions & 0 deletions test/optigraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,44 @@ function test_nlp_exceptions()
@test_throws Exception @NLconstraint(graph, graph[1][:x]^3 >= 0)
end

function test_multiple_graphs()
graph = OptiGraph()
set_optimizer(graph, Ipopt.Optimizer)
@optinode(graph, nodes[1:4])
for (i, node) in enumerate(nodes)
@variable(node, x >= i)
@objective(node, Min, 2 * x)
end
for i in 1:3
@linkconstraint(graph, nodes[i + 1][:x] + nodes[i][:x] >= i * 4)
end

node_membership = [1, 1, 2, 2]
hypergraph, hyper_map = hyper_graph(graph)
partition = Partition(hypergraph, node_membership, hyper_map)
apply_partition!(graph, partition)
subs = subgraphs(graph)
expanded_subgraphs = Plasmo.expand.(graph, subs, 1)

set_optimizer(
expanded_subgraphs[1],
optimizer_with_attributes(Ipopt.Optimizer, "print_level" => 0)
)
set_optimizer(
expanded_subgraphs[2],
optimizer_with_attributes(Ipopt.Optimizer, "print_level" => 0)
)

middle_link = graph.optiedges[1].linkrefs[1]
optimize!(expanded_subgraphs[1])
dual1 = dual(middle_link)
optimize!(expanded_subgraphs[2])
dual2 = dual(middle_link)

@test dual(expanded_subgraphs[1], middle_link) == dual1
@test dual(expanded_subgraphs[2], middle_link) == dual2
end

function run_tests()
for name in names(@__MODULE__; all=true)
if !startswith("$(name)", "test_")
Expand Down

0 comments on commit 0d52c94

Please sign in to comment.