My code lookes like this, its a problem where the placement of a factory has to be optimized for the transportation and demand for products, m is factories and n is costumers. When i run the code it nerver ends. What am i missing?
m = 3;
n = 5;
s = [ 239 225 184 ] ;
d = [ 92 82 83 69 74 ] ;
f = [ 589 766 886 ];
c = [ 14 5 6 24 6
9 22 26 5 21
16 11 23 28 24 ];
e=0.01;
tic
x = zeros(size(c));
y = zeros(size(f));
ss=s;
dd=d;
cc=c;
ff=f;
wow = 20;
cost = 0;
while sum(dd)>0
[Factory_price,i] = min(ff(ff>0));
factory_kap = ss(i);
row = cc(i,:);
[factory_rk,j] = min(row(row>0));
cost = factory_rk+cost;
demand = dd(j);
while factory_kap > 0 && demand > 0
factory_kap = factory_kap-1;
demand = demand-1;
cost = factory_rk+cost;
if demand == 0
dd(j) = 0;
cc(i,j) = 0;
elseif factory_kap == 0
ss(i) = 0;
ff(i) = 0;
end
end
wow=wow-1;
end
cost;
toc
1 Comment
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/619803-while-function#comment_1072938
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/619803-while-function#comment_1072938
Sign in to comment.