Writing a simple production scheduling (optimal control) problem in JuMP

Hi! I am working through the introductory exercises of “Linear Programming & Network Flows” by Bazaraa et.al by writing and solving them as JuMP programs. Actually, my question is about an example from the Introduction.

The problem is basically this:

# A company wishes to determine the production rate over the planning
# horizon of the next T weeks such that the known demand is satisfied
# and the total production and inventory cost is minimized.

and the mathematical formulation is:


which we can discretize as:

and this is the linear program I am trying to write.
To be honest, I haven’t tried a lot to do this, but I got this far:

using JuMP
using Clp


m=Model(with_optimizer(Clp.Optimizer))

T = 4 # 4 weeks horizon

@expression(m, g[t=0:T], -t+5)

@variable(m, 0 <= x[0:T] <= 0.8)
@variable(m, 0 <= y[0:T] <= 0.9, start=0.0)

@objective(m, Min, 2*sum(x) + 3*sum(y))

@constraint(m, [t in 0:(T-1)], y[t+1] == y[t] + (x[t+1] - g[t+1]))

JuMP.optimize!(m)

println("Objective value: ", JuMP.objective_value(m))

where I didn’t really discretize time (or discretized it in 1-year intervals…) but I still got an error:

ERROR: LoadError: KeyError: key MathOptInterface.VariableIndex(1) not found

Is this something that can be easily corrected? Am I missing something essential about JuMP? This is the first time I am using it.

Welcome to JuMP :slight_smile:

It looks like you’re using 0.19-alpha which is not recommended if you’re a first-time JuMP user. Please use the latest release (0.18.4) instead. This is the version you’ll get by default from ] add JuMP. The error you’re seeing is a know issue with the alpha release.

Thank you :slightly_smiling_face:

I downgraded to v.0.18.4 but it seems that the examples I’ve seen in the documentation use 0.19 syntax…
I guess I’m asking if someone could point me to some examples that I could use… thanks!
For instance when I write

using JuMP
using Clp

solver = Clp.Optimizer

m=Model(with_optimizer(solver))

I get ERROR: LoadError: UndefVarError: with_optimizer not defined error.

The JuMP README has links to the documentation and examples for the latest release.

2 Likes

Ok! Thank you