sdynamic.m

来自「清华大学运筹学课件」· M 代码 · 共 73 行

M
73
字号
% the program is with the scheduling problem in the dynamic programming
% please input the scheduling matrix 

input('the program is with the scheduling problem in the dynamic programming')

m=2;
n=input('Please input the number=')

S=input('Please input the scheduling matrix S(m,n)=')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

for i=1:n
    opt_schedule(i)=0;
end

for k=1:n
 
    mintemp=S(1,1);
    
    for i=1:m
        for j=1:n
          if S(i,j)<mintemp
             mintemp=S(i,j);
          end
        end
    end

    for i=1:m
      for j=1:n
        if S(i,j)==mintemp;
            linetemp=i;
            columntemp=j;
        end
      end
    end
 
    if linetemp==1
        i=1;
        while 1
            if opt_schedule(i)==0
              opt_schedule(i)=columntemp;
              break
            end
            i=i+1;
        end
    elseif linetemp==2
        i=n;
        while 1
            if opt_schedule(i)==0
             opt_schedule(i)=columntemp;
             break
            end
           i=i-1;
        end
    end
    
    
  for i=1:m
    S(i,columntemp)=1000;
  end
   
end

opt_schedule
     
     
     
     
     
     
     
    

⌨️ 快捷键说明

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