Algorithm for solving optimization problems
In this example, we will consider a standard algorithm for solving optimization problems using the library. JuMP.
JuMP.jl is an open source library. This library implements an algebraic modeling language that allows users to formulate and solve a wide range of optimization problems using various solvers.
Installing Libraries
If the latest version of the package is not installed in your environment JuMP, uncomment and run the cell below:
Pkg.add(["JuMP", "HiGHS"])
The algorithm for solving the problem
An algorithm for solving an optimization problem using JuMP It includes several systematic steps, from the formulation of the task to obtaining and interpreting the results. Here is the standard algorithm for solving the problem:
- connecting the library
JuMP - Selecting and connecting the solver library,
- Creating an optimization task,
- Variable declarations,
- Formulation of the objective function,
- Formulation of the condition,
- Problem solving,
- Output of results,
- Analysis of the results.
Task description
In this example, we will find the values of the variables x and y, which will lead to the smallest possible value of the linear objective function.:
subject to the following conditions:
We will also define the following boundaries of the values of the variables x and y:
Problem solving
Connect the library JuMP:
using JuMP;
In this example, we use the solver library HiGHS.jl. Connect the library HiGHS:
using HiGHS;
Create an optimization task using the function Model() and specify the name of the solver in parentheses.:
optimization_problem = Model(HiGHS.Optimizer)
Use a macro @variable to determine the decision variables. Specify the boundaries of the values of the variables x and y:
@variable(optimization_problem, x >= 1);
@variable(optimization_problem, 0 <= y <= 20);
Set the target function to be optimized using a macro @objective:
@objective(optimization_problem, Min, 13x + 22y);
Set the first condition for solving the optimization problem using a macro @constraint:
@constraint(optimization_problem, c1, 3x + 8y >= 20)
Set the second condition for solving the optimization problem:
@constraint(optimization_problem, c2, 6x + 10y <= 100)
Solve the optimization problem:
optimize!(optimization_problem)
Print the found optimal values of x and y:
println("Оптимальное значение x: ", value(x))
println("Оптимальное значение y: ", value(y))
Display the status of the solver result:
task_status = termination_status(optimization_problem)
println("Статус: ", task_status)
The OPTIMAL status means that the solver has found a globally optimal solution to the problem.
Conclusion
In this example, we have analyzed the algorithm for solving the basic optimization problem using libraries. JuMP and HiGHS. Library JuMP allows you to formulate an optimization problem, set conditions, and solve it using a user-defined solver. You can familiarize yourself with the practical applications of the library. JuMP in our course Fundamentals of Optimization.