intlinprog gives wrong answer/uses double altough all variables are defined as integers

조회 수: 2 (최근 30일)
Hi,
intlinprog calculates the LP-Value wrong. It seems like the first variable isn't used as a binary, though it's defined as a binary. Possible values for LP should be 0,20,30 or 50 depending on the values of b (or no answer at all). Could somebody be so kind and help me out with this problem?
f =
20
30
intcon =
1 2
A =
0.0500 0.0200
-0.0500 -0.0200
b =
0.0600
-0.0100
lb =
0 0
ub =
1 1
LP: Optimal objective value is 4.000000.
Optimal solution found.
Intlinprog stopped at the root node because the objective value is within a gap tolerance of the optimal value, options.AbsoluteGapTolerance = 0 (the default value). The intcon variables are integer within tolerance, options.IntegerTolerance = 1e-05 (the default value).
ans =
1
0

채택된 답변

John D'Errico
John D'Errico 2016년 8월 10일
편집: John D'Errico 2016년 8월 10일
So I ran your test case.
[X,fval] = intlinprog(f,intcon,A,b,[],[],lb,ub)
LP: Optimal objective value is 4.000000.
Optimal solution found.
Intlinprog stopped at the root node because the objective value is within a gap tolerance of the optimal value, options.AbsoluteGapTolerance = 0
(the default value). The intcon variables are integer within tolerance, options.IntegerTolerance = 1e-05 (the default value).
X =
1
0
fval =
20
Works fine. Exactly what do you think is wrong? The solution it returns is [1;0] which, the last time I checked is a binary result. And the objective at that point is 20.
I even checked that X was indeed an exact integer vector.
X == round(X)
ans =
1
1
The solution satisfies the inequality constraints.
A*X <= b
ans =
1
1
So I'm at a complete loss to guess what you think is wrong. Looks fine to me.
Are you worried that the class of the result vector X is a double vector? Doubles can represent integers EXACTLY, as long as the integer is no larger than 2^53-1. I'm pretty sure that a 0-1 binary result is less than that limit.
So perhaps you expected the result to be an integer class vector? How should MATLAB choose what class to make it then? What if only SOME of the elements were constrained to be integer? Vectors cannot be of mixed classes, with some elements of class logical, and others of class int32, while other elements are doubles. That cannot happen (nor will it EVER be possible.)
So MATLAB returned integer results, in the form of a double. Again:
X == round(X)
ans =
1
1
X is composed of EXACT integers. That they happen to have been stuffed into a double precision vector is not relevant. They are indeed integers.
  댓글 수: 2
Steffen Kuehl
Steffen Kuehl 2016년 8월 10일
Thank you John for running my test case. I thought LP is the result of the optimization (That's a little embarrassing). Thanks for helping me out! :) And sorry for bothering you with this
John D'Errico
John D'Errico 2016년 8월 10일
편집: John D'Errico 2016년 8월 10일
AH! Ok, glad to have helped clear it up. Yeah, the objective value is stuffed in the second return argument, fval.

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

추가 답변 (0개)

카테고리

Help CenterFile 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!

Translated by