Error,, too many input arguments!!
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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
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;
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!