필터 지우기
필터 지우기

Error,, too many input arguments!!

조회 수: 4 (최근 30일)
Yasmin Tamimi
Yasmin Tamimi 2011년 3월 27일
function [x,fval] = yasmin
%% Fitness function (objective function) and number of variables
fitnessFcn = @(x) ga_test(x);
numberOfVariables = 1310;
A=[]; %% (2596x1310)
b=[]; %% (1310x1)
Aeq=[]; %% (20x220)
beq=[]; %% (220x1)
%% Decision variables are bounded (either zero or one)
LB = zeros(1,1310);
UB = ones(1,1310);
Bound = [LB;UB];
% Create an options structure to be passed to GA % Three options namely 'CreationFcn', 'MutationFcn', and % 'PopInitRange' are required part of the problem. %% Population size to be at least the value of Number of variables, so that %% the individuals in each population span the space being searched.
options = gaoptimset('CreationFcn',@int_pop,'MutationFcn',@int_mutation, ... 'PopInitRange',Bound,'Display','iter','StallGenL',100,'Generations',150, ... 'PopulationSize',1310,'PlotFcns',{@gaplotbestf,@gaplotbestindiv});
[x,fval] = ga(fitnessFcn,numberOfVariables,A,b,Aeq,beq,LB,UB,[],options);
x
%%************************************************************************* %%*************************************************************************
% Mutation function to generate childrens satisfying the range and integer % constraints on decision variables.
function mutationChildren = int_mutation(parents,options,GenomeLength, ... FitnessFcn,state,thisScore,thisPopulation)
shrink = .01;
scale = 1;
scale = scale - shrink * scale * state.Generation/options.Generations;
range = options.PopInitRange;
lower = range(1,:);
upper = range(2,:);
scale = scale * (upper - lower);
mutationPop = length(parents);
% The use of ROUND function will make sure that childrens are integers.
mutationChildren = repmat(lower,mutationPop,1) + ... round(repmat(scale,mutationPop,1) .* rand(mutationPop,GenomeLength));
% End of mutation function
%%************************************************************************* %%*************************************************************************
function Population = int_pop(GenomeLength,FitnessFcn,options)
totalpopulation = sum(options.PopulationSize);
range = options.PopInitRange;
lower= range(1,:);
span = range(2,:) - lower;
% The use of ROUND function will make sure that individuals are integers.
Population = repmat(lower,totalpopulation,1) + ... round(repmat(span,totalpopulation,1) .* rand(totalpopulation,GenomeLength));
% End of creation function
When I run my m-file from the command line I write: x=ga(@ga_test,1310,A,b,Aeq,beq,LB,UB,[],options) OR [x,fval]=ga(@ga_test,1310,A,b,Aeq,beq,LB,UB,[],options)
and I get error using ga,, Too many input arguments
So I also tried : x=ga(yasmin) but I keep getting the same error.
Any help in this regard will be highly appreciated
Thanx in advance.
  댓글 수: 2
Atakan
Atakan 2011년 3월 28일
just try yasmin on command window,it will work...
Yasmin Tamimi
Yasmin Tamimi 2011년 3월 28일
Actually this is what I've done, but unfortunately it didn't work!!

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2011년 3월 27일
Which version are you using?
Please check
which -all ga
If you see anything other than an entry under the gads toolbox, you might have a conflicting function.
  댓글 수: 13
Walter Roberson
Walter Roberson 2011년 3월 29일
Are you trying to put in a numeric value for GenomeLength in a 'function' line? That isn't allowed. If you must, for some reason, override the value you are passing in (something that is more often a mistake than not) then use an assignment after the 'function' line, such as
GenomeLength = 1310;
Yasmin Tamimi
Yasmin Tamimi 2011년 3월 29일
Yes, that was my error. I've been using numeric values in a function line!! I run my example for both GenomeLength = 1310 which was wrong and the correct was for GenomeLength = 30 (#variables in the fitness function only)as defined in the reference manual.
Thank u very much for ur help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by