Skip to content

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

Repository files navigation


Integrated Mathematics Project


Sponsor Quantum Software Development


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



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}

Solution Steps

  1. Express the cherry chocolate constraint:

    x 1 2 + x 2 3 130

    \frac{x_1}{2} + \frac{x_2}{3} \leq 130
  2. 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.


Optimal Solution:

( x 1 , x 2 ) = ( 180 , 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

  • 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









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.