I use the while function for iteration but when the process is running can't stop ... please help me ... what should I do?

function [Solution, OverallCost]=VAM(CostsMtx, resources_col, demands_row)
%[CostsMtx,ss,sd]=inputFun(CostsMtx, resources_col, demands_row);
C_start = [464 513 464 513
352 416 690 352
995 682 388 388];
C = C_start
[m,n]=size(C)
a = [75
125
100
]
b = [80 65 70 85]
X = zeros(m,n)
stop = 0;
while stop == 0
for i = 1:m
for j = 1:n
if a(i,1) == 0
C(i,j) == max(C(:,j))
if b(1,j) == 0
C(i,j) == max(C(i,:))
end
end
end
C_sort_col = sort(C,1)
C_sort_row = sort(C,2)
Diff_customer = abs(C_sort_col(1,:)- C_sort_col(2,:))
Diff_supplier = abs(C_sort_row(:,1)- C_sort_row(:,2))
for i = 1:m
if a(i,1) == 0
Diff_supplier(i,1) = 0
end
end
for j = 1:n
if b(1,j) == 0
Diff_customer(1,j) = 0
end
end
Max_Diff_customer = max(Diff_customer)
Max_Diff_supplier = max(Diff_supplier)
Customer_nr = find(Diff_customer==max(Max_Diff_customer,Max_Diff_supplier))
Supplier_nr = find(Diff_supplier==max(Max_Diff_customer,Max_Diff_supplier))
if isempty(Customer_nr) == 0
Supplier_nr_ = find(C(:,Customer_nr(1)) == min(C(:,Customer_nr(1))))
X(Supplier_nr_(1),Customer_nr(1)) = min(a(Supplier_nr_(1),1),b(1,Customer_nr(1)))
a(Supplier_nr_(1),1) = a(Supplier_nr_(1),1) - X(Supplier_nr_(1),Customer_nr(1))
b(1,Customer_nr(1)) = b(1,Customer_nr(1)) - X(Supplier_nr_(1),Customer_nr(1))
Supplier_nr = []
end
if isempty(Supplier_nr) == 0
Customer_nr_ = find(C(Supplier_nr(1),:) == min(C(Supplier_nr(1),:)));
X(Supplier_nr(1),Customer_nr_(1)) = min(a(Supplier_nr(1),1),b(1,Customer_nr_(1)));
a(Supplier_nr(1),1) = a(Supplier_nr(1),1) - X(Supplier_nr(1),Customer_nr_(1));
b(1,Customer_nr_(1)) = b(1,Customer_nr_(1)) - X(Supplier_nr(1),Customer_nr_(1));
end
%Stop condition:
if (max(a)==0||max(b)==0)
stop = 1;
end
a1 = a > 0;
b1 = b > 0;
if sum(a1) == 1
stop = 1;
for j = 1:n
if b(j) > 0;
X(a1 == 1,j) = b(j);
end
end
end
if sum(b1) == 1
stop = 1;
for i = 1:m
if a(i) > 0;
X(i,b1 == 1) = a(i);
end
end
end
end
if (isempty(a1) || isempty(b1))
stop = 1;
end
Solution = X;
OverallCost = sum(sum(C_start .* X));
a;
b;
disp('The Initial Feasible Solution Using Vogels Method');
disp('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
X
disp('Initial Cost:');
OverallCost
disp('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
end

4 Comments

CTRL+C will stop a script stuck in an infinite loop. If it's in an infinite loop then it is likely the stop condition on your loop is not being met
You're comparing to 0 exactly. It is sometimes possible for a rounding error to occur, so values that look like 0 are actually 1e-16. Did you try comparing to a tolerance instead?
This time I edited your question for you. Next time, please use the tools explained on this page to make your question more readable.
You should also try the debugger first to step through your code. It would also help if you attach a mat file or write some code that would allow us to run your code.
What do you mean? We still can't run your code and it is still not clear what you expect and want.

Sign in to comment.

Answers (0)

Categories

Find more on Scope Variables and Generate Names in Help Center and File Exchange

Asked:

on 14 Apr 2021

Commented:

Rik
on 15 Apr 2021

Community Treasure Hunt

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

Start Hunting!