Skip to content

Commit e4458df

Browse files
committed
fix formatting
1 parent c03f30b commit e4458df

File tree

7 files changed

+43
-28
lines changed

7 files changed

+43
-28
lines changed

examples/optigraph_2_nodes.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@ n1 = @optinode(graph)
88
n2 = @optinode(graph)
99

1010
#Node 1 Model
11-
@variable(n1,0 <= x <= 2)
12-
@variable(n1,0 <= y <= 3)
11+
@variable(n1, 0 <= x <= 2)
12+
@variable(n1, 0 <= y <= 3)
1313
@variable(n1, z >= 0)
14-
@constraint(n1,x+y+z >= 4)
14+
@constraint(n1, x + y + z >= 4)
1515

1616
#Node 2 Model
17-
@variable(n2,x)
18-
@variable(n2,z >= 0)
19-
@constraint(n2,z + x >= 4)
17+
@variable(n2, x)
18+
@variable(n2, z >= 0)
19+
@constraint(n2, z + x >= 4)
2020

2121
#Link constraints take the same expressions as the JuMP @constraint macro
22-
@linkconstraint(graph,n1[:x] == n2[:x])
23-
@linkconstraint(graph,n1[:z] == n2[:z])
22+
@linkconstraint(graph, n1[:x] == n2[:x])
23+
@linkconstraint(graph, n1[:z] == n2[:z])
2424

2525
#Objective function
26-
@objective(graph,Min,n1[:y] + n2[:x] + n1[:z])
26+
@objective(graph, Min, n1[:y] + n2[:x] + n1[:z])
2727

2828
#Optimize with glpk.
2929
optimizer = GLPK.Optimizer
30-
set_optimizer(graph,optimizer)
30+
set_optimizer(graph, optimizer)
3131
optimize!(graph)
3232

3333
#Get results
@@ -36,16 +36,16 @@ println("objective value = ", objective_value(graph))
3636

3737
println()
3838
println("variable values:")
39-
println("n1[:z] = ",value(n1[:z]))
40-
println("n2[:z] = ",value(n2[:z]))
41-
println("n1[:x] = ",value(n1[:x]))
42-
println("n1[:y] = ",value(n1[:y]))
43-
println("n2[:x] = ",value(n2[:x]))
39+
println("n1[:z] = ", value(n1[:z]))
40+
println("n2[:z] = ", value(n2[:z]))
41+
println("n1[:x] = ", value(n1[:x]))
42+
println("n1[:y] = ", value(n1[:y]))
43+
println("n2[:x] = ", value(n2[:x]))
4444

4545
println()
4646
println("dual values on nodes:")
4747
for constraint_type in list_of_constraint_types(graph)
48-
cons = all_constraints(graph,constraint_type[1],constraint_type[2])
48+
cons = all_constraints(graph, constraint_type[1], constraint_type[2])
4949
for con in cons
5050
println("($con) = $(dual(con))")
5151
end

src/Plasmo.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ export
8989
hierarchical_edges_not_global,
9090
global_edges,
9191
graph_depth,
92-
9392
aggregate,
9493
aggregate!,
9594

src/moi_backend_graph.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,16 @@ function MOI.optimize!(graph_backend::GraphBackend)
273273
MOI.optimize!(graph_backend.optimizer)
274274
return nothing
275275
end
276+
277+
function MOIU.reset_optimizer(graph_backend::GraphBackend)
278+
MOI.empty!(graph_backend.optimizer)
279+
# delete graph backend from all nodes
280+
graph = graph_backend.optigraph
281+
for node in all_nodes(graph_backend.optigraph)
282+
nb = JuMP.backend(node)
283+
filter!(x -> x != graph.id, nb.graph_ids)
284+
delete!(nb.optimizers, graph.id)
285+
end
286+
graph_backend.state = MOIU.EMPTY_OPTIMIZER
287+
return nothing
288+
end

src/optigraph.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -642,17 +642,17 @@ end
642642

643643
function JuMP.set_objective_function(graph::OptiGraph, expr::JuMP.GenericAffExpr)
644644
graph.objective_function = expr
645-
return
645+
return nothing
646646
end
647647

648648
function JuMP.set_objective_function(graph::OptiGraph, expr::JuMP.GenericQuadExpr)
649649
graph.objective_function = expr
650-
return
650+
return nothing
651651
end
652652

653653
function set_node_objective_functions(graph::OptiGraph)
654654
_set_node_objective_functions(graph, objective_function(graph))
655-
return
655+
return nothing
656656
end
657657

658658
function _set_node_objective_functions(graph::OptiGraph, expr::JuMP.GenericAffExpr)
@@ -667,7 +667,7 @@ function _set_node_objective_functions(graph::OptiGraph, expr::JuMP.GenericAffEx
667667
for node in all_nodes(graph)
668668
JuMP.set_objective_function(node, node_expressions[node])
669669
end
670-
return
670+
return nothing
671671
end
672672

673673
function _set_node_objective_functions(graph::OptiGraph, expr::JuMP.GenericQuadExpr)
@@ -687,7 +687,7 @@ function _set_node_objective_functions(graph::OptiGraph, expr::JuMP.GenericQuadE
687687
for node in all_nodes(graph)
688688
JuMP.set_objective_function(node, node_expressions[node])
689689
end
690-
return
690+
return nothing
691691
end
692692

693693
"""

src/optimizer_interface.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ function MOIU.attach_optimizer(graph::OptiGraph)
175175
return MOIU.attach_optimizer(backend(graph))
176176
end
177177

178+
function MOIU.reset_optimizer(graph::OptiGraph)
179+
return MOIU.reset_optimizer(backend(graph))
180+
end
181+
178182
#################################
179183
# Optimizer
180184
#################################

test/optiedge.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ function test_optiedge_1()
5757
@test num_nodes(link_con) == 2
5858

5959
@test Base.string(e1) == "OptiEdge w/ 1 Constraint(s)"
60-
@test JuMP.constraint_string(MIME("text/latex"), link_ref) ==
61-
"ref: n4[:x] - n1[:x] = 0"
60+
@test JuMP.constraint_string(MIME("text/latex"), link_ref) == "ref: n4[:x] - n1[:x] = 0"
6261
@test JuMP.constraint_string(MIME("text/latex"), link_con) == "n4_{:x} - n1_{:x} = 0"
6362
@test Base.string(link_con) ==
6463
"LinkConstraint: n4[:x] - n1[:x], MathOptInterface.EqualTo{Float64}(0.0)"

test/optigraph.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,12 @@ function test_multiple_graphs()
284284
expanded_subgraphs = Plasmo.expand.(graph, subs, 1)
285285

286286
set_optimizer(
287-
expanded_subgraphs[1],
288-
optimizer_with_attributes(Ipopt.Optimizer, "print_level" => 0)
287+
expanded_subgraphs[1],
288+
optimizer_with_attributes(Ipopt.Optimizer, "print_level" => 0),
289289
)
290290
set_optimizer(
291-
expanded_subgraphs[2],
292-
optimizer_with_attributes(Ipopt.Optimizer, "print_level" => 0)
291+
expanded_subgraphs[2],
292+
optimizer_with_attributes(Ipopt.Optimizer, "print_level" => 0),
293293
)
294294

295295
middle_link = graph.optiedges[1].linkrefs[1]

0 commit comments

Comments
 (0)