print("Hello World!")Hello World!
Applied Optimization with Julia
. . .
I really appreciate active participation and interaction!
After today, you will be able to:
. . .
Bonus points only count if the exam is passed (4.0 or better)!
. . .
We are also happy to supervise Bachelor and Master theses!

. . .
Question: Have you ever heard of Julia?
. . .
Allows for fast data workflows, particularly in scientific computing!
. . .
JuMP is an alternative to Pyomo, GAMS, and AMPL!
. . .
. . .
Modeling is a creative process!
. . .
We will go through these components step by step in each lecture!
\[ \begin{aligned} &\text{Maximize} \quad F = \sum_{j\in \mathcal{J}} c_j \times X_j \end{aligned} \]
subject to
\[ \begin{aligned} &\sum_{j\in \mathcal{J}} a_{i,j} \times X_j \le b_i && \forall i \in \mathcal{I} \\ &X_j \ge 0 && \forall j \in \mathcal{J} \end{aligned} \]
\[ \begin{aligned} \mathcal{I} &: \text{set of resources, indexed by } i,\\ \mathcal{J} &: \text{set of activities, indexed by } j,\\ F &: \text{Objective function variable,}\\ X_{j} &: \text{decision variables,}\\ c_{j} &: \text{objective function coefficients,}\\ a_{i,j} &: \text{parameters,}\\ b_{i} &: \text{parameters} \end{aligned} \]
. . .
Question: Have you ever seen something like this before?
We’ve just seen the general structure:
. . .
Now let’s see how this works with a real problem!
. . .
Watch for these components as we build our first model together.
A company is producing solar panels in Dresden and Laupheim and has to transport them to new solar farms near Hamburg, Munich, and Berlin. The quantities offered and demanded (truckloads) and the transport costs per truckload in Euro are summarized in the following table.
| Origin/Destination | Hamburg | Munich | Berlin | Available |
|---|---|---|---|---|
| Dresden | 5010 | 4640 | 1980 | 34 |
| Laupheim | 7120 | 1710 | 6430 | 41 |
| Demand | 21 | 17 | 29 |
Example: A truckload from Dresden \(i=1\) to Munich \(j=2\) costs \(c_{1,2}=4640\) Euro. Moreover, it is necessary to fulfil all customer demands, as the contract has been signed.

First, we always need to understand the objectives.
. . .
Question: What are our possible objectives?
Minimizing the transport costs over all truckloads while meeting the demand within the available supply.
Remember, sets are collections of elements
. . .
Question: What sets are needed?
. . .
\[ \begin{aligned} \mathcal{I} &: \text{Set of production sites, indexed by } i \text{ with } i \in \{1, \ldots, |\mathcal{I}|\}, \\ \mathcal{J} &: \text{Set of customers, indexed by } j \text{ with } j \in \{1, \ldots, |\mathcal{J}|\}. \end{aligned} \]
. . .
We often use plural names for sets and a calligraphic letter, e.g., \(\mathcal{I}\) and \(\mathcal{J}\).
Parameters are fixed values that are given.
. . .
Question: What parameters are needed?
. . .
\[ \begin{aligned} c_{i,j} &: \text{Costs per truck load for transport from } i \text{ to } j, \\ a_i &: \text{Available truck loads at } i, \\ b_j &: \text{Customer demands at } j. \end{aligned} \]
. . .
We usually use the corresponding lower-case letter, e.g., \(c\), \(a\), and \(b\).
. . .
Question: What decision variables are needed?
. . .
\[ X_{i,j} : \text{Trucks that deliver panels from site } i \text{ to customer } j. \]
. . .
We use upper-case letters to distinguish variables from parameters, e.g., \(X\).
. . .
Question: Do you remember the objective?
Minimize the transport costs over all truckloads while meeting customer demand within the available supply from production sites.
. . .
Question: How can we write this down?
. . .
\[ \text{Minimize} \quad \sum_{i \in \mathcal{I}} \sum_{j \in \mathcal{J}} c_{i,j} \times X_{i,j} \]
Question: Objective value without the supply and demand constraints?
. . .
. . .
Question: What constraints are needed?
Ensure that the number of panels transported from a location does not exceed the available panels.
. . .
Question: How can we formalize this?
. . .
\[ \sum_{j \in \mathcal{J}} X_{i,j} \leq a_i \quad \forall i \in \mathcal{I} \]
Ensure that the demand of each customer is covered.
. . .
Question: Any ideas?
. . .
\[ \sum_{i \in \mathcal{I}} X_{i,j} = b_j \quad \forall j \in \mathcal{J} \]
Ensure no negative number of truckloads are transported.
. . .
Question: Does anyone have an idea how to write this down?
. . .
\[ X_{i,j} \geq 0 \quad \forall i \in \mathcal{I}, \forall j \in \mathcal{J} \]
The complete model can then be written as:
\[ \begin{aligned} \text{Minimize} \quad F &= \sum_{i \in \mathcal{I}} \sum_{j \in \mathcal{J}} c_{i,j} \times X_{i,j} \\ \text{subject to:} \quad &\sum_{j \in \mathcal{J}} X_{i,j} \leq a_i \quad &&\forall i \in \mathcal{I} \\ &\sum_{i \in \mathcal{I}} X_{i,j} = b_j \quad &&\forall j \in \mathcal{J} \\ &X_{i,j} \geq 0 \quad &&\forall i \in \mathcal{I}, \forall j \in \mathcal{J} \end{aligned} \]
Question: Could we replace \(=\) by \(\geq\) in the demand constraint?
. . .
. . .
Question: Why won’t we transport more than the demand?
. . .
| Route | Truckloads | Cost |
|---|---|---|
| Dresden → Hamburg | 5 | 25,050 |
| Dresden → Berlin | 29 | 57,420 |
| Laupheim → Hamburg | 16 | 113,920 |
| Laupheim → Munich | 17 | 29,070 |
The minimal total cost is 225,460 Euro.
. . .
In a few weeks, you will compute this solution yourself — with just a few lines of Julia code!
Unfortunately, the margins on solar panels are low. After the previous contract has been fulfilled, the company will produce the same number of panels as before. In addition, all three customers want to order the same number of truckloads with solar panels again. The revenue per truckload of panels is 11,000 Euros. The complete production of a truckload of solar panels, including materials, costs 6,300 Euros.
In the new contract, the company wants to maximize its profits while the demand does not have to be fulfilled.
. . .
Question: What changes are necessary?
. . .
. . .
Question: Does our decision variable change?
. . .
\[ \begin{aligned} r &: \text{Revenue per truckload of solar panels,} \\ k &: \text{Production costs per truckload of solar panels.} \end{aligned} \]
. . .
We use \(k\) here, as \(c_{i,j}\) already stands for the transport costs!
. . .
Question: What is the profit per truckload of solar panels?
. . .
\[ p = r - k \]
\[ \begin{aligned} \text{Minimize} \quad F &= \sum_{i \in \mathcal{I}} \sum_{j \in \mathcal{J}} c_{i,j} \times X_{i,j} \\ \text{subject to:} \quad &\sum_{j \in \mathcal{J}} X_{i,j} \leq a_i \quad &&\forall i \in \mathcal{I} \\ &\sum_{i \in \mathcal{I}} X_{i,j} = b_j \quad &&\forall j \in \mathcal{J} \\ &X_{i,j} \geq 0 \quad &&\forall i \in \mathcal{I}, \forall j \in \mathcal{J} \end{aligned} \]
. . .
Question: What do we need to change here?
\[ \begin{aligned} \text{Maximize} \quad F &= \sum_{i \in \mathcal{I}} \sum_{j \in \mathcal{J}} (p-c_{i,j}) \times X_{i,j} \\ \text{subject to:} \quad &\sum_{j \in \mathcal{J}} X_{i,j} \leq a_i \quad &&\forall i \in \mathcal{I} \\ &\sum_{i \in \mathcal{I}} X_{i,j} \leq b_j \quad &&\forall j \in \mathcal{J} \\ &X_{i,j} \geq 0 \quad &&\forall i \in \mathcal{I}, \forall j \in \mathcal{J} \end{aligned} \]
Question: One customer will not receive a single panel. Who and why?
. . .
. . .
| Route | Truckloads | Profit |
|---|---|---|
| Dresden → Berlin | 29 | 78,880 |
| Laupheim → Munich | 17 | 50,830 |
| → Hamburg | 0 | 0 |
The maximal profit is 129,710 Euro.
. . .
With the former \(=\) demand constraint, the model would be forced into the unprofitable deliveries to Hamburg!
Take a moment to think about what we just built:
How many decision variables does this problem have?
\(|\mathcal{I}| \times |\mathcal{J}| = 2 \times 3 = 6\) variables
Each represents a shipping route from a production site to a customer.
What happens if we add more production sites?
The number of variables grows as \(|\mathcal{I}| \times |\mathcal{J}|\)
What real-world factors are we ignoring?
How would the model change for different scenarios?
\(X_{i,j} \geq 0\) also allows fractional truckloads. Is that a problem?
Modeling Process:
Key Insights:
. . .
This systematic approach works for any optimization problem!

To prepare for the upcoming lectures, we start by installing the Julia Programming Language and an Integrated Development Environment (IDE) to work with Julia.

juliaup. . .
If you are ever asked to add something to your “PATH”, do so!

. . .
Any problems? Ask me for help!
print("Hello World!")Hello World!
. . .
Hello World! → perfect!. . .
Don’t worry if it is not running right away. We will fix this together!
Before the next lecture, try to ensure you can:
. . .
Having trouble? We will fix your issues together in the next lecture!
. . .
And that’s it for today’s lecture!
We now have covered a first introduction and are ready to start solving some problems in the upcoming lectures.
For interesting literature to learn more about Julia, take a look at the literature list of this course.