Help with JuMP extension

I am trying to tweak JuMP so that I can specify and query some more specific stuff that I can not currently do with inbuilt JuMP functions and macros. See the example below:

First, I want to specify the ‘kind’ of variable I am defining. For example, in the snippet below, x[1:2] are stage-1 variables, and y[1:5] are stage-2 variables. So, I want to be able to specify these ‘kinds’ when declaring the variables. I understand one way is to do is as shown here; however, I would also be want to able to retrieve the variables of particular ‘kind’ later, and of course, solve a JuMP model with these new variables involved. See the code snippet below; it summarizes what I am trying to do.

using JuMP
model = Model(CPLEX.Optimizer)

#Be able to declare the 'kind' of variable
@variable(model, x[1:2] >= 0, stage1)
@variable(model, y[1:5] >= 0, stage2)

#Be able to retrieve the variable and their 'kind'
stage1_var(model)  #should return x[1], x[2]
stage2_var(model)  #should return y[1],..., y[5]

@constraint(model, x[1]+y[3] <= 3)
@constraint(model, x[2]+y[5] <= 10)

@objective(model, Min, sum(x[i] for i=1:2) + sum(y[i] for i=1:5))

#Be able to solve a JuMP model with the above 'new' type of variables defined

Additionally, after solving this model, I would want to use this JuMP model variables (not their values) in another JuMP model with additional variables and constraints. How do I ‘transfer’ these variables from one model to another?

Can someone guide me on how to proceed with this, and what would be a good approach to achieve this? Any help is appreciated.
I have used JuMP to solve models before, but I am very new to extending JuMP models. I have found myself spending lots of time reading other packages and documentation. While I continue to do so, I would really appreciate ideas and feedback from people who have worked extensively with these kinds of problems. Thanks a lot!

1 Like

Hi, and welcome to Julia Discourse!

It looks like you are trying to build/solve stochastic optimization problems.
If your goal is to do that, and not to build an entire JuMP extension around it, I can point you to existing JuMP extensions that cater to stochastic optimization.

For instance:

  • StochasticPrograms (see this example). I believe the name is explicit enough :slight_smile:
  • ParameterJuMP allows you to tag certain variables as parameter, which are automatically processed before passing the model to the solver.

If your goal is to build a new JuMP extension, then more involved JuMP developers will be more knowledgeable than me about how to go about that.


Hi @mtanneau,

Thanks for the references. Yes, I am working with stochastic programs (but not just trying to build/solve them), and actually currently trying to understand the StochasticPrograms.jl as it seems the closest to what I am trying to achieve. Also, I never came across ParameterJuMP, but it looks interesting, and maybe I could borrow some ideas from there.

That being said, I am actually trying to build a JuMP extension, so it goes without saying I need to understand all the machinery and workflow techniques. I hope I get some help here. :slight_smile:

1 Like

These references can possibly give me a good start, especially the SDDP reference you gave. I will spend some time analyzing these codes, and see if I have further questions. Thank you.

With Plasmo.jl you can define a network of models for such applications.


Thanks @bbrunaud for directing me to Plasmo.jl. It looks interesting. I will take a deeper look into it.

I wrote PlasmoAlgorithms.jl automated decomposition algorithms starting from Plasmo model graphs

1 Like

Thanks for the reference!