Error using lmi/horzcat One of the constraints evaluates to a FALSE LOGICAL variable

149 views
Skip to first unread message

zeZhou

unread,
Jun 3, 2019, 3:50:28 AM6/3/19
to YALMIP
load('data.mat');

numLocs = length(locations);

distance = zeros(numLocs,numLocs);
d = customer_demands;

for i = 1:numLocs
    for j = 1:numLocs
        dx = locations(i,1) - locations(j,1);
        dy = locations(i,2) - locations(j,2);
        distance(i,j) = sqrt(dx.^2 + dy.^2);
    end
end

x = binvar(numLocs,numLocs);
q = sdpvar(numLocs,numLocs);
B = sdpvar(numLocs,numLocs);
V = intvar(1);
M = 100.0;

ctr = [];

for i = 1:numLocs
    ctr = [ctr,  sum(x(i,:)) - sum(x(:,i)) == 0];
end


for i = 2:numLocs
    ctr = [ctr, sum(x(i,:)) == 1]; % line 30
end

for i = 1:numLocs
    for j = 1:numLocs
        ctr = [ctr, q(i,j) >=0] ;
    end
end

for i = 2:numLocs
    ctr = [ctr, sum(q(i,:)) - sum(q(:,i)) - d(i-1) == 0]; % line 40
end

for i = 1:numLocs
    for j = 1:numLocs
        ctr = [ctr, B(i,j) - x(i,j)*M <= 0];
    end
end

for i = 1:numLocs
    for j = 1:numLocs
        ctr = [ctr, B(i,j) - V <= 0];
    end
end


for i = 1:numLocs
    for j = 1:numLocs
        ctr = [ctr, q(i,j) - B(i,j) <= 0];
    end
end


ctr = [ctr, V>=0];

objective = vehicle_cost*V;

for i = 1:numLocs
    for j = 1:numLocs
        objective = objective + travel_cost*x(i,j)*distance(i,j);
    end
end

sol = optimize(ctr,objective);

x_star = value(x);


-----------------------------------------------------------
by running this I got:

Warning: One of the constraints evaluates to a DOUBLE variable 
> In constraint/horzcat (line 6)
  In A4_42 (line 30) 
Error using lmi/horzcat (line 21)
One of the constraints evaluates to a FALSE LOGICAL variable

Error in A4_42 (line 40)
    ctr = [ctr, sum(q(i,:)) - sum(q(:,i)) - d(i-1) == 0];

-------------------------------------------------------------
This is a model of Vehicle Routing Problem,

and the corresponding lines refer to the constraints (2)  and (3) in the picture.

DV x(i,j) is a binary variable representing whether a trip from location i to j is taken. DV q(i,j) belongs to positive real number and represents the total delivered amount in this trip. 

Is this error caused by infeasible constraints?

Thanks in advance!
微信图片_20190603094322.png

Johan Löfberg

unread,
Jun 3, 2019, 3:56:20 AM6/3/19
to YALMIP
My guess is you don't want all your decision matrices to be symmetric, as you have now

Since q is symmetric, sum(q(i,:)) - sum(q(:,i)) will always be 0, and if d(i-1) is non-zero, it is trivially infeasible as it then says -d(i-1) == 0

zeZhou

unread,
Jun 3, 2019, 6:54:45 AM6/3/19
to YALMIP
Thanks a lot!

after I create DVs as followings, everything goes well:

x = binvar(numLocs,numLocs,'full');
q = sdpvar(numLocs,numLocs,'full');
B = sdpvar(numLocs,numLocs,'full');
V = intvar(1);
Reply all
Reply to author
Forward
0 new messages