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

**URL:** https://discourse.julialang.org/t/writing-a-simple-production-scheduling-optimal-control-problem-in-jump/17748
**Category:** Optimization (Mathematical)
**Created:** [November 19, 2018, 7:40pm UTC](https://discourse.julialang.org/t/writing-a-simple-production-scheduling-optimal-control-problem-in-jump/17748 "2018-11-19T19:40:44Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![rotsoc](https://avatars.discourse-cdn.com/v4/letter/r/b2d939/32.png) [@rotsoc](https://discourse.julialang.org/u/rotsoc)
#### Post date: [November 19, 2018, 7:40pm UTC](https://discourse.julialang.org/t/writing-a-simple-production-scheduling-optimal-control-problem-in-jump/17748/1 "2018-11-19T19:40:44Z")

</div>

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:

```julia
# 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:

 ![img1](https://global.discourse-cdn.com/julialang/original/3X/6/2/62518237643285e6622370e8bd2bcb661cbb3f3e.jpeg)  
which we can discretize as:  
 ![img2](https://global.discourse-cdn.com/julialang/original/3X/c/5/c58a283d678868b953035100cf3829e167c73665.jpeg)

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:

```julia
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:

```julia
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.

---

<div class="post-metadata">

### Author: ![miles.lubin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miles.lubin/32/279_2.png) [@miles.lubin](https://discourse.julialang.org/u/miles.lubin)
#### Post date: [November 19, 2018, 9:34pm UTC](https://discourse.julialang.org/t/writing-a-simple-production-scheduling-optimal-control-problem-in-jump/17748/2 "2018-11-19T21:34:18Z")

</div>

> [@rotsoc](#):
>
> Am I missing something essential about JuMP? This is the first time I am using it.

Welcome to JuMP 🙂

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.

---

<div class="post-metadata">

### Author: ![rotsoc](https://avatars.discourse-cdn.com/v4/letter/r/b2d939/32.png) [@rotsoc](https://discourse.julialang.org/u/rotsoc)
#### Post date: [November 20, 2018, 12:32pm UTC](https://discourse.julialang.org/t/writing-a-simple-production-scheduling-optimal-control-problem-in-jump/17748/3 "2018-11-20T12:32:34Z")

</div>

> [@miles.lubin](#):
>
> Welcome to JuMP 🙂

Thank you 🙂

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

```julia
using JuMP
using Clp

solver = Clp.Optimizer

m=Model(with_optimizer(solver))

```

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

---

<div class="post-metadata">

### Author: ![miles.lubin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miles.lubin/32/279_2.png) [@miles.lubin](https://discourse.julialang.org/u/miles.lubin)
#### Post date: [November 20, 2018, 1:53pm UTC](https://discourse.julialang.org/t/writing-a-simple-production-scheduling-optimal-control-problem-in-jump/17748/4 "2018-11-20T13:53:36Z")

</div>

The JuMP README has links to the [documentation](http://www.juliaopt.org/JuMP.jl/0.18/) and [examples](https://github.com/JuliaOpt/JuMP.jl/tree/release-0.18/examples) for the latest release.

---

<div class="post-metadata">

### Author: ![rotsoc](https://avatars.discourse-cdn.com/v4/letter/r/b2d939/32.png) [@rotsoc](https://discourse.julialang.org/u/rotsoc)
#### Post date: [November 20, 2018, 2:31pm UTC](https://discourse.julialang.org/t/writing-a-simple-production-scheduling-optimal-control-problem-in-jump/17748/5 "2018-11-20T14:31:18Z")

</div>

Ok! Thank you
