fitness.m

来自「多智能体工具包」· M 代码 · 共 66 行

M
66
字号
function Fitness_Value=fitness(chromosome)% FITNESS	Fitness function for Genetic Algorithm.%     Copyright (c) 1997-2000 Jiming Liu and Jianbing Wuglobal Total_Cell_Num CELL Current_Goal Step_Change_Ratio Step_Ratio;global Last_MoveDirection Single_Code_Width;Object_Config=get_object_config(3,1);Goal_Vector=Current_Goal-Object_Config;GO_dist=sqrt(Goal_Vector(1)^2+Goal_Vector(2)^2);Robot_Config=[]; for mm=1:Total_Cell_Num  Current_Cell_Code=chromosome((mm-1)*Single_Code_Width+1:mm*...                 Single_Code_Width);  Robot_Config(mm,:)=get_code_config(Current_Cell_Code);end% ------- Join Force -------- %[Sum_Force,Force_Direction,Force_Vector]=force_calcu(Robot_Config);if Sum_Force==0  Sum_Force=0.0001;end% ------- Cosine of Co Angle ------- %Cos_Angle=(Goal_Vector(1)*Force_Vector(1)+Goal_Vector(2)*Force_Vector(2))/...         (GO_dist*Sum_Force);if Cos_Angle<0  Cos_Angle=0;end% ------ the Change of the Step   f3 ------ %Step_Diff=Sum_Force*Step_Ratio-GO_dist*Step_Change_Ratio;Step_Limit=exp(-5*Step_Diff*Step_Diff);% ------- Force Difference before and aftet the motion   f4 ------- %if isempty(Last_MoveDirection)  Direction_Limit=1;else  Diff_Direction=Last_MoveDirection-Force_Direction;  Direction_Limit=exp(-3*Diff_Direction*Diff_Direction);end% ---- F5 : average distance between the robtos and the Object -----%Total_Dist=0;%for mm=1:Total_Cell_Num%  Diff_Now=Robot_Config(mm,:)-Object_Config;%  Total_Dist=Total_Dist+sqrt(Diff_Now(1)^2+Diff_Now(2)^2)/Total_Cell_Num;%end%Fit_AvergeDist=1/Total_Dist^3;% ---- F6 : average distance between the robtos and the Object -----Total_Dist=[];for mm=1:Total_Cell_Num  Diff_Now=Robot_Config(mm,:)-Object_Config;  Dist_Now=sqrt(Diff_Now(1)^2+Diff_Now(2)^2);  Total_Dist=[Total_Dist Dist_Now];endMax_Dist=max(Total_Dist);Fit_AvergeDist=1/Max_Dist^4;%-----------------------------------Fitness_Value=Sum_Force*Cos_Angle^2*Fit_AvergeDist;

⌨️ 快捷键说明

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