Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Aug 27, 2024
1 parent 96997ab commit 8995775
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
26 changes: 13 additions & 13 deletions docs/src/tutorials/getting_started/sum_if.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,19 @@ model = Model()
model = Model()
@variable(model, flows[e in edges] >= 0)
for n in nodes
flow_out = AffExpr(0.0)
for (i, j) in edges
if i == n
add_to_expression!(flow_out, flows[(i, j)])
end
end
flow_in = AffExpr(0.0)
for (i, j) in edges
if j == n
add_to_expression!(flow_in, flows[(i, j)])
end
end
@constraint(model, flow_out - flow_in == demand(n))
flow_out = AffExpr(0.0)
for (i, j) in edges
if i == n
add_to_expression!(flow_out, flows[(i, j)])
end
end
@constraint(model, flow_in - flow_out == demand(n))
end

# This formulation includes two for-loops, with a loop over every edge (twice) for
Expand All @@ -133,8 +133,8 @@ function build_naive_model(nodes, edges, demand)
@constraint(
model,
[n in nodes],
sum(flows[(i, j)] for (i, j) in edges if i == n) -
sum(flows[(i, j)] for (i, j) in edges if j == n) == demand(n)
sum(flows[(i, j)] for (i, j) in edges if j == n) -
sum(flows[(i, j)] for (i, j) in edges if i == n) == demand(n)
)
return model
end
Expand Down Expand Up @@ -179,8 +179,8 @@ model = Model()
@constraint(
model,
[n in nodes],
sum(flows[(n, j)] for j in out_nodes[n]) -
sum(flows[(i, n)] for i in in_nodes[n]) == demand(n)
sum(flows[(i, n)] for i in in_nodes[n]) -
sum(flows[(n, j)] for j in out_nodes[n]) == demand(n)
);

# The benefit of this formulation is that we now loop over `out_nodes[n]`
Expand All @@ -202,8 +202,8 @@ function build_cached_model(nodes, edges, demand)
@constraint(
model,
[n in nodes],
sum(flows[(n, j)] for j in out_nodes[n]) -
sum(flows[(i, n)] for i in in_nodes[n]) == demand(n)
sum(flows[(i, n)] for i in in_nodes[n]) -
sum(flows[(n, j)] for j in out_nodes[n]) == demand(n)
)
return model
end
Expand Down
2 changes: 2 additions & 0 deletions docs/styles/config/vocabularies/JuMP/accept.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Geomstats
Geoopt
GLPK
(Gurobi|GUROBI)
gurobipy
GZip
Hypatia
(Ipopt|IPOPT)
Expand All @@ -158,6 +159,7 @@ Pavito
Penbmi
Penopt
Plasmo
Pyomo
puzzlor
RAPOSa
Riemopt
Expand Down

0 comments on commit 8995775

Please sign in to comment.