Skip to content

StructJuMP/StructJuMPSolverInterface.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StructJuMPSolverInterface

StructJuMP's Solver Interface

StructJuMPSolverInterface provides the NLP solver interface and glue code for StructJuMP, which is an extension of JuMP for structured optimization problems such as stochastic optimization problems. StructJuMPSolverInterface supports PIPS and IPOPT NLP solvers.

PIPS parallel interface ("PipsNlp") matches StructJuMP's paralel capabilities. The two offer a truly parallel modeling + solving environment. In addition, StructJuMPSolverInterface provides an PIPS serial interface ("PipsNlpSerial"), which is used mostly for debugging purposes, and an Ipopt interface to StructJuMP, which is also serial.

Installation

Pkg.clone("https://github.com/StructJuMP/StructJuMPSolverInterface.jl")

An Example

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

Exposed API functions

  • 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 by id. 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 block id.
v = getVarValues(m,1) # v is holding the variable values of 1st scenario.
  • getVarValue(m,id,var_idx) returns value of the variable indexed by var_idx in the block id.
a = getVarValue(m,1,2) #a is the 2nd variable value of block id # 1. 
  • getNumVars and getNumCons return the number of variables and constraints of block id.
  • getTotalNumVars and getTotalNumCons return the total number of variables and constraints of the problem. The parameter m 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)

Known Limitation

  • Variables in the structural blocks needs to be declared before the constraint declarations.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages