Effacer les filtres
Effacer les filtres

how do i write a constraint and the sum of the z value?

3 vues (au cours des 30 derniers jours)
sharifah shuthairah syed abdullah
Commenté : Walter Roberson le 10 Juin 2018
i have the code and i try to make x as constraint but when i run i always get an error said that Undefined function or variable 'x'. below is the code and how can i get the sum of the z value?
clc;
clear;
%sum sum sum sum(fik*djq*xij*xkq)
%i,k= facilities
%j,q= location
%f(i,k)= flow between facilities i and k
%d(j,q)= distance between locations j and q
%xij = 1 if facility i is assigned to location j and if otherwise, xij = 0
% Flow matrix: flow assigning facility i (column) to facility k (row)
f = [0 5 7 9;
5 0 4 6;
7 4 0 3;
9 6 3 0];
%Distance matrix: distance assigning location j (column) to location q (row)
d = [0 6 8 9;
6 0 5 1;
8 5 0 2;
9 1 2 0];
z= 0;
nf= 4;%no of facilities
nd= 4;%no of locations
for i=1:nf
for j=1:nf
for k=1:nd
for q=1:nd
z = min('z','sum(sum(f(i,k)*d(j,q)*x(i,j)*x(k,q)))');
%if x(i,j)==1;
%else x(k,q)==0;
end
end
end
end
%Constraints %x as binary 0 1, %x(i,j) = 1 if facility i is assigned to location j 0r otherwise, x(i,j) = 0
Constraints.constr1 = (x(i,j))==1;
%The first set of constraints requires that each facility gets exactly one %location, that is for each facility, the sum of the location values %corresponding to that facility is exactly one
Constraints.constr2 = sum(x,2) == 1;
%The second set of constraints are inequalities. These constraints specify %that each office has no more than one facility in it.
Constraints.constr3 = sum(x,1) == 1;
disp (z);
are the constraint i code is wrong? and how can i get the sum of z value?
  6 commentaires
sharifah shuthairah syed abdullah
if i put it like this
x = [0 1 0 0;
1 0 1 0;
0 1 0 1;
0 0 1 0];
Constraints.constr1 = (x(i,j))==1;
then error came out and said Index in position 1 is invalid. Array indices must be positive integers or logical values.
Walter Roberson
Walter Roberson le 10 Juin 2018
If you tried to do that before your for i loop, then i would not have been defined, and would have the default value of sqrt(-1)

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Get Started with Optimization Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by