The mathematical optimization process consists of modeling a problem with the goal of minimizing (or maximizing) a function, e.g., minimizing the total cost of a transportation system (or maximizing the expected total profit of a project). Mathematical optimization modeling fundamentally involves formulating the objective function that one seeks to optimize, and a set of constraints that translates the limitations, specifications, assumptions and rules a problem may present and delimits the feasible set of solutions to the problem. Thus, the most general and abstract formulation for an optimization model is as follows.
The vector corresponds to the vector of decision variables for the problem, whose solution represents the optimal solution of the problem, that is, the set of values
To better illustrate how the application of an optimization model works, let’s consider the following example:
The terrain in the presented situation can be represented on a Cartesian plane , where the point corresponds to the center of the base of the semicircle and the boundaries of the terrain are given by the region (where is the radius of the semicircle), which corresponds to the feasible region. Since the problem seeks to maximize the area of
From this model, it is possible to discover, by applying the KKT Conditions (see more on Appendix), that the pair that maximizes the building’s area and satisfies the specified constraints is given by , which results in the optimal plot of . Since , the optimal dimensions are and the optimal area is 50 m2.

Figure 2:The dimensions result on a optimal area of m2. Figure made on Desmos
Components of an Optimization Model¶
Every optimization model is built from a set of components that together define the problem to be solved. These components describe the universe of values, the choices we can make, the constants we cannot change, and the rules that those choices must obey. When these components are combined, an optimization model becomes a precise mathematical description of a decision problem. The solver then searches for the decision variable values that satisfy all constraints and optimize the objective function. The main components of an optimization model are:
- Ranges
- They are the basic domains used to define the indexes for other components. They tell the model which values are valid for a given index and are typically written as ordered sequences or sets, such as the rows of a matrix, the columns of a board, or the time periods in a schedule. E.g., if my problem involves a set of distribution centers and a set of customers, I might define a range for the distribution centers as and a range for the customers as . These ranges allow us to write constraints and objective functions that refer to all distribution centers or all customers without having to list them individually, which allows for more compact and general formulations.
- Sets
- They are collections of related elements built from ranges or defined explicitly. E.g. if a problem deals with a range of suppliers and a range of customers, I might define a set of possible routes between them as , which represents all possible relations or routes between suppliers and customers. Well defining sets make it easier to write constraints over many elements without listing them one by one.
- Decision Variables
- They are the unknowns the model is trying to determine. They represent the choices available to the decision-maker, such as the decision to buy or not buy a certain item, how long to keep a machine running, or how much of an item to produce. In mathematical notation, decision variables are typically written as , , or , and they can be continuous, integer, or binary depending on the problem.
- Parameters
- They are the fixed values that describe the problem data. They do not change during optimization and are used to define costs, capacities, pre-filled values or other constants. Examples include the cost of a route, the size of a board or the fact that a specific square is pre-filled in a puzzle.
- Objective Function
- It’s the formula that the model seeks to minimize or maximize. It is expressed in terms of the decision variables and parameters, and it captures what we care most about in the problem. Common examples include minimizing total cost, maximizing coverage, or maximizing the number of correctly placed pieces. The objective function gives the model a direction and a single numerical criterion for choosing the best solution.
- Constraints
- They are the rules that the decision variables must satisfy. They define the feasible region of the model and ensure that the solution obeys the problem’s physical, logical, or specific requirements and premisses. E.g., in the context of a transportation problem, constraints can require that the total amount shipped from a supplier does not exceed its capacity, or that the total amount received by a customer meets its demand. Also, they might define basic restrictions such as non-negativity of decision variables, or that a certain variable must be binary (0 or 1) or an integer.
Linear Optimization¶
Linear Optimization (LO), or Linear Programming, works with a subset of optimization problems in which both objective function and set of constraints are linear formulas, that is, written as a sum of products between constants and variables, as in the following example.
This kind of model represents a Linear Optimization Problem (LOP). If the objective function is not linear or the problem has at least one non-linear constraint, then it’s a Non-Linear Optimization Problem (NLOP) and one should need Non-Linear Programming (NLP) techniques to solve it.
Linear Optimization Hypotheses¶
Because the objective function and the model constraints are linear expressions, an LOP implicitly assumes at least four hypotheses in its modeling:
- Proportionality
- The contribution of each decision variable to the objective function and to the model constraints must be directly proportional to its value. Situations that take into account economies of scale, initial manufacturing setup costs, etc., are examples where this principle is violated.
- Additivity
- The contribution of each decision variable to the objective function and to the model constraints must be directly proportional to its value. Situations that take into account economies of scale, initial manufacturing setup costs, etc., are examples where this principle is violated.
- Divisibility and non-negativity
- Each of the decision variables can take any values within the set of positive real numbers, as long as they satisfy the model’s constraints.
- Certainty
- The coefficients and independent terms of the objective function and the model’s constraints are deterministic, that is, if it is modeled that , it would be assumed that the coefficients 2 and 3 of and , respectively, would be known and certain, that is, it would be certain that the contribution of to would always be 2 times the amount of , while the contribution of to would always be 3 times the amount of , no matter what the values of and are. In the BLOP model for the Queens game, all coefficients and independent terms will be equal to 1 (except for the arbitrary constant , which can take any value, as will be seen later).
Why Python?¶
Python is a high-level, interpreted programming language that is widely used in the field of optimization due to its simplicity, readability, and extensive library support. It provides a rich ecosystem of packages for mathematical computing, data analysis, and machine learning, making it an ideal choice for implementing and solving optimization models. Python’s syntax is straightforward and easy to learn, which allows practitioners to focus on the logic of their optimization problems rather than on complex programming details. Additionally, Python has powerful libraries such as NumPy for numerical computations, Pandas for data manipulation, and Matplotlib for visualization, which can be very helpful in analyzing and interpreting optimization results. Moreover, Python interfaces with many optimization solvers, making it a versatile tool for both academic research and industry applications in optimization.
Python Libraries¶
Along this book, it’ll be used the following Python libraries:
- Pyomo
- A powerful and flexible optimization modeling language that allows users to define optimization problems in a clear and concise way. Pyomo supports a wide range of optimization problem types, including linear, integer, and nonlinear programming, and can interface with various solvers.
- NetworkX
- A library for the creation, manipulation, and study of complex networks. It provides tools for working with graphs and networks, which can be useful for modeling and solving optimization problems that involve network structures.
- Matplotlib
- A plotting library for Python that provides a wide range of tools for creating static, animated, and interactive visualizations. It can be used to visualize optimization results, such as the feasible region, the objective function landscape, or the solution itself.
With this three libraries, we will be able to model, solve and visualize the optimization problems we will encounter in this book. But...
How to install these libraries?¶
To install the libraries mentioned above, you can use the Python package manager pip. Here are the commands you can run in your terminal to install each library. Make sure you have Python installed on your system and that pip is available. You can run these commands one by one to install the libraries, or you can combine them into a single command:
pip install pyomo networkx matplotlib gurobipy highspyHowever, it’s recommended to install these libraries by using uv or conda, as they will create an isolated environment for your project and avoid potential conflicts with other packages. You can create a new environment and install the libraries just running:
uv init
uv add pyomo networkx matplotlib gurobipy highspyAppendix¶
How to solve the Semicircle Terrain Problem with KKT Conditions¶
Figure 3:What are the building’s dimensions that maximize its area? Animation made on Desmos
Since the optimization model of this problem is non-linear, which makes it a Non-Linear Optimization Problem (NLOP), it is possible to solve it by applying the set of constraints given by the KKT conditions.
From the original NLOP:
Its Lagragean will be given by:
And the original NLOP is reformulated as the following:
Which can be simplified to:
S.t.:
From that, let’s make some assumptions in order to bump into contradictions until find the solution.
In case of :
Which contradicts with the initial assumption. Therefore, . Due to symmetry of this problem, we would conclude the same for . So as well.
If , then:
And it’s found a feasible solution to the problem, but it doesn’t maximize its objective function. Rather, it minimizes it to zero. So let’s take the other path. If , then:
Thus, it’s found that maximizes the objetive function, resulting in a optimal area of .
References¶
BELFIORE, Patrícia; FÁVERO, Luiz Paulo. Pesquisa Operacional: Para cursos de Administração, Contabilidade e Economia. Elsevier Editora Ltda., 2012.
KOCHENDERFER, Mykel J.; WHEELER, Tim A. Algorithms for Optimization. The MITPress Cambridge, Massachusetts London, England. 2nd Edition, 2026. Available at AlgorithmsBook.
Wikipedia. KKT Conditions. Accessed on June 19th, 2026.