Skip to content

Quantum-Software-Development/Optimization-Simulation-Modeling-LinearProgramming

Folders and files

NameName
Last commit message
Last commit date
Mar 14, 2025
Feb 22, 2025
Feb 26, 2025
Mar 13, 2025
Mar 13, 2025
Mar 24, 2025
Mar 26, 2025
Apr 6, 2025
Apr 19, 2025
Apr 18, 2025
Feb 19, 2025
Apr 23, 2025
Mar 14, 2025
Mar 14, 2025
Apr 21, 2025
Mar 14, 2025
Mar 14, 2025

Repository files navigation


Integrated Mathematics Project

LOGISTICS, FINANCE, CREDIT, ENGINEERING, HEALTH AND OTHERS



This Repo is focused on mathematical concepts, taught during the third semester of the Data Science and Artificial Intelligence bachelor's program at PUC-SP in 2025, under the instruction of Professor Doctor in Mathematics Daniel Rodrigues da Silva



Sponsor Quantum Software Development



Access Tutoril about solving LP problems using Geogebra



Constrained and unconstrained optimization. Linear Programming: formulation, geometric solution, simplex method, and duality. Network flow models: Transportation, Assignment, Shortest Path, and Maximum Flow problems. Integer programming. Multiobjective programming. Monte Carlo and discrete event simulation.

Optimization and simulation are two key areas in Operations Research, used for problem-solving and decision-making, but they approach these tasks differently[4][5]. Simulation creates a virtual model to analyze a system's behavior under various conditions, allowing for experimentation by varying parameters[1]. Optimization, on the other hand, employs mathematical algorithms to identify the best configuration of these parameters, aiming to maximize or minimize a specific objective, such as reducing costs or increasing efficiency[1][2].

Sim-Opt (Simulation-Optimization) Sim-opt combines simulation and optimization techniques to provide a comprehensive and dynamic understanding of a system[1]. This approach integrates real-world uncertainties with the search for ideal solutions[1]. By simulating the impact of each parameter and comparing it to an ideal scenario, sim-opt helps identify the factors that most influence a system's performance, leading to more strategic decisions[1].


Benefits of Sim-Opt

  • Analyzing uncertain scenarios: Sim-opt evaluates the impact of unpredictable events and helps plan strategies to manage risks[1].
  • Optimizing processes: It identifies bottlenecks and opportunities for improvement and defines the best practices for various situations[1].
  • Making informed decisions: Sim-opt bases decisions on data and simulations, reducing uncertainty and the risk of errors[1].

How to Implement Optimization in Simulation Models

  1. Define decision variables: Identify the variables that affect the simulation model's outputs and will be tested by the optimization algorithm[3].
  2. Define variable types and limits: Determine whether each decision variable is real or integer and set lower and upper limits. The optimization algorithm will search for solutions within these limits[3].
  3. Define the objective function: Establish a function to evaluate the solutions tested by the algorithm. This function can be designed to minimize, maximize, or use both types of variables, depending on the study's objectives[3].
  4. Select population size: Choose the number of solutions for the evolutionary algorithm. The population size affects the reliability and time required for the search. Also, define other parameters such as the required precision, significance level, and number of replications[3].
  5. Analyze solutions: After the search, analyze the solutions found. Compare all solutions based on the objective function to identify the best and other competitive solutions[3].

The key difference between sim-opt and other analytical tools is its ability to model the complexity and dynamics of real-world systems, including data uncertainty and variability[1]. This allows for the creation of more robust and adaptable plans[1].



I- Example of a Optimization Problem

Click here to access Theoretical and Pratical Material.


An optimization problem can be represented using the optidef package. For example:

min x f ( x ) subject to  x 0

\begin{aligned}
    &\min_{x} f(x) \\
    &\text{subject to } x \geq 0
\end{aligned}

The simplex algorithm is used to solve linear problems. Although there isn't a specific command for it, we can describe it in text or use tables to show the steps of the algorithm.


A matrix can be created using the amsmath package:

A = [ a 11 a 12 a 21 a 22 ]

A =
\begin{bmatrix}
a_{11} & a_{12} \\
a_{21} & a_{22}
\end{bmatrix}

Simulation generally involves complex mathematical models that can be described using differential or integral equations.

y ( t ) = A e k t

\y(t) = A e^{kt}

Note: This equation represents a simple solution to an ordinary differential equation.



Click here to access Theoretical and Pratical Material.

Click here and access exercises manually solved.

Click here and access extras exercises


Example: Maximizing Profit for a Chocolate Manufacturer

A chocolate manufacturer has a stock of chocolates, consisting of 130 kg with cherry filling and 170 kg with mint filling. He decides to sell the stock in the form of two different assorted packages. One package contains a mix with half the weight in cherry chocolates and half in mint chocolates and sells for R$ 20.00 per kg. The other package contains a mix of one-third cherry chocolates and two-thirds mint chocolates and sells for R$ 12.50 per kg. How many kilograms of each mix should the seller prepare to maximize his sales profit?

Objective Function

Z = 20 x 1 + 12.5 x 2

Z = 20x_1 + 12.5x_2

{ x 1 2 + x 2 3 130 x 1 2 + 2 x 2 3 170 x 1 0 , x 2 0

\begin{cases}
    \frac{x_1}{2} + \frac{x_2}{3} \leq 130 \\
    \frac{x_1}{2} + \frac{2x_2}{3} \leq 170 \\
    x_1 \geq 0, \quad x_2 \geq 0
\end{cases}

  1. Express the cherry chocolate constraint:

x 1 2 + x 2 3 130

\frac{x_1}{2} + \frac{x_2}{3} \leq 130

  1. Express the mint chocolate constraint:

x 1 2 + 2 x 2 3 170

\frac{x_1}{2} + \frac{2x_2}{3} \leq 170



Solve the system using the Simplex Method or an optimization tool.


Solving the system yields:

( x 1 , x 2 ) = ( 180 , 120 )

\(x_1, x_2) = (180, 120)

Z = 20 ( 180 ) + 12.5 ( 120 )

\Z = 20(180) + 12.5(120)

Z = 3600 + 1500 = 5100


Thus, the maximum profit achievable is R$ 5,100.



Click here to access Theoretical and Pratical Material.

Click here and access solved exercises manually


The graphical method for solving simple linear programming (LP) problems involving two decision variables. The graphical method provides a visual way to understand the constraints, the feasible region, and how to find the optimal solution that either maximizes or minimizes the objective function.

Key Concepts:


  • Objective Function: This is the linear function that we aim to maximize or minimize. For example:

    max / min Z = c 1 x 1 + c 2 x 2

      Max/Min \quad Z = c_1x_1 + c_2x_2

  • Constraints: These are linear inequalities or equalities that restrict the values the decision variables can take.

    a i 1 x 1 + a i 2 x 2 = b i

     a_{i1}x_1 + a_{i2}x_2 = b_i

    a i 1 x 1 + a i 2 x 2 b i

    a_{i1}x_1 + a_{i2}x_2 \leq b_i

    a_{i1}x_1 + a_{i2}x_2 \geq b_i

  • Feasible Solution: A solution ( x 1 , x 2 ) that satisfies all the constraints of the problem.

  • Feasible Region: The set of all feasible solutions. Graphically, this is a subregion of the plane formed by the intersection of the regions defined by the constraints. The feasible region is often a convex polygon.

  • Boundary Line: Each equality constraint or the equality part of an inequality constraint represents a straight line in the graph.

  • Semiplane: Each inequality constraint defines a half-plane on one side of its boundary line, including the line itself. The feasible region is the intersection of these semiplanes.

  • Vertices (Extreme Points): The corner points of the feasible region, formed by the intersection of two or more boundary lines.

  • Optimal Solution: A feasible solution that yields the best (maximum for maximization problems, minimum for minimization problems) value of the objective function.


Steps to Solve Graphically


  1. Plot the Constraints: FFor each constraint, treat it as an equality and plot the corresponding straight line on the Cartesian plane ( x 1 on the horizontal axis, x 2 on the vertical axis) [3].

  1. Identify the Feasible Region: For each inequality constraint, determine which side of the line satisfies the inequality. This can be done by testing a point (e.g., the origin ( 0 , 0 ) ) ; if it's not on the line) in the inequality. The feasible region is the area where all the shaded regions of the inequalities overlap. If there are non-negativity constraints ( x 1 0 ) and ( x 2 0 ) , the feasible region will be in the first quadrant [3].

  1. Identify the Vertices: Determine the coordinates of all the vertices (corner points) of the feasible region [4, 6]. These are the points where the boundary lines intersect.

  1. Evaluate the Objective Function at Each Vertex: Substitute the coordinates of each vertex into the objective function to find the value of the objective function at that point [6].

  1. Determine the Optimal Solution:
    • For a maximization problem, the vertex that yields the largest value of the objective function is the optimal solution [1, 6].
    • For a minimization problem, the vertex that yields the smallest value of the objective function is the optimal solution [2, 7].



Possible Scenarios

  • Unique Optimal Solution: The objective function achieves its maximum or minimum value at a single vertex of the feasible region [3, 5, 6].

  • Multiple Optimal Solutions: The objective function achieves its optimal value at more than one point, typically along an edge connecting two adjacent vertices. In this case, all points on that edge are optimal solutions [5].

  • Unbounded Feasible Region: If the feasible region extends infinitely in some direction, the objective function might also be unbounded (it can increase or decrease indefinitely without reaching a maximum or minimum value) [5]. However, if an optimal solution exists even with an unbounded region, it will still occur at a vertex [5].

  • Empty Feasible Region: If the constraints are inconsistent and there are no points that satisfy all of them simultaneously, the feasible region is empty, and the linear programming problem has no solution [4].


Theorem on Optimal Solutions

If the feasible region of a linear programming problem is non-empty and bounded, then the objective function attains both a maximum and a minimum value, and these occur at extreme points (vertices) of the feasible region [5].

If the feasible region is unbounded, and if the objective function attains a maximum or minimum value, it will also occur at an extreme point (vertex) [5].


Examples

The source provides several examples [6-8] that illustrate the graphical method for both maximization and minimization problems with different sets of constraints. These examples demonstrate how to plot the constraints, identify the feasible region, find the vertices, and evaluate the objective function to determine the optimal solution and its value. For instance, Example 1 [6] finds the maximum of x 1 + 2 x 2 subject to several constraints.


Conclusion about the Graphical Method

The graphical method is a useful tool for solving linear programming problems with two decision variables, providing a clear visual representation of the solution process. It helps in understanding the concepts of feasible solutions, feasible regions, and the role of vertices in finding the optimal solution. However, this method is limited to problems with only two decision variables. For problems with more variables, more advanced techniques like the simplex algorithm are required.



IV- The Simplex Method

Click here to access Theoretical and Pratical Material.

Click here and access Simplex Implementation and Calculus Exercises Manually Solved


V- Two-Stage Simplex

Click here to access Theoretical and Pratical Material.

Click here and access Two-StageS Simplex with Multiple Iteraties - Implementation and Calculus Exercise Manually Solved

Click here and access Two-Stage Simplex with Only One Iteration - Implementation and Calculus Exercise Manually Solved


VI - Excel Solver for Linear Programming - Simplex

The Excel Solver is an optimization tool available in Microsoft Excel that allows users to find the optimal solution to decision problems involving constraints and objectives. It can solve linear and nonlinear programming problems by adjusting the values of decision variables to maximize or minimize a target (objective) function, subject to a set of constraints.


In the context of Linear Programming (LP) and the Simplex Method, Excel Solver can be used to: • Define decision variables (cells that Solver will change); • Set a linear objective function to maximize or minimize; • Specify constraints on variables (e.g., inequalities or equalities); • Use the Simplex LP solving method to compute the optimal solution


Solver is especially useful in educational settings for visualizing and solving linear optimization problems without requiring programming, making it a powerful tool for teaching and learning operations research.


Simplex Method using Excel Solver

This example shows how to solve a Linear Programming (LP) problem using the Simplex Method via Excel Solver.


Problem

Maximize the objective function:

Z = 3x + 5y

Subject to the constraints:

x + 2y ≤ 100 2x + y ≤ 80 x, y ≥ 0


Excel Spreadsheet Setup

Fill the spreadsheet with the following structure:

Variables and Objective

Cell Description Formula / Value
B1 x (Decision Variable) (leave blank)
B2 y (Decision Variable) (leave blank)
B3 Objective Function Z =3*B1 + 5*B2

Constraints Left-Hand Side (LHS)

Cell Description Formula
B5 Constraint 1 LHS =1*B1 + 2*B2
B6 Constraint 2 LHS =2*B1 + 1*B2

Constraints Right-Hand Side (RHS)

Cell Description Value
C5 Constraint 1 RHS 100
C6 Constraint 2 RHS 80

Solver Configuration (Simplex LP)

  1. Go to Data > Solver.
  2. Set Objective Cell: B3
  3. Select: Max
  4. By Changing Variable Cells: B1:B2
  5. Add Constraints:
    • B5 <= C5
    • B6 <= C6
    • B1 >= 0
    • B2 >= 0
  6. Choose Simplex LP as the solving method.
  7. Click Solve.

Solution

After running Solver

x = 20 y = 40 Z = 320 + 540 = 260

Z = 260


Excel Solver Example – Linear Programming with Simplex

This example demonstrates how to use Excel Solver to solve a Linear Programming problem using the Simplex Method.

Problem Statement

Maximize:

Z = 40x + 30y

Subject to:

2x + y ≤ 40 x + 2y ≤ 50 x, y ≥ 0

Excel Setup

Cell Description Formula / Value
B1 x (Decision Variable) (leave blank)
B2 y (Decision Variable) (leave blank)
B3 Objective Function (Z) =40*B1 + 30*B2
B5 Constraint 1 (LHS) =2*B1 + 1*B2
B6 Constraint 2 (LHS) =1*B1 + 2*B2
Cell Constraint RHS Value
C5 Constraint 1 (RHS) 40
C6 Constraint 2 (RHS) 50

Solver Configuration

  1. Set Objective: B3
  2. To: Maximize
  3. By Changing Variable Cells: B1:B2
  4. Subject to the Constraints:
    • B5 <= C5
    • B6 <= C6
    • B1 >= 0
    • B2 >= 0
  5. Choose Simplex LP as the solving method.

Click Solve to find the optimal solution.

Solution Output

After running Solver:

  • x = 10
  • y = 20
  • Z = 40×10 + 30×20 = 1000

Extras Excercise:



A company, after going through a production streamlining process, ended up with the availability of 3 productive resources: R1, R2, and R3.

A study on resource usage showed the possibility of producing two products: P1 and P2. After evaluating costs and consulting the sales department, it was found that:

  • P1 yields a profit of 120 monetary units per unit
  • P2 yields a profit of 150 monetary units per unit

The production department provided the following resource usage table:

Product R1/unit R2/unit R3/unit
P1 2 3 5
P2 4 0 3

And the monthly resource availability:

Resource Monthly Availability
R1 100
R2 90
R3 120

Mathematically model the Linear Programming (LP) problem to maximize profit under resource constraints.


  • Let:

x₁ = quantity produced of product P1

x₂ = quantity produced of product P2


☟ Or in LaTeX (for use in documents):

x_1 = \text{quantity produced of product P1} \\

x_2 = \text{quantity produced of product P2}

Maximize total profit:

Maximize:  Z = 120 x 1 + 150 x 2

\text{Maximize: } Z = 120x_1 + 150x_2

Each resource has limited availability:

R1 Constraint:

2 x 1 + 4 x 2 100

2x_1 + 4x_2 \leq 100

R2 Constraint:

3 x 1 90

$3x_1 \leq 90

R3 Constraint:

5 x 1 + 3 x 2 120

5x_1 + 3x_2 \leq 120

We cannot produce a negative quantity of products:

x 1 0 , x 2 0

x_1 \geq 0, \quad x_2 \geq 0


{ Maximize  Z = 120 x 1 + 150 x 2 2 x 1 + 4 x 2 100 3 x 1 90 5 x 1 + 3 x 2 120 x 1 0 , x 2 0

\boxed{
\begin{cases}
\text{Maximize } Z = 120x_1 + 150x_2 \\
2x_1 + 4x_2 \leq 100 \\
3x_1 \leq 90 \\
5x_1 + 3x_2 \leq 120 \\
x_1 \geq 0, \quad x_2 \geq 0
\end{cases}
}

📌 Summary Tables

🔢 Profit per Product

Product Profit per Unit (u.m.)
P1 120
P2 150

🧰 Resource Usage per Unit

Product R1/unit R2/unit R3/unit
P1 2 3 5
P2 4 0 3

📦 Monthly Resource Availability

Resource Available Units
R1 100
R2 90
R3 120

🧠 Notes:

• This LP model can be solved using methods such as the Simplex Algorithm.

• Can also be implemented in software such as Python (PuLP), MATLAB, or Excel Solver.




$ Z = 4x_1 + 3x_2 $

Z = 4x_1 + 3x_2

$ \begin{cases} x_1 + 3x_2 \leq 7 \ 2x_1 + 2x_2 \leq 8 \ x_1 + x_2 \leq 3 \ x_2 \leq 2 \ x_1 \geq 0, \quad x_2 \geq 0 \end{cases} $

\begin{cases}
x_1 + 3x_2 \leq 7 \\
2x_1 + 2x_2 \leq 8 \\
x_1 + x_2 \leq 3 \\
x_2 \leq 2 \\
x_1 \geq 0, \quad x_2 \geq 0
\end{cases}

Step 1: Plot the Constraints:

Convert inequalities into equalities to draw the lines:


1. x 1 + 3 x 2 = 7

  • If x 1 = 0 x 2 = 7 3 2.33
  • If x 2 = 0 x 1 = 7

x_1 + 3x_2 = 7$
   - If x_1 = 0 \Rightarrow x_2 = \frac{7}{3} \approx 2.33
   - If x_2 = 0 \Rightarrow x_1 = 7



2. 2 x 1 + 2 x 2 = 8

  • If x 1 = 0 x 2 = 4
  • If x 2 = 0 x 1 = 4

x_1 + 2x_2 = 8
   - If x_1 = 0 \Rightarrow x_2 = 4
   - If x_2 = 0 \Rightarrow x_1 = 4



3. x 1 + x 2 = 3

  • If x 1 = 0 x 2 = 3
  • If x 2 = 0 x 1 = 3

x_1 + x_2 = 3
   - If x_1 = 0 \Rightarrow x_2 = 3
   - If x_2 = 0 \Rightarrow x_1 = 3



4. x 2 = 2 → horizontal line


x_2 = 2 → horizontal line




Step 2: Identify the Feasible Region

  • The feasible region is the intersection of all shaded regions that satisfy the constraints.
  • Must include x 1 0 and x 2 0 .

x_1 \geq 0$ and $x_2 \geq 0




Step 3: Find Intersection Points (Vertices)


1. Intersection of x 1 + 3 x 2 = 7 and 2 x 1 + 2 x 2 = 8 :

  • Multiply first by 2: 2 x 1 + 6 x 2 = 14
  • Subtract: 4 x 2 = 6 x 2 = 1.5 , x 1 = 2.5
  • Point: (2.5, 1.5)

Intersection of x_1 + 3x_2 = 7 and 2x_1 + 2x_2 = 8:
   - Multiply first by 2: 2x_1 + 6x_2 = 14
   - Subtract: 4x_2 = 6 \Rightarrow x_2 = 1.5$, $x_1 = 2.5
   - Point: **(2.5, 1.5)**



2. Intersection of x 1 + 3 x 2 = 7 and x 1 + x 2 = 3 :

  • Subtract: 2 x 2 = 4 x 2 = 2 , x 1 = 1
  • Point: (1, 2)

 Intersection of x_1 + 3x_2 = 7 and x_1 + x_2 = 3:
   - Subtract: 2x_2 = 4 \Rightarrow x_2 = 2$, x_1 = 1
   - Point: **(1, 2)**



---lll--- LATER-----




Step 4: Evaluate Objective Function at Each Vertex









Max. Z = 4 x 1 + 3 x 2 S.a. { x 1 + 3 x 2 7 2 x 1 + 2 x 2 8 x 1 + x 2 3 x 2 2 x 1 0  e  x 2 0








Contributions are welcome! If you want to add more examples, correct errors, or improve the documentation, please submit a pull request. Let's learn and grow together on the journey of integral calculus.


Any contributions are highly appreciated. You can contribute in two ways:

  1. Create an issue and tell us your idea 💡. Make sure that you use the new idea label in this case;

  2. Fork the project and submit a full requesto with your new idea. Before doing that, please make sure that you read and follow the Contributions Guide. ⊹🔭๋


Main Contributors


Sources

➢ 1. Simulation-optimization: how to combine them in decision-making

➢ 2. What is optimization? / VirtualCAE

➢ 3. Optimization in simulation models: a study

➢ 4. Simulation-Optimization: Why and How to Combine Them?

➢ 5. Invited Tutorial: Simulation-Optimization

➢ 6. Optimization and Simulation Models / DCA / Unicamp

➢ 7. Process Simulation and Optimization: Efficient Planning

➢ 8. Simulation Modeling vs Optimization: How to Choose

Copyright 2025 Quantum Software Development. Code released under the MIT License license.