forked from plasmo-dev/Plasmo.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
459 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,64 @@ | ||
# dev file for subgraphs | ||
|
||
using Plasmo | ||
using HiGHS | ||
|
||
graph = OptiGraph(; name=:g1) | ||
|
||
# subgraph1 | ||
sg1 = Plasmo.add_subgraph(graph; name=:sg1, optimizer_graph=graph) | ||
|
||
# node 1 | ||
n1 = Plasmo.add_node(sg1) | ||
@variable(n1, x >= 0) | ||
@variable(n1, y >= 0) | ||
@constraint(n1, ref1, x+y <= 10) | ||
@constraint(n1, ref1, n1[:x]+ n1[:y] <= 10) | ||
|
||
#node 2 | ||
n2 = Plasmo.add_node(sg1) | ||
@variable(n2, x >= 1) | ||
@variable(n2, y >= 2) | ||
@constraint(n2, ref2, x+y <= 4) | ||
@constraint(n2, ref2, n2[:x] + n2[:y] <= 4) | ||
|
||
# linking constraint | ||
# linking constraint on subgraph1 | ||
edge1 = Plasmo.add_edge(sg1, n1, n2) | ||
@constraint(edge1, ref_edge_1, n1[:x] == n2[:x]) | ||
|
||
sg2 = Plasmo.add_subgraph(graph; name=:sg2) | ||
# subgraph 2 | ||
sg2 = Plasmo.add_subgraph(graph; name=:sg2, optimizer_graph=graph) | ||
|
||
# node 3 | ||
n3 = Plasmo.add_node(sg2) | ||
@variable(n3, x >= 0) | ||
@variable(n3, y >= 0) | ||
@constraint(n3, ref3, x+y <= 10) | ||
@constraint(n3, ref3, n3[:x] + n3[:y] <= 10) | ||
|
||
#node 4 | ||
n4 = Plasmo.add_node(sg2) | ||
@variable(n4, x >= 1) | ||
@variable(n4, y >= 2) | ||
@constraint(n2, ref4, x+y <= 4) | ||
@constraint(n4, ref4, n4[:x] + n4[:y] <= 4) | ||
|
||
# linking constraint | ||
# linking constraint on subgraph2 | ||
edge2 = Plasmo.add_edge(sg2, n3, n4) | ||
@constraint(edge2, ref3, n3[:x] == n4[:x]) | ||
|
||
@constraint(edge2, ref_edge_2, n3[:x] == n4[:x]) | ||
|
||
# link across subgraphs | ||
edge3 = Plasmo.add_edge(graph, n2, n4) | ||
@constraint(edge3, ref_edge_3, n2[:y] == n4[:y]) | ||
|
||
@objective(graph, Min, n1[:x] + n2[:x] + n3[:x] + n4[:x]) | ||
# total objective function | ||
@objective(graph, Max, n1[:x] + n2[:x] + n3[:x] + n4[:x]) | ||
|
||
obj = objective_function(graph) | ||
|
||
set_optimizer(graph, HiGHS.Optimizer) | ||
optimize!(graph) | ||
|
||
# TODO: | ||
#@linkconstraint(graph, n1[:x] + n2[:x] == 2) | ||
@show value(n1[:x]) | ||
@show value(n2[:x]) | ||
@show value(n3[:x]) | ||
@show value(n4[:x]) | ||
@show value(n2[:y]) | ||
@show value(n4[:y]) | ||
|
||
# TODO: | ||
set_optimizer(graph, HiGHS.Optimizer) | ||
optimize!(graph) | ||
println(objective_value(graph)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using JuMP | ||
|
||
m = Model() | ||
@variable(m, x >= 0) | ||
@variable(m, y >= 0) | ||
@constraint(m, ref, x^3 + y^3 >= 0) | ||
|
Oops, something went wrong.