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

2 visualizaciones (últimos 30 días)
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

Respuesta aceptada

John D'Errico
John D'Errico el 10 de Ag. de 2016
Editada: John D'Errico el 10 de Ag. de 2016
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 comentarios
Steffen Kuehl
Steffen Kuehl el 10 de Ag. de 2016
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 el 10 de Ag. de 2016
Editada: John D'Errico el 10 de Ag. de 2016
AH! Ok, glad to have helped clear it up. Yeah, the objective value is stuffed in the second return argument, fval.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by