Engee documentation
Notebook

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:

In [ ]:
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:

  1. connecting the library JuMP
  2. Selecting and connecting the solver library,
  3. Creating an optimization task,
  4. Variable declarations,
  5. Formulation of the objective function,
  6. Formulation of the condition,
  7. Problem solving,
  8. Output of results,
  9. 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:

In [ ]:
using JuMP;

In this example, we use the solver library HiGHS.jl. Connect the library HiGHS:

In [ ]:
using HiGHS;

Create an optimization task using the function Model() and specify the name of the solver in parentheses.:

In [ ]:
optimization_problem = Model(HiGHS.Optimizer)
Out[0]:
A JuMP Model
├ solver: HiGHS
├ objective_sense: FEASIBILITY_SENSE
├ num_variables: 0
├ num_constraints: 0
└ Names registered in the model: none

Use a macro @variable to determine the decision variables. Specify the boundaries of the values of the variables x and y:

In [ ]:
@variable(optimization_problem, x >= 1);
@variable(optimization_problem, 0 <= y <= 20);

Set the target function to be optimized using a macro @objective:

In [ ]:
@objective(optimization_problem, Min, 13x + 22y);

Set the first condition for solving the optimization problem using a macro @constraint:

In [ ]:
@constraint(optimization_problem, c1, 3x + 8y >= 20)
Out[0]:
$$ 3 x + 8 y \geq 20 $$

Set the second condition for solving the optimization problem:

In [ ]:
@constraint(optimization_problem, c2, 6x + 10y <= 100)
Out[0]:
$$ 6 x + 10 y \leq 100 $$

Solve the optimization problem:

In [ ]:
optimize!(optimization_problem)
Running HiGHS 1.11.0 (git hash: 364c83a51e): Copyright (c) 2025 HiGHS under MIT licence terms
LP   has 2 rows; 2 cols; 4 nonzeros
Coefficient ranges:
  Matrix [3e+00, 1e+01]
  Cost   [1e+01, 2e+01]
  Bound  [1e+00, 2e+01]
  RHS    [2e+01, 1e+02]
Presolving model
2 rows, 2 cols, 4 nonzeros  0s
2 rows, 2 cols, 4 nonzeros  0s
Presolve : Reductions: rows 2(-0); columns 2(-0); elements 4(-0) - Not reduced
Problem not reduced by presolve: solving the LP
Using EKK dual simplex solver - serial
  Iteration        Objective     Infeasibilities num(sum)
          0     1.3000046544e+01 Pr: 1(17) 0s
          1     5.9750000000e+01 Pr: 0(0) 0s
Model status        : Optimal
Simplex   iterations: 1
Objective value     :  5.9750000000e+01
P-D objective error :  0.0000000000e+00
HiGHS run time      :          0.00

Print the found optimal values of x and y:

In [ ]:
println("Оптимальное значение x: ", value(x))
println("Оптимальное значение y: ", value(y))
Оптимальное значение x: 1.0
Оптимальное значение y: 2.125

Display the status of the solver result:

In [ ]:
task_status = termination_status(optimization_problem)
println("Статус: ", task_status)
Статус: OPTIMAL

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.