calcuonce.m
来自「多智能体工具包」· M 代码 · 共 75 行
M
75 行
function calcuonce% CALCUONCE Operate the main computation.% Copyright (c) 1997-2000 Jiming Liu and Jianbing Wuglobal CELL HISTORY Response_Weight Class_Change_Dist Run_Times;global Current_Goal Total_Cell_Num Goal_Vary_Tm Ga_Generations; global Fitness_Fun Bit_Length Population_Size Total_Generations Cross_Prob;global Mutation_Prob Total_Cell_Num Single_Code_Width Reach_Now;if isempty(Ga_Generations) New_Population=chrom_generat(Bit_Length,Population_Size);else New_Population=Ga_Generations;end%Crossover_Pop=cross_chrom(New_Population,Cross_Prob);%Mutate_Pop=mutate(Crossover_Pop,Mutation_Prob);%Selected_Pop=select_gen(Fitness_Fun,Mutate_Pop);%Fittest_Chrom=Selected_Pop(1,:);%Selected_Pop(1,:)=[];%Selected_Pop=[Selected_Pop;Fittest_Chrom];%Ga_Generations=Selected_Pop;for mm=1:Population_Size Age=Run_Times*Population_Size+mm; Goal_History=[0 0 Age Current_Goal(1) Current_Goal(2)]; HISTORY=[HISTORY;Goal_History]; Sub_History=[]; Current_Code=New_Population(mm,:);% Current_Code=Selected_Pop(mm,:); for Loop=1:Total_Cell_Num Current_Cell_Code=Current_Code((Loop-1)*Single_Code_Width+1:Loop*... Single_Code_Width); Robot_Config(Loop,:)=get_code_config(Current_Cell_Code); end [Delta_Move,New_Object_Config]=move_object(Robot_Config); for Loop=1:Total_Cell_Num Temp_Config=Robot_Config(Loop,:)+Delta_Move; CELL(Loop,3:4)=get_new_config(Temp_Config); Sub_History=[Sub_History;1 Loop Age CELL(Loop,3:4)]; end CELL(Total_Cell_Num+1,3:4)=New_Object_Config; HISTORY=[HISTORY;Sub_History]; HISTORY=[HISTORY;3 1 Age New_Object_Config]; GO_Diff=New_Object_Config-Current_Goal; Current_GO_Dist=sqrt(GO_Diff(1)^2+GO_Diff(2)^2); if Current_GO_Dist<0.2 Reach_Now=Reach_Now+1; if Reach_Now>3 init_goal; Reach_Now=0; break; end else Reach_Now=0; end% plot_cell;endCrossover_Pop=cross_chrom(New_Population,Cross_Prob);Mutate_Pop=mutate(Crossover_Pop,Mutation_Prob);Selected_Pop=select_gen(Fitness_Fun,Mutate_Pop);Fittest_Chrom=Selected_Pop(1,:);Selected_Pop(1,:)=[];Selected_Pop=[Selected_Pop;Fittest_Chrom];Ga_Generations=Selected_Pop;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?