how do i create a binary [0,1]?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
how can i write to declare that x will be variable for binary 0,1
if x(i,j)=1 ;
else (x(k,q)= 0;
end;
i want to put it in my coding below
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;
nd= 4;
for i=1:nf
for j=1:nf
for k=1:nd
for q=1:nd
z = min('z','f(i,k)*d(j,q)*x(i,j)*x(k,q)');
end
end
end
end
%Constraints
%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.constr1 = 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.constr2 = sum(x,1) == 1;
disp (z);
0 commentaires
Réponses (2)
Image Analyst
le 16 Mai 2018
Do you mean like this???
% x(i, j) = 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];
x = zeros(size(f));
[rows, columns] = size(f)
for row = 1 : rows
for col = 1 : columns
facility_i = col;
facility_k = row;
if f(row, col) == facility_k
x(row, col) = 1;
end
end
end
x
Not exactly what i, j, and k mean. How are they related to row and column. If you say xij, then i=row and j=column, but then in your flow matrix explanation you say i is column, not row and you don't even mention j - you mention k which is row, but i was row. I'm confused (or you are).
1 commentaire
semi legend
le 11 Nov 2018
Modifié(e) : semi legend
le 11 Nov 2018
imagine if you have 5 virables , and you want to set the last 2 either on of them 0 or 1
you could do it, but that depends in what you want for that problem "to be or not to be"
[Inf;Inf;Inf;1;1]; to be % it will force (4) and (5) to be binary by 1 or 0 or [Inf;Inf;Inf;0;0]; or not to be
inf ; means array of infinite ( integers)
hope that at least helps
0 commentaires
Voir également
Catégories
En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!