📄 dynamic.m
字号:
function y = dynamic(b,k,choices,stages,X,table)
inf2 = 10^7;
A = first(X,table);
B = zeros(1,stages+1);
table = setinf(A,table);
sA = size(A);
while sA(1) < k
i = 1;
while i <= stages
if i == 1
if sA(1) >= choices^i %the ith stage all have been set to inf
i = i + 1;
else
path = stage(1,choices,stages,X,A,table);
if path == 0 %the value of this path is inf
i = i + 1;
else
m = norm(path);
if m > inf2
i = i + 1;
end
if m < inf2
C = change(path,X,table);
r = check(C,A,X,table);
if r ~= 0
r = checkb(C,B,X,table);
end
if r ~= 0
B = [B;C];
tB = size(B);
if tB > 1
B = arrange(B);
end
table = setinf(C,table);
end
i = i + 1;
end
end
end
else
if sA(1) >= choices^i %the ith stage all have been set to inf
i = i + 1;
else
path1 = stage(i,choices,stages,X,A,table);
if path1 == 0 %(all have been set to inf)
i = i + 1;
else
for j = 1:i-1
path(j) = A(sA(1),j);
end
path = [path(1:(i-1)),path1];
m = norm(path);
if m > inf2
i = i + 1;
end
if m < inf2
r = checkpath(b,path,stages,X,table);
if r ~= 0
C = change(path,X,table);
r = check(C,A,X,table);
if r ~= 0
r = checkb(C,B,X,table);
end
if r ~= 0
B = [B;C];
if tB > 1
B = arrange(B);
end
table = setinf(C,table);
end
end
i = i + 1;
end
end
end
end
end
sB = size(B);
sA = size(A);
if sB(1) == 1
disp(['There are only ',num2str(sA(1)),' path(s)']);
break
else
%if sA(1) + sB(1) >= k + 1
% A = [A;B(2:k-sA(1)+1,:)];
% break
%else
A = [A;B(2,:)];
B = sub(B);
%end
end
sA = size(A);
%sB = size(B);
end
% if sA(1) < k
% A = [A;B(2:k-sA(1)+1,:)];
% end
%sA = size(A);
for i = 1:sA(1)
A(i,:) = getvalue(A(i,1:sA(2)-1),X,table);
end
y = A;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -