%% This is an auto generated M file to do optimization with the Genetic Algorithm and
% Direct Search Toolbox. Use GAOPTIMSET for default GA options structure.
int c(8,8)={{0,12,14,10,20,25,27,18 },{12,0,5,13,6,14,41,39},{14,5,0,16,18,20,30,32},{10,13,16,0,14,27,15,12},{20,6,18,14,0,22,18,26},{25,14,20,27,22,0,27,32},{27,41,30,15,18,27,0,15},{18,39,32,12,26,32,15,0}}
int X(8,8);
int popsize;
int chromlength;
% #include
% #include
%
% {
% int i,j;
% srand((int)time(0));
%
% for(i=0;i<10;i++)
% {
% j=rand()%2;
% printf(" %d ",j);
% }
sum=0;
for i=1:8;
for j=i+1:8;
% srand((int)time(0));
% X[i][j]=rand();
% X[i][j]=rand()%2;
A=eye(40,28); % 生成一个 数值数组
A_str1=int2str(A) % 转换成 串数组。请读者自己用 size 检验。
%X[i][j]=ceil(fix(rand(0,1)*40));
if R(x)<0.9||AvgDelay>10
sum=c(i,j)*X(i,j)+(41*(R(x)-0.9)).^2;
else sum=c(i,j)*X(i,j);
%printf("%d",sum);
end
end
end
%initPop=initializega(40,[0,1],'fitness');%
%%Fitness function
fitnessFunction = @zuiyou;
%%Number of Variables
nvars = 8 ;
%Linear inequality constraints
Aineq = [0 12 14 10 20 25 27 18 ; 12 0 5 13 6 14 41 39 ; 14 5 0 16 18 20 30 32 ; 10 13 16 0 14 27 15 12 ; 20 6 18 14 0 22 18 26 ; 25 14 20 27 22 0 27 32 ; 27 41 30 15 18 27 0 15 ; 18 39 32 12 26 32 15 0 ];
Bineq = [3000 ; 3000 ; 3000 ; 3000 ; 3000 ; 3000 ; 3000 ; 3000 ];
%Linear equality constraints
Aeq = [];
Beq = [];
%Bounds
LB = 0 ;
UB = 1 ;
%Nonlinear constraints
nonlconFunction = [];
%Start with default options
options = gaoptimset;
%%Modify some parameters
pop=round(rand(40,28));
options = gaoptimset(options,'PopulationType' ,'bitString');
options = gaoptimset(options,'PopulationSize' ,40);
options = gaoptimset(options,'chromlength',28 );
options = gaoptimset(options,'MutationFcn' ,{ @mutationgaussian 1 1 });
options = gaoptimset(options,'Display' ,'off');
options = gaoptimset(options,'PlotFcns' ,{ @gaplotbestf @gaplotdistance @gaplotselection });
%%Run GA
[X,FVAL,REASON,OUTPUT,POPULATION,SCORES] = ga(fitnessFunction,nvars,Aineq,Bineq,Aeq,Beq,LB,UB,nonlconFunction,options);
运行提示:too many input arguments
该怎么解决啊?