StructJuMPSolverInterface defines the nonlinear solver interface for StructJuMP--the Structured Modeling Extension for JuMP and provides glue code for PIPS and IPOPT solvers.
PIPS parallel interface ("PipsNlp") matches StructJuMP's paralel capabilities. The two offer a truly parallel modeling + solving environment. In addition, PIPS also has a serial interface ("PipsNlpSerial"), which is used mostly for debugging purposes. The Ipopt interface to StructJuMP is also serial.
Declaring the root stage variables and constraints.
using StructJuMP, JuMP
using StructJuMPSolverInterface
scen = 3
m = StructuredModel(num_scenarios=scen)
@variable(m, x[1:2])
@NLconstraint(m, x[1] + x[2] == 100)
@NLobjective(m, Min, x[1]^2 + x[2]^2)
Declaring the second stage variables and constraints.
for(i in getLocalChildrenIds(m))
bl = StructuredModel(parent=m,id=i)
@variable(bl, y[1:2])
@NLconstraint(bl, x[1] + y[1]+y[2] ≥ 0)
@NLconstraint(bl, x[1] + y[1]+y[2] ≤ 50)
@NLobjective(bl, Min, y[1]^2 + y[2]^2)
end
At this point, m
is a two level model that has a single root node, or block and 3
children nodes. The model can be solved by calling solve
function with a parameter solver
equal to one of the known solvers, "PipsNlp", "PipsNlpSerial"
or "Ipopt"
.
solve(m,solver="PipsNlp") #solving using parallel PIPS-NLP solver
getLocalBlocksIds(m)
returns a vector of block IDs residing on the current MPI rank.getLocalChildrenIds(m)
returns a vector of children scenario IDs residing on the current MPI rank.
@show getLocalChildrenIds(m)
@show getLocalBlocksIds(m)
getModel(m,id)
returns the block with specified byid
. The root block by default has the ID equals to 0.
mm = getModel(m,1) # mm is now the 1st scenario node.
getVarValues(m,id)
returns the variable values vector for blockid
.
v = getVarValues(m,1) # v is holding the variable values of 1st scenario.
getVarValue(m,id,var_idx)
returns value of the variable indexed byvar_idx
in the blockid
.
a = getVarValue(m,1,2) #a is the 2nd variable value of block id # 1.
getNumVars
andgetNumCons
return the number of variables and constraints of blockid
.getTotalNumVars
andgetTotalNumCons
return the total number of variables and constraints of the problem. The parameterm
needs to point to the root block.
@show getNumVars(m,id)
@show getNumCons(m,id)
@show getTotalNumVars(m)
@show getTotalNumCons(m)
getObjectiveVal
returns the value of objective.
@show getObjectiveVal(m)
- Variables in the structural blocks needs to be declared before the constraint declarations.