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);
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];
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.