Skip to content

Commit

Permalink
got quadratic working
Browse files Browse the repository at this point in the history
  • Loading branch information
jalving committed Jan 5, 2024
1 parent ed77656 commit aff115a
Show file tree
Hide file tree
Showing 9 changed files with 459 additions and 126 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
Expand Down
31 changes: 19 additions & 12 deletions src/dev1.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Plasmo
using HiGHS
# using HiGHS
using Ipopt

graph = OptiGraph(; name=:g1)

Expand All @@ -8,29 +9,35 @@ n1 = Plasmo.add_node(graph)
@variable(n1, y >= 0)
@constraint(n1, ref1, x+y <= 10)

# TODO: quadratic functions
@constraint(n1, refq, x^2 + y^2 <= 2)

n2 = Plasmo.add_node(graph)
@variable(n2, x >= 1)
@variable(n2, y >= 2)
@constraint(n2, ref2, x+y <= 4)

# linking constraint
edge1 = Plasmo.add_edge(graph, n1, n2)
@constraint(edge1, ref3, n1[:x] == n2[:x])

@objective(graph, Min, n1[:x] + n2[:x])
@constraint(edge1, ref3a, n1[:x] == n2[:x])
@constraint(edge1, ref3b, n1[:x]^2 + n2[:x]^2 <= 3)

obj = objective_function(graph)
#@objective(graph, Min, n1[:x] + n2[:x])# + n2[:x]^2)

@objective(graph, Min, n1[:x]^2 + n2[:x]^2)

# TODO:
#@linkconstraint(graph, n1[:x] + n2[:x] == 2)
obj = objective_function(graph)

# TODO:
set_optimizer(graph, HiGHS.Optimizer)
optimize!(graph)
# TODO linkconstraint macro:
# @linkconstraint(graph, n1[:x] + n2[:x] == 2)

# TODO: nonlinear
# TODO: nonlinear functions
# @constraint(n1, )

# TODO: build backend from multiple graphs

# TODO: hypergraph interface
# TODO: hypergraph interface

# set_optimizer(graph, HiGHS.Optimizer)
set_optimizer(graph, Ipopt.Optimizer)
optimize!(graph)
40 changes: 24 additions & 16 deletions src/dev2.jl
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))
7 changes: 7 additions & 0 deletions src/dev3.jl
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)

Loading

0 comments on commit aff115a

Please sign in to comment.