Algorithm parameter of solve ignored

조회 수: 16 (최근 30일)
Jon Bebeau
Jon Bebeau 2019년 3월 5일
댓글: Jon Bebeau 2019년 3월 5일
Using Problem-based linear solver linprog. Trying to pass Algorithm interior-point. Algorithm used is dual-simplex.
x1 = optimvar('x1'); %
x2 = optimvar('x2'); %
x3 = optimvar('x3'); %
x4 = optimvar('x4'); %
x5 = optimvar('x5'); %
prob = optimproblem('Objective',10*x1 + 2*x2 + 4*x3 + 8*x4 - x5,'ObjectiveSense','min');
options = optimoptions('linprog','Algorithm','interior-point');
% Constraints
prob.Constraints.cons1 = x1 + 4*x2 - x3 >= 16;
prob.Constraints.cons2 = 2*x1 + x2 + x3 >= 4;
prob.Constraints.cons3 = 3*x1 + x4 + x5 >= 8;
prob.Constraints.cons4 = x1 + 2*x4 - x5 >= 20;
prob.Constraints.cons5 = x1 >= 0;
prob.Constraints.cons6 = x2 >= 0;
prob.Constraints.cons7 = x3 >= 0;
prob.Constraints.cons8 = x4 >= 0;
prob.Constraints.cons9 = x5 >= 0;
prob.optimoptions(options);
problem = prob2struct(prob);
[sol, fval, exitflag, output] = solve(prob)
Optimal solution found.
sol =
x1: 0
x2: 4.0000
x3: 0
x4: 10.0000
x5: 0
fval = 88
exitflag = OptimalSolution
output =
iterations: 7
constrviolation: 3.5527e-15
message: 'Optimal solution found.'
algorithm: 'dual-simplex'
firstorderopt: 1.4211e-14
solver: 'linprog'

채택된 답변

Alan Weiss
Alan Weiss 2019년 3월 5일
You are passing the options incorrectly. See this example on the solve function reference page.
Alan Weiss
MATLAB mathematical toolbox documentation

추가 답변 (1개)

Jon Bebeau
Jon Bebeau 2019년 3월 5일
Alan, I tried all that... Using the example in the documentation: I get an Error:
options = optimoptions('intlinprog','Display','off');
problem = prob2struct(prob);
sol = solve(prob,'Options',options)
I get an Error:
Error using optim.problemdef.OptimizationProblem/solve
Options is not a valid solver. Use 'linprog' or 'intlinprog' instead.
In my output the above error, both lines, are in red but MATLAB won't cut and paste the error message.
  댓글 수: 4
Jon Bebeau
Jon Bebeau 2019년 3월 5일
Alan, The prob2struct is left over from my many, many attempts to find a solution. You are right using the solve function the prob2struct call is superfluous.
Steve Lord has already commented with the proper syntax for R2017b and this is the version I have.
Jon Bebeau
Jon Bebeau 2019년 3월 5일
Steve, I am using R2017b. Your suggestion fixed the problem. THANKS.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by