Applied Optimization with Julia
University of Hamburg
After this lecture, you will be able to:
Where is the
challenge?

Question: What could be the objective?
Minimize the combined setup and inventory holding cost while satisfying the demand and adhering to the production capacity.

Question: What is the trade-off?
Larger batches require less setup cost per bottle, but increase the storage cost.
Question: What are sets again?
Sets are collections of objects.
Question: What could be the sets here?
Question: What are possible parameters?
We have the following sets:
Our objective is to:
Minimize the combined setup and inventory holding cost while satisfying the demand and adhering to the production capacity.
Question: What could be our decision variable/s?
Our objective is to:
Minimize the combined setup and inventory holding cost while satisfying the demand and adhering to the production capacity.
Question: What could be our objective function?
We need the following variables:
We need the following parameters:
\[\text{Minimize} \quad \sum_{i \in \mathcal{I}} \sum_{t \in \mathcal{T}} (c_i \times W_{i,t} + f_i \times Y_{i,t})\]

Question: What constraints?
The goal of these constraints is to:
Consider the current inventory and batch sizes and compute the remaining inventory.
We need the following variables and parameters:
Question: What could the constraint look like?
\[W_{i,t-1} + X_{i,t} - W_{i,t} = d_{i,t} \quad \forall i\in\mathcal{I}, t\in\mathcal{T}\]
with \(W_{i,0} = 0\), as the warehouse starts empty.
Remember, these are the variables and parameters:
Question: Why do we have to fix \(W_{i,0} = 0\)?
Otherwise, the solver could invent free starting inventory and would never need to bottle anything for the first weeks!
The goal of these constraints is to:
Set up beer types in all periods where the batch size is \(>\) 0.
We need the following variables and parameters:
Question: What could the second constraint be?
\[X_{i,t} \leq Y_{i,t} \times \sum_{\tau \in \mathcal{T}} d_{i,\tau} \quad \forall i\in\mathcal{I}, t\in\mathcal{T}\]
Question: Do you know this type of constraint?
This type of constraint is called a “Big-M” constraint!
The goal of these constraints is to:
Limit the capacity of the bottling plant per period.
We need the following variables and parameters:
Question: What could the third constraint be?
It uses more parameters than the previous constraints, but it is easier to understand.
\[\sum_{i \in \mathcal{I}} (b_i \times X_{i,t} + g_i \times Y_{i,t}) \leq a_t \quad \forall t\in\mathcal{T}\]
And that’s basically it!
The complete model is known as the Capacitated Lot-Sizing Problem (CLSP).
\[\text{Minimize} \quad \sum_{i \in \mathcal{I}} \sum_{t \in \mathcal{T}} (c_i \times W_{i,t} + f_i \times Y_{i,t})\]
The goal of the objective function is to:
Minimize the combined setup and inventory holding cost while satisfying the demand and adhering to the production capacity.
\[W_{i,t-1} + X_{i,t} - W_{i,t} = d_{i,t} \quad \forall i\in\mathcal{I}, t\in\mathcal{T} \quad (W_{i,0} = 0)\]
\[X_{i,t} \leq Y_{i,t} \times \sum_{\tau \in \mathcal{T}} d_{i,\tau} \quad \forall i\in\mathcal{I}, t\in\mathcal{T}\]
\[\sum_{i \in \mathcal{I}} (b_i \times X_{i,t} + g_i \times Y_{i,t}) \leq a_t \quad \forall t\in\mathcal{T}\]
Our constraints ensure:
Demand is met, inventory transferred, setup taken care of, and capacity respected.
\[Y_{i,t}\in\{0,1\} \quad \forall i\in\mathcal{I},t\in\mathcal{T}\]
\[W_{i,t}, X_{i,t}\geq 0 \quad \forall i\in\mathcal{I},t\in\mathcal{T}\]
The variable domains make sure that:
The binary setup variable is either 0 or 1 and that the inventory and batch size are non-negative.
Question: Why is a continuous batch size acceptable here?
At this scale, rounding a batch of thousands of bottles changes the cost only marginally.
Question: How could we formulate the variables in Julia?
2-dimensional DenseAxisArray{JuMP.VariableRef,2,...} with index sets:
Dimension 1, ["IPA", "Lager", "Stout"]
Dimension 2, 0:3
And data, a 3×4 Matrix{JuMP.VariableRef}:
W[IPA,0] W[IPA,1] W[IPA,2] W[IPA,3]
W[Lager,0] W[Lager,1] W[Lager,2] W[Lager,3]
W[Stout,0] W[Stout,1] W[Stout,2] W[Stout,3]
Note, how we declare the inventory \(W\) also for period 0!
\[\text{Minimize} \quad \sum_{i \in \mathcal{I}} \sum_{t \in \mathcal{T}} (c_i \times W_{i,t} + f_i \times Y_{i,t})\]
We need the demand \(d_{i,t}\), capacity \(a_t\), and times \(b_i\), \(g_i\):
d = Dict( # Demand per beer type and week
"IPA" => [300, 800, 500],
"Lager" => [600, 500, 800],
"Stout" => [200, 300, 250],
)
a = [1800, 1800, 1800] # Capacity per week in minutes
b = Dict("IPA" => 0.9, "Lager" => 0.6, "Stout" => 1.2) # Min. per bottle
g = Dict("IPA" => 60, "Lager" => 40, "Stout" => 80) # Setup in minutesThe constraints map almost one-to-one from the math:
Status: OPTIMAL
Total cost: 28130.0
Of the 28,130 total cost, 28,000 are setup costs and only 130 are inventory holding costs — but what does the plan look like?
IPA X = [300, 1300, 0] W = [0, 500, 0]
Lager X = [600, 500, 800] W = [0, 0, 0]
Stout X = [750, 0, 0] W = [550, 250, 0]
There exist several types of optimization problems:
Questions: On model characteristics
Question: How small can we make M without cutting off solutions?
The smaller of the two is the tighter bound — and tighter formulations are usually solved faster!
Questions: On model assumptions
End-of-horizon effect
The model plans no inventory for demand after week \(|\mathcal{T}|\), as it does not know about it. In practice, this is solved by re-planning on a rolling horizon.
Can this be
applied?
Solving the problem with commercial solvers is not tractable, as it takes too long.
Our CLSP is the single-level core of this problem — the real case is multi-level, with semi-finished products and storage resources.
Any idea what
could be done?
And that’s it for today’s lecture!
We now have covered the basics of the CLSP and are ready to start solving some tasks in the upcoming tutorial.
Questions?
For more interesting literature to learn more about Julia, take a look at the literature list of this course.
Lecture V - Planning in Breweries | Dr. Tobias Vlćek | Home