Solves an optimisation problem.
sopi_solve(problem, method)
the name of the optimisation method to use
// ----------------------------------------------------------------------------- // SOPI DEMO // ----------------------------------------------------------------------------- // This example shows how Sopi can be used to formulate and solve a simple linear // optimisation problem. // // The considered problem is the following, // min_x,y 10 x + 12 y // s.t. // y <= 2 x // 2x + 3y <= 240 // x + y >= 60 // x, y >= 0 // // The optimal solution is reached at x = 60 and y = 0 for f(x,y) = 600. // ----------------------------------------------------------------------------- // sopi_begin must be called before any sopi-related operation sopi_begin() // Creation of the optimisation variables x and y x = sopi_var(1) y = sopi_var(1) x.name = "x" y.name = "y" // Creation of the constraints of the problem. Note that constraints can be // gathered with & bounds = x >= 0 & y >=0 c1 = y <= 2 * x c2 = 2*x +3*y <= 240 c3 = x+y >= 60 // Creation of the objective function objective = 10*x + 12*y // Instanciation of the optimisation problem problem = sopi_min(objective, bounds, c1, c2, c3) disp(sprintf("Optimisation problem built by sopi:\n")) disp(problem) // Resolution of the problem // At the moment, the default linear solver is the built-in method 'karmarkar'. [optVar, fopt, info] = sopi_solve(problem) // The optimal values are given in the fields 'opt' disp(sprintf("Solution of the problem:\n")) disp(sprintf('\tSolver used: ''%s''', problem.solvers(1).name)) disp(sprintf('\tOptimal value of %s:%2.2f', x.name, x.opt)) disp(sprintf('\tOptimal value of %s:%2.2f', y.name, y.opt)) disp(sprintf('\tOptimal objective value:%2.2f', objective.opt)) // Displaying the problem and the solution found sopi_plot2DProblem(problem, x, y) sopi_end() | ![]() | ![]() |