Stochastic Programming Assignment 2023
Stochastic Programming Assignment 2023
UNIVERSITY OF TECHNOLOGY
FACULTY OF COMPUTER SCIENCE AND ENGINEERING
Assignment
Contents
Member list & Workload 3
1 Theoretical basis 4
1.1 Introduction to Stochastic Programming and Optimization . . . . . . . . . . . . 4
1.2 Stochastic linear programming (SLP) . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2.1 Wait-and-see approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2.2 No waiting approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3 One-Stage Stochastic linear programming - No Recourse (1-SLP) . . . . . . . . . 5
1.3.1 APPROACH 1. Use Chance constraint and Acceptable risk . . . . . . . . 6
1.3.2 APPROACH 2. For stochastic constraints T (α) ≤ h(α) . . . . . . . . . . 6
1.4 Generic Stochastic Programming with Recourse . . . . . . . . . . . . . . . . . . . 6
1.5 Two-Stage Stochastic linear programming with Recourse . . . . . . . . . . . . . . 7
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 1/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
4 Conclusion - Appreciation 33
5 Appendix 33
References 37
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 2/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 3/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
1 Theoretical basis
1.1 Introduction to Stochastic Programming and Optimization
Stochastic programming is a framework for modelling optimization problems that involve un-
certainty. Whereas deterministic optimization problems are formulated with known parameters,
real world problems almost invariably include some unknown parameters. When the parameters
are known only within certain bounds, one approach to tackling such problems is called robust
optimization. Here the goal is to find a solution which is feasible for all such data and optimal
in some sense. Stochastic programming models are similar in style but take advantage of the
fact that probability distributions governing the data are known or can be estimated. The goal
here is to find some policy that is feasible for all (or almost all) the possible data instances and
maximizes the expectation of some function of the decisions and the random variables.
Briefly, Stochastic programming can be viewed as mathematical programming with random
parameters (e.g., random variables, the variables whose possible values depend on the outcomes
of a chance phenomenon). The existence of random variables in the model being considered will
open up countless ways to pose different problems, reflecting various aspects of the issue being
addressed.
With x = (x1 , x2 , . . . , xn ) are called decision variables, certain matrix A and vector B (for deter-
ministic constraints), and with random parameters T, h in T x ≥ h define chance or probabilistic
constraints.
Oftentimes, decision variables x is dependent on random vector ω, which partially represents
for data uncertainty of the problem. How do we solve this problem, if w is really random variable?
Suppose it is possible to decide about the decision variables x after the observation of the
random vector ω. After having observed the random vector ω, we can solve the problem with
the decision variables vector x being clearly determined.
In this approach, we need to decide on x before knowing the values of ω. There are 2 main
ways to do it: (a) Guess at uncertainty, (b) Probabilistic Constraints.
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 4/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
(a) Guess at uncertainty: We will guess few reasonable values for ω. Three main ways
are:
Definition 1 Consider the following program LP (α) that is parameterized by the random vector
α:
Pn
Minimize z = g (x) = f (x) = cT x = j=1 cj xj
1. Matrix T = T (α) and (vector) h = h(α) express uncertainty via stochastic constraints.
2. Values (T, h) not known: they are unknown before an instance of model occurs, h(α) de-
pends only on random aj .
Fundamental assumption. We know a (joint) probability distribution of data. Hence the first
approach gives Probabilistic (Chance) Constraint LP.
The Scenario Analysis. Not perfect, but useful, is the second approach. The scenario ap-
proach assumes that there are a finite number of decisions that nature can make (outcomes of
randomness). Each of these possible decisions is called a scenario.
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 5/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
The chance constraint T x ≤ h implies that the acceptable risk rx is less than a specified
maximal 1 − p ∈ (0, 1).
Note: we use parameter vectorα = [α1 , α2 , ...] in general, and denote ω = [ω1 , ω2 , ..., ωS ]
specifically for states s called scenarios.
This kind of program targets a specific linear objective while accounting for a probability
function associated with various scenarios. Hence, we find an overall solution by looking at the
scenario solutions xs (s = 1, ..., S).
Advantage: each scenario problem is an LP.
Disadvantage: discrete distribution →
− mixed-integer LP model.
where x = (x1 , x2 , . . . , xn ) is the first stage decision variables, f (x) can be linear or not, a part
of the grand objective function g(x).
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 6/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
Vectors α = α(ω) and y = y(ω) are named correction, tuning or recourse decision variables,
only known after the experiment e.
Briefly we minimize total expected costs g(x) = f (x) + Q(x) while satisfying W · y(ω) =
h(ω) − T (ω) · x.
Here W is called m × p recourse matrix, and we begin with simple case of m = 1, q is the
unit recourse cost vector, having the same dimension as y, and y = y(ω) ∈ Rp .
Let x ∈ Rn and y ∈ Rn be two variables and let the set of all realizations of the unknown
data be given by ω, Ω = {ω1 , ..., ωn } ⊆ Rr , where r is the number of the random variables
s.t Ax = b
x≥0
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 7/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
s.t Tω + Wω y(ω) = hω
yω ≥ 0, ∀ω ∈ Ω
The first three lines define the first-stage problem and the last three lines define the second-
stage [Link] the first stage:
• Eω [Q(x, ω)] denotes the expected value of the optimal solution of the second stage problem.
Note: that all parameters and the decision variable of the second stage are dependent on
the specific realization of the stochastic data ω. The objective variable z is also a random vari-
able, since it is a function of ω. As a random variable cannot be optimized, stochastic solvers
automatically optimize the expected value of the objective variable z.
In the first stage, a decision has to be made before the realization of the uncertain data is
clear. The optimal solution of the first stage is fixed and only then it will become known which
values the uncertain parameters will take. Given the fixed solution of the first stage and the
new data, recourse action can be taken in the second stage and the optimal solution determined.
Each possible realization of the uncertain data is represented by ωs ∈ Ω and is called a scenario.
The objective is to find a feasible solution x that minimizes the total cost, namely the sum of
the first-stage costs and the expected second-stage costs.
The formulation above looks a lot messier than the deterministic LP formulation that we
discuss elsewhere. However, we can express this problem in a deterministic form by introducing
a different second-period y variable for each scenario. This formulation is called the deterministic
equivalent:
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 8/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
Pn
Min cT x + i=1 pi qiT yi
s.t Ax =b
Ti x + Wi yi = hi , i = 1, ..., n
x ≥0
yi ≥ 0, i = 1, ..., n
where n is the number of scenarios and pi is the probability of the scenario i ’s occurrence.
s.t Ax =b
T1 x + W1 y1 = h1
T2 x + W2 y2 = h2
.. ..
. .
Tn x + Wn yn = hn
x ≥0
yi ≥ 0, i = 1, ..., n
Notice that the non-anticipativity constraint is met. There is only one first-period decision,
x , whereas there are n second-period decisions, one for each scenario. he first-period decision
cannot anticipate one scenario over another and must be feasible for each scenario. That is, Ax
and Ti x + Wi yi for i = 1, .., n. Because we solve for all the decisions, x and yi simultaneously, we
are choosing x to be (in some sense) optimal over all the scenarios.
By solving the above formula, we obtain an optimal solution x of the first-stage problem and
optimal solutions yi of the second-stage problem for each scenario ωi , i = 1, ..., n. Given x, each
yi gives an optimal second-stage decision corresponding to a realization ω = ωi of the respective
scenario.
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 9/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
REQUEST. Build up the nummerical models of Equation 4 with simulated data. Find the
optimal solution x, y ∈ Rm , and z ∈ Rn by suitable soft (as GAMSPy).
Consider a situation where a manufacturer produces n products. There are in total m different
parts (or sub-assemblies) which have to be ordered from third-party suppliers. A unit of product
i requires aij units of part j, where i = 1, .., n and j = 1, .., m. Of course, aij may be zero for
some combinations of i and j. The demand for the products is modeled as a random vector D =
(D1 , ..., Dn ). Before the demand is known, the manufacturer may pre-order the parts from outside
suppliers at a cost of cj per unit of part j. After the demand D is observed, the manufacturer
may decide which portion of the demand is to be satisfied, so that the available numbers of parts
are not exceeded. d. It costs additionally li to satisfy a unit of demand for product i, and the
unit selling price of this product is qi . The parts not used are assessed salvage values sj < cj .
The unsatisfied demand is lost.
Suppose the numbers of parts ordered are equal to xj , j = 1, ..., m. After the demand D
becomes known, we need to determine how much of each product to make. Let us denote the
numbers of units produced by zi , i = 1, ..., n, and the numbers of parts left in inventory by
yj , j = 1, ..., m. For an observed value (a realization) d = (d1 , ..., dn ) of the random demand
vector D, we can find the best production plan by solving the following linear programming
problem:
The second-stage problem:
For an observed value d = (d1 , d2 , . . . , dn ) of the above random demand vector D, we can
find the best production plan by solving the following stochastic linear program (SLP) with:
Therefore, with the above variables and data, the profit will be equal to the profit margin plus
Pn Pm
the resale amount: i=1 (li − qi )zi + j=1 sj yj . In order to create an only problem between two
stages, we will switch from max to min: max = −min, which means, to maximize profits, the
company will strive to achieve the smallest loss cost.
n
X m
X
LSP : min Z = (li − qi )zi − sj yj (3)
z,y
i=1 j=1
Pn
• i=1 (li − qi )zi represents the production cost.
Pm
• j=1 represents the number of residual parts for resale.
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 10/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
With real data qi ≥ li , the first sum will be negative, which leads to the result of the first
equation will be negative, thus, we have some expected profit.
Let xj , j = 1, . . . , m be the number of parts need to be ordered before production, the variables
in the equation will have to satisfy these constraints:
y ≥ 0, j = 1, . . . , m
j
Pn
yj = xj − i=1 aij xi , j = 1, . . . , m
0 ≤ x ≤ d , i = 1, . . . , n
i i
In which, yj is the number of residual parts (which is non-negative) and is calculated by the
number of ordered parts minus the parts used for production by demand, zi is the number of
products, which is non-negative and not exceeds demand di .
The whole second-stage model can be represents:
T T
minz,y Z = c z − s y with c = (ci := li − qi ) are cost coefficients
y = x − AT z with A = [aij ] is a m x n matrix (4)
0 ≤ z ≤ d,
y≥0
c, s and A are the matrices of production cost, the cost of reserves for production and the amount
of raw materials needed for each product. The size of each matrix depends on the input data.
The first-stage problem
The 2-SLPWR model is based on a general rule: production ≥ demand. Approaching based
on distribution, we set Q(x) := E[Z(z, y)] = Eω[x, ω] representing the optimal value of problem.
The notation b = (b1 , b2 , . . . , bm ) is constructed according to the pre-order cost bj on a unit
of part j (before knowing the demand). The quantities xj are determined from the following
optimization problem:
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 11/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
General algebraic modeling system (GAMS) is a high-level modeling system for mathematical
optimization. It is designed for modeling and solving different kinds of problems—linear, non-
linear, as well as mixed-integer optimization problems. The main characteristics of this program
are also its availability for use on various computer platforms, while models are portable from
one platform to another. Therefore, it is very popular for scientific research. This program allows
users to implement different algorithms and to combine different solvers.
GAMSPy, on the other hand, is the combination of GAMS and the well-known programming
language Python. In this case, Python acts as a communication layer, allow us to easily build
complex mathematical models.
GAMS/GAMSPy model consists of the following main elements:
Element Explanation
Sets Used to define the indices in models
Data Can be defined in different types: parameters, tables, or scalar
Variables Should be defined before solving the model
Equations Define the relationship between the data and variables
Model The mutual name for a set of equations, which also include objective function,
In the Appendix section, Problem 1’s Source code shows group’s source code for Problem
1. The source code and results can also be found at this Google Colab link.
The tables below show the figures product selling prices (q), production costs (l), ordering
costs (b), cost of each part left (s), the number of parts needed to make a product (a) and the
demand of products in each scenario (d):
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 12/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 13/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
• Number of productions:
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 14/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
The evacuation process is described by assumptions and is divided into 2 stages depending
on the time people get access to the correct information. The general purpose is to build an
optimized evacuation plan in the first stage by reviewing the plans to cope with the disaster in
stage two.
The problem aimed at resolution involves modeling a travel network with nodes representing
locations and links indicating paths. The evacuation process is outlined through assumptions and
divided into two stages. In the first stage, it is assumed that affected individuals lack access to
information about the disaster’s extent and the path of damage. After reaching a time threshold
T, they can obtain accurate road network information through various real-time monitoring
devices. Therefore, addressing the problem involves predicting a plan in the first stage when a
disaster occurs, and in the second stage, adapting the plan based on known disaster information
to accommodate random situations occurring at the specified time.
The evacuation problem under the 2-SLP form is simply illustrated by the network shown
below:
Assume nodes 1 and 8 correspond to the disaster-affected area and the safe zone, respectively.
Four vehicles (a, b, c, d) are designated for evacuating the population to the safe area.
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 15/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
In the initial stages of the event, four evacuation vehicles adhere to a predetermined plan:
Vehicles a and b follow routes 1 → 2 → 3 → 4 → 6 → 8, while vehicles c and d traverse routes
1 → 3 → 5 → 6 → 7 → 8.
Following the event (beyond the time point T ∼), once the actual situation is known, the
plan is adjusted accordingly. Assuming two random scenarios to illustrate the planning:
Evacuation plan in Scenario 1:
Vehicles a and b move along routes 1 → 2 → 3 → 4 → 7 → 8.
Vehicles c and d move along routes 1 → 3 → 5 → 6 → 8.
Evacuation plan in Scenario 2:
Vehicles a and b move along routes 1 → 2 → 3 → 4 → 6 → 8.
Vehicle c moves along routes 1 → 3 → 5 → 6 → 8.
Vehicle d moves along routes 1 → 3 → 5 → 6 → 7 → 8.
Both scenarios showcase adjustments based on the actual conditions observed post-event,
underscoring the necessity for flexibility in the evacuation strategy.
3.2.2 Presenting the evacuation problem with the min-cost flow theory
We can construct a detailed evacuation plan for people from dangerous areas to safe areas
using the min-cost flow problem. The goal is to evacuate people from dangerous areas to safe
areas with the minimum evacuation time in the system G(V, A, U, C, D), where:
• C(i, j) represents the travel time of the link (i, j) ∈ A, denoted as cij .
• U (i, j) represents the travel time of the link (i, j) ∈ A, denoted as uij .
Assume that the travel time on the link (i, j) ∈ A is the same if the number of affected people on
the road does not exceed the maximum capacity (travel time does not change according to the
number of people). The sources in the network represent the dangerous areas, the sinks represent
the safe areas, and the other nodes are the intersections of the network. The links in the network
represent the movement of the affected people.
This model differs from the usual min-cost flow problem: The 2-SLP model has recourse,
representing the situation where the first and second stages occur at different times in the same
evacuation network. In the first stage, the travel time and capacity of the link are only predicted
by probability, people must be evacuated from the sources to other nodes before knowing the
travel time and capacity of the link in the second stage. In the second stage, the evacuation plan
will be determined based on the specific travel time and capacity.
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 16/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
Note that the evacuation plan in the first stage may not be feasible for the actual situation,
we can solve it by allowing shorter evacuation time in the second stage. In this case, the result
function will include punish costs in the first stage and the expected value of recourse costs in
the second stage.
For the purpose of building the model, Table 2 summarizes the symbols used in the mathe-
matical formulas:
Symbols Definitions
V Set of nodes
A Set of links
i, j Indexes of node i, j ∈ V
(i, j) Indexes of directional link (i, j) ∈ A
s Index of scenario
S Total of the scenarios that can happen
v Value of source node
T̃ Time mark
T Total of time
uij Flow of link (i, j)
usij (t) Flow of link (i, j) in the scenario s at time t
csij (t) Moving time of link (i, j) in the scenario s at time t
µs Probability in the scenario s
These two types of decision variables presented in Table 2 will be used to build the 2-SLP
evacuation model:
Symbols Definitions
xij Flow on link (i, j)
s
yij (t) Flow on link (i, j) in the scenario s at time t
In the first stage, a binary decision variable xij is used to represent the flow on link (i, j).
s
The second decision variable yij (t) is defined to represent the flow on link (i, j) in scenario s at
time t.
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 17/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
*The first stage The problem is described as follows: The purpose is to evacuate people
from dangerous places to safe places. In reality, there are more than one sources and sinks in the
evacuation network. Therefore, the physical network with multiple sources should be converted
to an equivalent network with a single supersource, even to multiple sinks. It means a supersource
k is added to the network, and meanwhile the dummy arcs (k, i) should be added. Where K is
the set of source nodes, and let the capacity on the dummy arc be the value of the supply at node
P
i, i.e., uki = di , i ∈ K. Hence the supply value at the supersource can be set as d − k = i∈K di .
In the first stage, a feasible evacuation should be determined from supersource to supersink. The
flow on each link should satisfy the flow balance constraint below:
X X
xij − xji = di (1)
(i,j)∈A (j,i)∈A
Meanwhile, the flow on each link must also satisfy the capacity constraint:
On a separate note, the flow balance constraint may generate a path with loops and sub-tours
if there are potential loops in the evacuation network. To eliminate loops on the generated
physical evacuation path, the link penalty pij , (i, j) ∈ A is particularly introduced. With this
consideration, the penalty function can be defined as:
X
f (X) = pij xij (3)
(i,j)∈A
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 18/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
we add the arc (j, j ′ ) to the network with infinite capacity, i.e., uij = ∞, and the travel time for
each dummy arc is csij (t), ∀t ∈ {0, 1, . . . , T }.
To ensure high accuracy in predicting pre-disaster planning to minimize loss of life and prop-
erty when evacuating people, the problem must ensure an important time requirement. The
affected people will be evacuated along the a priori evacuation plan in the first stage; in other
words, the evacuation plan in different scenarios before the time threshold is the same as the a
priori path. So the problem conditions are:
X
yij (t) = xij , (i, j) ∈ A, s = 1, 2, . . . , S (4)
i≤T
Therefore, the purpose of the second stage boils down to finding the minimum total time it takes
for affected people to evacuate from the dangerous area to a safe place in each scenario s:
X
Q(Y, s) = min csij (t)yij
s
(t) (5)
(i,j)∈A
s.t.
X X
s s ′
yij (t) − yji (t ) = dsi (t), ∀i ∈ V, t ∈ {0, 1, . . . , T }, s = 1, 2, . . . , S (6)
(i,j)∈A (j,i)∈A
s
0 ≤ yij ≤ usij ∀(i, j) ∈ A, t ∈ {0, 1, . . . , T }, s = 1, 2, . . . , S (7)
X
s
yij (t) = lij , ∀(i, j) ∈ A, s = 1, 2, . . . , S (8)
t≤T
With:
(5) is the total evacuation time of all traffic flow in the most optimistic way.
(6), (7) are the flow balance condition and traffic volume condition respectively.
(8) is a condition to ensure that the evacuation plan in each scenario in stage two before time
T is consistent with the plan in the initial phase.
From the above two stages, we can come up with an adaptive plan model to minimize the
penalty for the previous evacuation plan and the expected minimum time of the adaptive evacu-
ation plan according to each scenario with a probability µs , s = 1, 2, . . . , S corresponds to each
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 19/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
scenario as follows:
P
min (i,j)∈A pij xij + Ss=1 µs . (i,j)∈As csij (t)yij s
P P
(t)
s.t.
P P
(i,j)∈A xij − (j,i)∈A xij = di , ∀i ∈ V
0 ≤ xij ≤ uij , ∀i ∈ V (9)
s s ′
(t ) = dsi (t), ∀i ∈ V, t ∈ {0, 1, . . . , T }, s = 1, 2, . . . , S
P P
(i ,j ′ )∈A yij
t t s
(t) − (jt′ ,it )∈As yij
s
≤ usij , ∀(i, j) ∈ A, t ∈ {0, 1, . . . , T }, s = 1, 2, . . . , S
0 ≤ yij
y s (t) = x ∈ A, s = 1, 2, . . . , S (∗)
P
t≤T̃ ij ij
(*) is essentially an integer programming model which contains two types of decision variables,
s
i.e., X := {xij }(i,j)∈A and Y := {yij }(i,j)∈A{0,1,...,T },s=1,2,...,S . In this model, the coupling con-
straint is a complex constraint, which leads to the model cannot be solved in polynomial time.
s
Therefore, we use the Lagrangian multiplier αi,j (t), (i, j) ∈ A, s = 1, 2, . . . , St ≤ T for the
coupling constraint, and then this constraint can be relaxed into the objective function in the
following form:
S
X X X
s s
αij yij (t) − xij
s=1 (i,j)∈A t≤T̃
After the relaxation of the formula, the model can be formulated as follows:
PS P P P
P s s S P s s
min (i,j)∈A pij x ij + s=1 µ s . (i,j)∈As c ij (t).yij (t) + s=1 (i,j)∈A αij t≤T̃ y ij (t) − x ij
s.t.
P
P
(i,j)∈A xij − (i,j)∈A xij = di , ∀i ∈ V
0 ≤ xij ≤ uij , ∀(i, j) ∈ A
s s ′
(t ) = dsi (t), ∀i ∈ V, t ∈ {0, 1, . . . , T }, s = 1, 2, . . . , S
P P
yit jt′ ∈As yij (t) − (j ′ ,it )∈As yij
t
0 ≤ y s ≤ us , ∀(i, j) ∈ A, t ∈ {0, 1, . . . , T }, s = 1, 2, . . . , S
ij ij
(11)
It is worthwhile to note that the variables X and Y can be separated from each other in above
relaxed model:
X S
X X S
X X X
min pij xij + µs csij (t).yij
s
(t) + s
αij s
yij (t) − xij
(i,j)∈A s=1 (i,j)∈As s=1 (i,j)∈A t≤T̃
X S
X X X S
X X X S
X X
= pij xij + µs .csij (t).yij
s
(t)+ s
αij s
.yij (t)− s
αij xij
(i,j)∈A s=1 (i,j)∈A t∈{0,1,2,...,T } s=1 (i,j)∈A t≤T̃ s=1 (i,j)∈A
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 20/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
!
X S
X S
X X X X
s
= pij − αij (t) xij + µs csij (t) + s
αij s
(t) yij (t)
(i,j)∈A s=1 s=1 (i,j)∈A t∈{0,1,2,...,T } t≤T̃
3.3.4 Solutions:
By combining similar terms, the relaxed model is decomposed into two subproblems as follows:
Obviously, the first sub-problem can be regarded as a min-cost flow problem, and its form is
given as follows:
P PS s
min SP 1(α) = (i,j)∈A (pij − s=1 αij (t))xij
s.t.
P P (12)
(i,j)∈A xij − (i,j)∈A xji = di , ∀i ∈ V
0 ≤ x ≤ u , ∀(i, j) ∈ A
ij ij
PS P s
The objective function of subproblem 1 can be defined as gij = pij − s=1 t≤T̃ αij to represent
the generalized cost of each link. Therefore, the subproblem 1 can be solved by the successive
shortest path algorithm. For convenience, the optimal objective value of subproblem 1 is abbre-
viated as ZSP 1 (α)∗ .
The second subproblem of the relaxed model is associated with the decision variable Y , and
its optimal objective value of the problem is abbreviated as ZSP 2 (α)∗ , shown as follows:
PS P P
µs .csij (t) + t≤T̃ αsij (t) ysij (t)
P
min SP 2(a) = s=1 (i,j)∈A t=0,1,2,...,T
s.t.
(13)
s
(t) − (j ′ ,it )∈As ysij (t′ ) = dsi (t), ∀i ∈ V, t ∈ {0, 1, . . . , T }, s = 1, 2, . . . , S
P P
(i ,j ′ )∈A yij
t t s t
P ij
y
t≤T̃ s (t) = x ij , (i, j) ∈ A, s = 1, 2, . . . , S
The minimum-cost flow problem (MCFP) is an optimization and decision problem to find
the cheapest possible way of sending a certain amount of flow through a flow network.
The problem consists of a directed graph G(V, E).
1. Each node carries a value called bi . If bi > 0, it means the node has a supply of bi , and if
bi < 0, it means the node has a demand of bi .
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 21/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
2. Each edge on the graph will have a capacity uij ≥ 0 (the maximum amount of goods that
can pass through that node) and cij ≥ 0 (the cost of one unit passing through it).
4. The problem requires finding the minimum flow, i.e., it needs to minimize the following
function:
X
xij .cij
(i,j)∈E
This means that the sum of the outflows from node i minus the sum of the inflows to node
i will equal the supply or demand of node i.
Negative Cost Cycle is a cycle in a network such that the total cost of the edges in the cycle
is negative.
When solving a streaming problem on a network, after each augmentation step, you update
the network to reflect changes in the stream. A residual network is a representation of the current
network after each update step.
Consider the following concept: Let G be a network, and x be a feasible solution to the
minimum cost flow problem. The residual capacity of an edge (i, j) is defined as rij = uij − xij ,
signifying the additional flow units that can be sent from vertex i to vertex j. It is also possible
to negate the existing flow xij on the arc by sending xij units of flow from j to i along the
arc (i, j). Notably, sending a unit of flow from i to j along the arc (i, j) increases the objective
function by cij , while sending a unit of flow from j to i on the same arc decreases the flow cost
by cij . Building upon these concepts, the residual network concerning the given flow x is defined
as follows. Consider a transportation network G = (V, E). A feasible solution x results in a new
(residual) transportation network denoted as Gx = (V, Ex ), where Ex represents a set of residual
edges corresponding to the feasible solution x. So, what is Ex ? It involves replacing each arc
(i, j) in E with two arcs: (i, j) and (j, i). The arc (i, j) has a cost of cij and a (residual) capacity
of rij = uij − xij , while the arc (j, i) has a cost of −cij and a (residual) capacity of rji = xij .
The set Ex is then constructed from the new edges with a positive residual capacity. Refer to
the figure below to ensure a clear understanding of the construction of the residual network.
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 22/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
You can notice immediately that such a definition of the residual network has some technical
difficulties. Let’s sum them up:
• If G contains both the edges (i, j) and (j, i), the residual network may contain four edges
between i and j (two parallel arcs from i to j and two contrary). To avoid this situation
we have two options. First, transform the original network to one in which the network
contains either edge (i, j) or edge (j, i), but not both, by splitting the vertexes i and j.
Second, represent our network by the adjacency list, which is handling parallel arcs. We
could even use two adjacency matrices if it were more convenient.
• Let’s imagine now that we have a lot of parallel edges from i to j with different costs.
Unfortunately, we can’t merge them by summarizing their capacities, as we could do while
we were finding the maximum flow. So, we need to keep each of the parallel edges in our
data structure separate.
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 23/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
• Step 1: Select x as a feasible flow between any origin-destination pair. This flow has
the minimum cost among the set of feasible flows with the same flow value |x|.
A(x) = {(i, j) | (i, j) ∈ A, xij < uij } ∪ {(j, i) | (j, i) ∈ A, xij > 0}
c ,
ij (i, j) ∈ A, xij < uij
C(x) =
−c , (j, i) ∈ A, x > 0
ij ji
u , (i, j) ∈ A, x < u
ij ij ij
U (x) =
x , (j, i) ∈ A, x > 0
ji ji
• Step 3: Increase the flow on each edge of P up to the capacity limit of the edge with
the smallest limit on the path, ensuring that |x| ≤ v. If the flow value |x| does not
exceed v, return to Step 1.
Let us define:
In which: xij represents flow unit, uij represents capacity, and cij represents the cost of path
(i, j).
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 24/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
First we add 2 additional nodes s, t, which are the start and end node, and then calculate
the minimum cost by adding 1 flow.
We have the yellow path representing the path with minimum cost, which is 0 + 6 + 3 + 0 = 9.
Increase the flow of each edge up to the capacity limit of the edge with the smallest limit on
the path (min(10, 10, 5) = 5 flows).
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 25/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
The current flow is 5, so the cost is: 5.0 + 5.6 + 5.3 + 5.0 = 45.
We proceed to find the Residual Network.
Using Bellman-Ford algorithm to check for negative cycles, we couldn’t find any of them.
Continue to find the path with minimum cost, we have the yellow path, which has the cost:
0 + 6 + 6 + 4 + 0 = 16.
After increasing the flow on each edge up to the capacity limit, we have the following Residual
Network:
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 26/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
At this time, there is no path from s to t so we end the algorithm here. Rebuild the trans-
portation model:
The optimal flow has the cost of: 10.6 + 5.6 + 5.3 + 5.4 = 125.
This section describes the negative cycle optimal conditions and, as a consequence, cycle-
canceling algorithm.
We are starting with this important theorem:
Theorem 1 (Solution Existence): Let G be a transportation network. Suppose that G
contains no uncapacitated negative cost cycle and there exists a feasible solution of the minimum
cost flow problem. Then the optimal solution exists.
Proof. One can see that the minimum cost flow problem is a special case of the linear pro-
gramming problem. The latter is well known to have an optimal solution if it has a feasible
solution and its objective function is bounded. Evidently, if G doesn’t contain an uncapacitated
negative cycle then the objective function of the minimum cost flow problem is bounded from
below — therefore, the assertion of the theorem follows forthwith.
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 27/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
• If the surplus network Gx∗ contains a negative cost cycle, you can “go around” this cycle
to reduce the cost of the flow. Therefore, x∗ cannot be optimal. Conversely, if the surplus
network Gx∗ does not contain a negative cost cycle, it means there is no way to “go around”
and reduce the cost of the flow. Therefore, x∗ is optimal. In summary, this relates to how
the cost of the flow changes when we change the solution, and if there is no negative cost
cycle, then the current solution is optimal.
In summary, this relates to how the cost of the flow changes when we change the solution,
and if there is no negative cost cycle, then the current solution is optimal.
This theorem gives the cycle-canceling algorithm for solving the minimum cost flow problem.
First, we use any maximum flow algorithm to establish a feasible flow in the network. Then
the algorithm attempts to improve the objective function by finding negative cost cycles in the
residual network and augmenting the flow on these cycles. Let us specify a program in pseudocode
like it is done:
4. δ ← minrij : (i, j) ∈ W
6. Update Gx
How many iterations does the algorithm perform? First, note that all the data is integral. After
line 1 of the program we have an integral feasible solution x. It implies the integrality of Gx .
In each iteration of the cycle in line 2 the algorithm finds the minimum residual capacity in the
found negative cycle. In the first iteration δ will be an integer. Therefore, the modified residual
capacities will be integers, too. And in all subsequent iterations the residual capacities will be
integers again. This reasoning implies:
Theorem 3 (Integrality Property): If all edge capacities and supplies/demands on ver-
texes are integers, then the minimum cost flow problem always has an integer solution. The
cycle-canceling algorithm works in cases when the minimum cost flow problem has an optimal
solution and all the data is integral and we don’t need any other assumptions.
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 28/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
Now let us denote the maximum capacity of an arc by U and its maximum absolute value of
cost by C. Suppose that m denotes the number of edges in G and n denotes the number of ver-
texes. For a minimum cost flow problem, the absolute value of the objective function is bounded
by mCU . Any cycle canceling decreases the objective function by a strictly positive amount.
Since we are assuming that all data is integral, the algorithm terminates within O(mCU ) itera-
tions. One can use O(nm) algorithm for identifying a negative cycle (for instance, Bellman-Ford’s
algorithm or label correcting algorithm), and obtain complexity O(nm2 CU ) of the algorithm.
In conclusion, The Cycle Canceling algorithm is a well-established method used to solve the
minimum-cost flow problem. The primary objective is to optimize the flow in a network by
iteratively identifying and eliminating negative cycles, adjusting the flow values to improve the
overall cost.
In contrast to the example of Successive Shortest Path Algorithm, which has 1 supply and 1
demand, at this example, we have 2 supplies and 2 demands.
Let us define:
In which: xij represents flow unit, uij represents capacity, and cij represents the cost of path
(i, j).
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 29/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
A feasible solution has the cost of: 6.8 + 6.5 + 4.6 + 5.4 = 122. We proceed to build the
following Residual Network:
We have the cycle 1 → 2 → 3 → 4 → 1 is a negative cycle, which has the cost of: 6 + 6 +
(−5) + (−8) = −1 and the capacity of it is: min(6, 1, 6, 6) = 1.
Proceed to augmentation along the cycle (1 cycle).
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 30/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
The cycle 3 → 5 → 4 → 3 is a negative cycle that has the cost of 3 − 4 − 6 = −7 and the
capacity is min(5, 5, 5) = 5. Continue to augmentation along the cycle (5 cycles).
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 31/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
Using the Bellman-Ford algorithm to check, we find that there is no negative cycles left, we
can end the algorithm here. Rebuild the transportation network.
The optimal flow has the cost of: 6.6 + 5.6 + 5.3 = 81.
– Time Complexity: O(V E 2 log(U )), where V represents the number of vertices, E is
the number of edges, and U is the maximum capacity in the network.
– Pros: Easy to comprehend, simple to implement, effective for solving most straight-
forward graph problems.
– Cons: Not particularly efficient for complex graphs, relies heavily on path selection to
increase flow, potentially yielding inaccurate results.
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 32/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
4 Conclusion - Appreciation
For the Question 1 of this year’s Assignment, the optimal cost is a negative number, meaning
we are making a profit. Calculating the profit from each product component gives us a production
plan that yields the best profit. Therefore, the 2-SLPWR problem is very useful in various fields
of life, or is this case, both Problem 1 and the Emergency Evacuation Problem - Problem 2.
Regarding Question 2, based on the complexity of each algorithm, we can see that the
Successive Shortest Path algorithm has the highest efficiency among the two. Thus, for the
EPDR problem, the Successive Shortest Path algorithm is the most suitable one.
In our submission, we have attached: (1) this report, (2) a python file that contain our solution
for Problem 1, (3) a C++ file containing source code for 2 Min-cost flow algorithms included in
this report to further illustrate the algorithms, and (4) a weekly progress log.
We can’t complete this report without the support of the teachers in charge of this course. We
want to express our sincere appreciation to the teachers, specifically to Mr. Thịnh, for resolving
our questions in class.
5 Appendix
Below is the group’s source code for Problem 1.
1 from gamspy import Container , Set , Parameter , Variable , Equation , Model , Sum ,
Sense
2 import numpy as np
3 import random
4 import pandas as pd
5
6 n = 8
7 m = 5
8 S = 4
9 p_s = 1/ S
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 33/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
10 model = Container ()
11
20 dataframe_d = pd . DataFrame (
21 [[ sce , pro , np . random . binomial (10 ,0.5 , size =1) [0]] for pro in Products for sce
in Scenarios ] , columns =[ " Scenario " , " Product " , " Demand " ]
22 ) . set_index ([ " Scenario " , " Product " ])
23 d = Parameter ( container = model , name = " d " , domain =[ k , i ] , records = dataframe_d .
reset_index () )
24
25 dataframe_A = pd . DataFrame (
26 [[ pro , sup , random . randint (0 ,10) ] for sup in Suppliers for pro in Products ] ,
columns =[ " Product " , " Supplier " , " Units " ]
27 ) . set_index ([ " Product " , " Supplier " ])
28 A = Parameter ( container = model , name = " A " , domain =[ i , j ] , records = dataframe_A .
reset_index () )
29
30 dataframe_b = pd . DataFrame (
31 [[ sup , random . randint (1000 ,10000) ] for sup in Suppliers ] , columns =[ " Supplier " ,
" value " ]
32 ) . set_index ( " Supplier " )
33 b = Parameter ( container = model , name = " b " , domain =j , records = dataframe_b . reset_index
() )
34
35 dataframe_s = pd . DataFrame (
36 [[ sup , random . randint (1000 , dataframe_b . loc [ sup , ’ value ’ ]) ] for sup in
Suppliers ] ,
37 columns =[ " Supplier " , " Cost " ]
38 ) . set_index ( " Supplier " )
39 s = Parameter ( container = model , name = " s " , domain =j , records = dataframe_s . reset_index
() )
40
41 dataframe_l = pd . DataFrame (
42 [[ pro , random . randint (100 _000 , 1 _000_000 ) ] for pro in Products ] ,
43 columns =[ " Product " , " value " ]
44 ) . set_index ( " Product " )
45
46 l = Parameter ( container = model , name = " l " , domain =i , records = dataframe_l . reset_index
() )
47
48 dataframe_q = pd . DataFrame (
49 [[ pro , random . randint (4 _000_000 , 10 _000_000 ) ] for pro in Products ] ,
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 34/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
57 x = Variable (
58 container = model ,
59 name = " x " ,
60 domain =j ,
61 type = " Positive " ,
62 )
63
64 y = Variable (
65 container = model ,
66 name = " y " ,
67 domain =[ k , j ] ,
68 type = " Positive " ,
69 )
70
71 z = Variable (
72 container = model ,
73 name = " z " ,
74 domain =[ k , i ] ,
75 type = " Positive " ,
76 )
77
78 supply = Equation (
79 container = model ,
80 name = " supply " ,
81 domain =[ k , j ]
82 )
83
84 supply [k , j ] = y [k , j ] == x [ j ] - Sum (i , A [i , j ] * z [k , i ])
85
86 demand = Equation (
87 container = model ,
88 name = " demand " ,
89 domain =[ k , i ]
90 )
91
92 demand [k , i ] = z [k , i ] <= d [k , i ]
93
96 prob = Model (
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 35/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
97 container = model ,
98 name = " prob " ,
99 equations = model . getEquations () ,
100 problem = " MIP " ,
101 sense = Sense . MIN ,
102 objective = obj ,
103 )
104
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 36/37
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
References
[1] [Link], “A two-stage stochastic programming framework for evacuation planning in disaster
responses”, Computers & Industrial Engineering, vol. 145, p. 106458, 2020.
[2] Alexander Shapiro and Andy Philpott, “A Tutorial on Stochastic Programming ”, 2007.
[3] Hashnayne Ahmed, “Formulation of Two-Stage Stochastic Programming with Fixed Re-
course”.
[4] [Link]
[5] [Link]
Assignment for Mathematical Modelling - Academic year 2023 - 2024 Page 37/37