Algorithm parameter of solve ignored
이전 댓글 표시
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'
채택된 답변
추가 답변 (1개)
Jon Bebeau
2019년 3월 5일
댓글 수: 4
Steven Lord
2019년 3월 5일
The version of the example in the documentation for release R2017b has a slightly different call to solve.
sol = solve(prob,options)
The Optimization Toolbox Release Notes state that the syntax for solve has changed since R2017b. The page to which Alan linked is for the most recent release (currently R2018b) where the "solve(prob, options)" syntax has been removed.
Alan Weiss
2019년 3월 5일
You are undoubtedly using R2017b. The syntax for passing options to solve changed in R2018a. You should use
sol = solve(prob,options)
and remove the statement prob.optimoptions(options);.
I am a little confuse why you have a prob2struct call, but that is not directly relevant.
Alan Weiss
MATLAB mathematical toolbox documentation
Jon Bebeau
2019년 3월 5일
Jon Bebeau
2019년 3월 5일
카테고리
도움말 센터 및 File Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!