dynamic3.m

来自「数组排序,按照数组的某个元素进行排序,使用请查看」· M 代码 · 共 113 行

M
113
字号
function y = dynamic3(k,stages,diffs,S,F,X,table,tablec,tables)

A = first3(stages,diffs,S,X,table,tablec);
B = zeros(1,stages+1);
table = setinf3(A,table);
sA = size(A);
sB = size(B);
inf2 = 10^8;
while (sA(1) < k)       
       i = 1;
        while i <= stages
            if i == 1
                if sA(1) >= tables(stages-i+1,2)- tables(stages-i+1,1) + 1   %the ith stage all have been set to inf
                    i = i + 1;
                else                       
                       path = stage3(1,stages,diffs,S,A,table,tablec,tables);  
                       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 = change3(path,F,table);
                               r = check3(C,A,F,X,table);       
                                   if r ~= 0
                                       r = checkb3(C,B,F,X,table);
                                   end
                                   if r ~= 0
                                       B = [B;C];
                                       tB = size(B);
                                       if tB > 1
                                           B = arrange(B);
                                       end
                                       table = setinf3(C,table);
                                   end
                               i = i + 1;
                               end   
                       end
                end
            else
                if sA(1) >= tables(stages-i+1,2)- tables(stages-i+1,1) + 1  %the ith stage all have been set to inf
                    i = i + 1;
                else
                        path1 = stage3(i,stages,diffs,S,A,table,tablec,tables);
                        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 = checkpath3(b,path,stages,X,table);
                                 %  if r ~= 0
                                       C = change3(path,F,table);
                                       r = check3(C,A,F,X,table);
                                       if r ~= 0
                                         r = checkb3(C,B,F,X,table);
                                       end
                                       if r ~= 0
                                       B = [B;C];
                                          if tB > 1
                                              B = arrange(B);
                                          end
                                       table = setinf3(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
sA = size(A);
%y = A;
%if sA(1) < k
%A = [A;B(2:k-sA(1)+1,:)];
%end
 for i = 1:sA(1)
     y(i,:) = getvalue3(A(i,1:sA(2)-1),F,X,table);
 end
%y = table;




⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?