2

I tried implementing the solution in optimal binary matrix using Matlab function intlinprog to a test input as in the following code

a=[450;400;250;200]; % test input
b=[750;500]; % test input
n = 4; % length of a
m = 2; % length of b
oness=ones(m,1);
f = (kron(a,oness))'; % objective function
cont1=kron(eye(n),oness'); 
cont2=-cont1;
cont3=-kron(a',eye(m));
A=[cont1;cont2;cont3];
bb=[ones(n,1);-zeros(n,1);-b];
lb = zeros(m*n,1);
ub = [ones(m*n,1)]; % enforces binary
intcon= [1,2,3,4,5,6,7,8]; % all variable should be integers  
 Aeq = [];
 beq = [];
x = intlinprog(f,intcon,A,bb,Aeq,beq,lb,ub)

However, I am getting the message

Intlinprog stopped because no integer points satisfy the constraints.

An obvious optimal solution for this test input would be x = [0;1;1;0;1;0;0;0].

However, if I remove the integrality constraints via intcon=[], I get an optimal solution. Why can't the function find the minimum solution with integral constraints?

Rodrigo de Azevedo
  • 1,097
  • 9
  • 17
Mustafa
  • 21
  • 5
  • Try to generate the test inputs randomly. You may have picked test inputs for which the corresponding polytope does not contain any integer points. – Rodrigo de Azevedo May 12 '17 at 14:18
  • I had a mistake in the problem definition that I have fixed now. The code now give output correctly. I am posting the new code as an answer. Many thanks to @RodrigodeAzevedo for your sincere support. – Mustafa May 12 '17 at 19:57

1 Answers1

0

I had a mistake in the problem definition that I have fixed now. The code now give output correctly. Below is the correct code:

a=[450;400;250;200]; % test input
b=[750;500]; % test input
n = 4;
m = 2;
oness=ones(m,1);
f = -(kron(a,oness))';
cont1=kron(eye(n),oness');
cont2=-cont1;
cont3=kron(a',eye(m));
A=[cont1;cont2;cont3];
bb=[ones(n,1);-zeros(n,1);b];
lb = zeros(m*n,1);
ub = [ones(m*n,1)]; % enforces binary
intcon= 1:8;
 Aeq = [];
 beq = [];
x = intlinprog(f,intcon,A,bb,Aeq,beq,lb,ub)

Answer:

x = [1;0;0;1;1;0;0;0] which give same optimal result as

x = [0;1;1;0;1;0;0;0]

Mustafa
  • 21
  • 5