Stochastic Programming-1
Stochastic Programming-1
UNIVERSITY OF TECHNOLOGY
FACULTY OF COMPUTER SCIENCE AND ENGINEERING
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 1/25
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
Contents
1 Introduction 3
4 Discussion 22
4.1 Integrative Analysis of Manufacturing and Emergency Planning . . . . . . . . . . 22
4.2 Challenges and Opportunities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.3 Implications and Future Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.4 Concluding Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
5 Conclusion 23
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 2/25
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
1 Introduction
The complex interplay of uncertain variables in the realms of industrial manufacturing and
emergency response planning poses significant challenges for decision-makers. It is in this context
that stochastic programming becomes indispensable, offering a robust and nuanced framework
for optimization amidst uncertainty. This framework not only accommodates variability but also
provides a structured approach to decision-making that can significantly mitigate risk. Our report
delves into two core applications of stochastic programming: the optimization of manufacturing
processes in the face of uncertain demand, and the development of responsive strategies for
emergency planning and disaster recovery.
The first part of our analysis addresses a pivotal aspect of industrial operations—the pro-
duction planning conundrum faced by manufacturers. Herein, we employ a two-stage stochastic
linear programming model (2-SLPWR) to navigate the complexities of aligning production with
fluctuating demand. This model offers a profound insight into how strategic planning, un-
derpinned by robust mathematical modeling, can effectively anticipate and accommodate the
randomness of consumer behavior and market trends. Through a comprehensive simulation
of scenarios and meticulous computational analysis, we elucidate the derivation of an optimal
solution that balances cost-efficiency with responsiveness to market dynamics.
Concurrently, the exigencies of emergency management present a scenario where the stakes
are elevated, and the need for precision and foresight is acute. In this domain, our study shifts
focus to Stochastic Linear Programming with Emergency Planning and Disaster Recovery (SLP-
EPDR), a field where the optimization of resources and routing can have far-reaching implications
on community safety and recovery. Algorithmic solutions rooted in stochastic programming pro-
vide a canvas for developing strategies that optimize evacuation routes, resource allocation, and
contingency planning, all within a framework that accommodates the inherent unpredictability
of emergencies.
By undertaking this dual analysis, our report seeks to cast light on the comprehensive ca-
pabilities of stochastic programming. We explore the theoretical underpinnings that inform this
field of study, as well as the practical implications of its application. The aim is to present a
holistic view of how stochastic programming can serve as a linchpin in the strategic planning of
both industrial and emergency scenarios, ensuring that decisions are data-driven, rigorously an-
alyzed, and strategically sound. Through this exploration, we underscore the value of stochastic
programming as an essential tool in the arsenal of modern decision-making.
In synthesizing these perspectives, the report will navigate through the nuanced facets of
stochastic programming, from the granular details of mathematical modeling to the broad strokes
of strategic application. We will dissect the challenges posed by uncertainty, explore the strategies
devised to confront these challenges and evaluate the outcomes of our analyses. By doing so, we
hope to demonstrate the indelible impact of stochastic programming on efficient decision-making
and its potential to transform theoretical models into actionable strategies with tangible benefits.
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 3/25
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
2.2 Methodology
The methodology employed to address the manufacturing optimization problem under uncer-
tainty is rooted in two-stage stochastic programming. This section delineates the step-by-step
process of formulating and implementing the model, as well as the rationale behind choosing this
particular approach.
Model Formulation
The two-stage stochastic programming model consists of two decision points: the first stage
(here-and-now) before the uncertainty is revealed and the second stage (wait-and-see) after the
uncertainty is realized. The model is formulated as follows:
1. Decision Variables:
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 4/25
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
2. Objective Function: The objective is to minimize the expected total cost, which is the
sum of the production, inventory holding, and stockout costs across all possible demand
scenarios.
3. Constraints:
• Production constraints ensure that the production amount does not exceed the plant’s
capacity.
• Inventory balance constraints ensure that inventory levels are maintained appropri-
ately, accounting for the initial stock, production output, and realized demand.
• Demand fulfillment constraints ensure that customer demand is met to the extent
possible.
The flowchart below illustrates the sequential decision-making process in the two-stage
stochastic programming model.
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 5/25
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
Initialize
Model
First-Stage
Decision
Generate
Scenarios
Second-
no Stage
Decision
Is solution
optimal?
yes
Stop
5. Data Collection and Preparation: Historical demand data is collected to inform the
demand probability distributions. Costs associated with production, inventory, and stock-
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 6/25
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
min z T c − sT y (1)
subject to the constraints of inventory balance and demand fulfillment, where c and s are cost
coefficient vectors, and z and y are decision variables representing the production plan and
inventory levels, respectively.
Additionally, the optimization problem is encapsulated by the following model:
where Q(x) = ED|z [g(x, D)] is the expected cost function conditioned on the realization of de-
mand D, and h and l represent the vectors of selling price and salvage value per unit, respectively.
Implementation
The model is implemented using a linear programming solver within a Python environment,
leveraging the PuLP library. The implementation involves:
1. Data Input: The demand scenarios, cost parameters, and initial inventory levels are input
into the model.
2. Solver Execution: The model is solved for each scenario, with the solver providing the
optimal first-stage decisions immediately and the optimal second-stage decisions once the
demand scenario is known.
3. Solution Analysis: The solutions across all scenarios are analyzed to determine the expected
costs and the robustness of the production plan.
Model Execution
The model is executed using a sample data set to validate its performance. The results are then
compared to a baseline model, which uses a deterministic approach to production planning.
By using this two-stage stochastic programming approach, the methodology allows for more
resilient and cost-effective decision-making in the face of demand uncertainty, compared to tra-
ditional deterministic models.
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 7/25
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
The first-stage model, which is concerned with initial production decisions before the realization
of demand, has resulted in an optimal objective value of $1013.625. The optimized decision
variables for ordering parts or producing products are as follows:
• x[0] = 18.0,
• x[1] = 15.0,
• x[2] = 18.0,
• x[3] = 18.0,
• x[4] = 20.0.
This indicates the quantities to be ordered or produced initially, without the knowledge of exact
future demand.
Upon the realization of demand in two different scenarios, the second-stage model adapted the
initial decisions accordingly.
• In Scenario 1, the model achieved an objective value of -646.0. The optimal production
values adjusted after the demand realization were [4.0, 1.0, 2.625, 0.0, 0.0, 1.125, 0.0, 0.0],
with some products not requiring any adjustment and others being increased.
• In Scenario 2, the model reached an objective value of -659.5. The optimal values for
production adjustments were [6.25, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], which again shows
variation in adjustments across different products.
The negative objective values represent the net cost savings compared to a scenario where no
production adjustment is possible. The results clearly indicate the efficacy of the two-stage
stochastic programming approach, where the adaptability to demand uncertainty can lead to
significant cost reductions.
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 8/25
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
2.3.3 Analysis
The results from the two-stage stochastic programming model demonstrate the model’s ability
to provide a flexible and cost-effective solution for manufacturing under uncertainty. The first-
stage decisions lay the groundwork for a proactive approach to production planning, while the
second-stage decisions allow for reactive adjustments, ensuring that production is closely aligned
with the actual demand.
The model’s performance in both scenarios suggests that it can effectively mitigate the risks
associated with demand uncertainty, leading to more efficient use of resources and reduced costs.
The cost savings observed in both scenarios highlight the potential for improved profitability
through the application of such advanced optimization techniques.
Overall, the analysis suggests that incorporating stochastic elements into production plan-
ning can provide a significant strategic advantage in the highly competitive and uncertain envi-
ronment of manufacturing.
2.4 Conclusion
The application of two-stage stochastic programming to the manufacturing optimization problem
has demonstrated the potential for significant improvements in cost management and service level
performance. The results of this study suggest that incorporating uncertainty into production
planning is not only feasible but also advantageous in today’s volatile manufacturing landscape.
In summary, finding the subgradient optimization will reduce the gap between the 2 bounds
and lead to the objective final solution. The main purpose is to plan before the disaster happens
- the optimal solution to stage 1 is to know which is the best plan to test all the uncertainty that
can happen in stage 2.8.
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 9/25
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
We will find a way to minimize the time travel of the flow from the supply node to the
demand node. If there exist multiple paths at the same time, we choose the path with maximum
capacities. The xij in the first stage has to satisfy the balance constraint the out-degree =
in-degree:
X X
xij − xji = di (3)
(i,j)∈A (j,i)∈A
Meanwhile, the flow on each link must also satisfy the capacity constraint:
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 10/25
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
Then the adaptive plan for the second stage is made using this model:
X X S
µs · Q(Y, s)
min Pij xij +
(i,j)∈A s=1
s. t.
X X
x ij − xji = di , ∀i ∈ V
(i,j)∈A
(j,i)∈A
0 ≤ xij ≤ uij , ∀(i, j) ∈ A
in which,
X
csij (t) · yij
s
Q(Y, s) = min
(t)
(i,j)∈A (5)
s. t.
X X
s s
yij (t) − yji (t) = dsi (t), ∀i ∈ V,
(i,j)∈A (j,i)∈A
t ∈ {0, . . . , T }, s = 1, . . . , S
s
(t) ≤ usij (t),
0 ≤ yij ∀(i, j) ∈ A,
t ∈ {0, . . . , T }, s = 1, . . . , S
X
s
yij (t) = xij , ∀(i, j) ∈ A, s = 1, . . . , S
t≤T
Given the substantial complexity of this model, it presents significant challenges in terms of
resolution. Therefore, it is prudent to decompose it into two distinct subproblems, which can be
addressed using the method of Successive Shortest Path Algorithm.
3.3 Implementation
Below is the implementation of the successive path algorithm:
1. Initialize the graph with zero flow x ← 0, and each node with v.
2. Choose a supply node (s) with v > 0 and a demand node (d) with v < 0. (If one of them
doesn’t exist, terminate the program).
a) Calculate the total travel time of all the possible approaches from s to d. If there are
no existing links but reverse links, we travel that link.
b) If a loop with negative flow exists, terminate the program with an error.
c) Choose the path that has minimum travel time and the highest capacity.
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 11/25
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
4. Calculate the amount of flow ∆ that can be sent on this path, which is the lowest capacity
of any edge on the path.
5. Update the flow, subtract the capacity of the forward links by ∆. By the time, add the
capacity ∆ of the reverse links. If the reverse link doesn’t exist, create a new edge with
negative travel time and the reverse direction.
8. Return to step 2.
• c(n): the shortest path from some node n to v in A(x) with respect to each edge’s travel
time.
1. Initialize the graph with zero flow x_ij = 0, for all (i, j) in A
2. Set v(n) = b(n) for all n in V
3. Initialize E = {e in V : v(e) > 0} and D = {e in V : v(e) < 0}
4. While E is not empty
a. Pick a node k in E and l in D
b. Compute c(k): shortest time cost of the paths from k to l in A(x)
with respect to edges’ travel time
c. Let R(x) be a path that has the minimum time cost from k to l.
d. Let u = min{e(k), -e(l), min{u_r(v, w) : (v, w) in R(x)}}
e. Send u units of flow on the residual path R(x)
f. Update x_ij, C(x), U_ij(x), A(x), E, D
5. End while
Here are also some notes for the algorithm. The reversible path is for the case if there
are no existing links with positive travel time, but reversible links, we travel that link to undo
previous flows. Then, we can continue. If there are some supply or demand nodes without any
positive links, the graph has no solution. In other words, it is impossible to satisfy all of the
transportation from the supply source to the demand source.
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 12/25
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
In the first stage of the Stochastic Programming problem, we meet the fixed scenario with
the same capacity and time travel, without uncertainty in the future. We set up an experimental
example with 9 nodes and 12 links at an example:
Figure 2: Graph 1
In order to verify the correctness of the successive shortest path algorithm, we can use this
algorithm to solve the Min-cost flow problem in a square 3 × 3 graph.
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 13/25
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
For the first iteration, we initialize the graph with zero flow. Then, we can see that node 1
is a supply value node with value v = 10, and node 9 is a demand node with value −v = −10.
After that, we calculate the travel time and the capacity of every possible path from node 1 to
node 9.
Among those paths, the route that has the lowest travel time is 3. The capacity of the path
is 2, which is the edge between node 5 and node 6. Therefore, we can transmit 2 supply values
to the demand node. Subtract a value of 2 to supply node 1, and add 2 to demand node 9.
Then, for each edge in the graph, we subtract 2 from the capacity. Also, we create the
reverse links that have negative travel time, capacity value is 2, and reverse the direction.
The total travel time for transmitting 2 supply values along the path is 300.
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 14/25
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
In this iteration, both the second and third paths have the same time, but the third path
has a higher capacity. We choose the third path to supply the highest value.
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 15/25
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
In this iteration, we choose the second path for the minimum time.
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 16/25
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
Figure 8: Result
In the second stage, several scenarios include randomness affecting the graph’s properties,
like capacity and weight. The second stage Stochastic Programming involves calculating the best
flow to adopt for every scenario happening in the future.
For a simple demonstration of the assignment, we will only consider 2 scenarios:
Scenario 1: only use graph 1, with µ1 = 50
˜ 50, change to apply graph 2, with µ2 = 50%
Scenario 2: Firstly use graph 1, after T=
Below is the second scenario of the graph at T=
˜ 50
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 17/25
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
Figure 9: Graph 2
Fortunately, the min-cost flow problem can also be solved with Successive Short Path algo-
rithm embedded in the Python library; to be more specific, networkx library. We utilize Python
to quickly solve the problem.
After drawing the graph and using “nx.capacity scaling” function, we received the following
result:
FlowCost 2800
FlowDict {2: {3: 4, 5: 1},
4: {5: 1, 7: 4},
1: {2: 0, 4: 0},
3: {6: 4},
5: {6: 1, 8: 1},
6: {9: 5},
7: {8: 4},
8: {9: 5},
9: {}
This means the flow for the second scenario is the following:
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 18/25
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 19/25
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
However, sometimes the Successive Shortest Path algorithm can return a wrong answer.
The algorithm can only consider one scenario at a time, and it does not consider the randomness
element when dealing with second-stage stochastic programming problems. Hence, the result is
not optimal.
Let’s consider the following example:
Figure 12: Graph 3 and the result of Example 3 in the first-stage problem
The shortest path from the demand node to the supply node for graph 3 in the first-stage
time-cost problem is 210, which is 1 → 4 → 5 → 8 → 9 (1). We can easily calculate that the
total time cost for the following paths in the problem is 2310.
Figure 13: Graph 4 and the result of Example 3 in the second-stage problem using Successive
shortest path algorithm
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 20/25
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
Figure 14: Graph 5 and the result of Example 3 in second-stage problem in other solution
However, if we consider another approach between the demand and supply node, especially
1 → 2 → 5 → 8 → 9 (2), we notice that in the 2nd-stage problem, the path only costs 80 + 60
+ 160 = 300. This means that path (2) is more efficient than path (1) 10%.
Therefore, we bring 6 units in node 2 and 4 units in node 4. The total time cost in this case
is 2480. This is 1,61% better than the output from the Successive shortest path algorithm.
Hence, we can observe that an optimal solution in sub-problem 1 cannot help provide an
optimal solution in sub-problem 2. As a result, to solve the problem, we need to use another
algorithm that considers all of the possible uncertainties. One of the possible approaches is the
Lagrangian relaxation algorithm.
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 21/25
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
Assuming the capacity of each edge is an integer, then each augmentation decreases the
total absolute balance B by a positive integer, and therefore by at least 1. It follows that the
cycle canceling algorithm halts after at most B iterations and thus runs in O(VAB) time.
Keep in mind that the successive path algorithm addresses only a single scenario, meaning
that in the context of two-stage stochastic programming, the derived solution may be inaccurate
as it fails to account for all possible scenarios.
3.6 Conclusion
In conclusion, this project has presented an approach to evaluate disaster through 2 stages
of stochastic programming. This method allows an adaptable framework that works well with
uncertainties and the dynamic nature of disaster scenarios.
The primary object of this report is to discuss the practical model for the road network
model, which is made to consider the behavior of the process by considering various aspects such
as travel times and capacities. These experimental models served as a crucial testing ground,
allowing us to analyze the effectiveness of the min-cost flow algorithm.
4 Discussion
The exploration of stochastic programming within the realms of industrial manufacturing
and emergency planning has yielded profound insights into the versatility and efficacy of the
approach. This discussion aims to integrate the findings from both Problem 1: Industry - Manu-
facturing and Problem 2: SLP-EPDR: Algorithmic Solutions, highlighting the interdependencies
and the distinct challenges addressed by each.
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 22/25
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
5 Conclusion
This report has meticulously examined the intricate role of stochastic programming in two
critical sectors: industrial manufacturing and emergency planning. Through the lens of two-stage
stochastic linear programming (2-SLPWR) and Stochastic Linear Programming with Emergency
Planning and Disaster Recovery (SLP-EPDR), we have unearthed the profound impact of this
mathematical approach in navigating the uncertainties inherent in these fields.
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 23/25
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
In the case of industrial manufacturing, the report has demonstrated the profound benefits
of employing stochastic programming for production planning. The adaptability offered by this
approach allows for a more resilient operation, capable of adjusting to market fluctuations and
demand uncertainties with remarkable efficiency. The optimal production strategies deduced
from the 2-SLPWR model underscore the potential for reducing operational costs, optimizing
inventory levels, and consequently, bolstering the robustness of supply chains.
Concurrently, the foray into emergency planning via the SLP-EPDR model has revealed the
criticality of rapid and informed decision-making in the face of disasters. The model’s efficacy
in optimizing evacuation routes and resource deployment highlights the lifesaving potential of
stochastic programming. By enabling emergency responders to anticipate various crisis scenar-
ios and respond with precision, the SLP-EPDR model stands as a testament to the value of
preparedness and pre-emptive strategy.
The challenges encountered during the analysis, from data simulation to computational
limitations, have further reinforced the importance of continuous improvement and innovation
in the field of stochastic programming. It is clear that as computational capabilities evolve, so
too will the sophistication and accuracy of these models.
Looking ahead, the application of stochastic programming is poised to extend far beyond the
realms explored in this report. The principles and methodologies outlined here hold significant
promise for a diverse array of sectors facing uncertainty. As the world becomes increasingly
interconnected and dynamic, the demand for advanced decision-making tools like stochastic
programming will only grow.
In conclusion, the findings of this report contribute to a burgeoning body of knowledge that
underscores the versatility and necessity of stochastic programming. Whether applied to the
methodical demands of manufacturing or the urgent needs of emergency response, stochastic
programming offers a strategic advantage that is both quantifiable and invaluable. It stands not
only as a testament to the power of mathematical modeling but also as an indispensable ally in
the quest for operational excellence and societal safety.
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 24/25
University of Technology, Ho Chi Minh City
Faculty of Computer Science and Engineering
References
[1] A. Shapiro, D. Dentcheva, and A. Ruszczynski, Lectures on stochastic programming: mod-
eling and theory. SIAM, 2021.
[3] L. Wang, “A two-stage stochastic programming framework for evacuation planning in dis-
aster responses,” Computers & Industrial Engineering, vol. 145, p. 106458, 2020.
Assignment for Discrete Structures for Computing - Academic year 2023 - 2024 Page 25/25