我是MatLab的新手,我正在编写一个MatLab GA程序来解决特定的调度问题。问题是我无法弄清楚一个特定错误的原因。这是主要计划:
1 FitnessFcn = @(seq)rate_fitness(seq,batch,obs);
2 MyPlotFcn = @(options,state,flag)rate_plot(options,state,flag,batch,seq,obs);
3 options = gaoptimset('PopulationType','custom','PopInitRange',[1;obs]);
4 options = gaoptimset(options,'CreationFcn',@rate_create,'CrossoverFcn', ...
@rate_crossover,'MutationFcn',@rate_mutate,'PlotFcn',MyPlotFcn);
5 [seq,objfunc,reason,output] = ga(FitnessFcn,obs,[],[],[],[],[],[],[],options);
这是rate_plot函数:
function state = rate_plot(options,state,flag,batch,seq,obs)
if strcmpi(flag,'init')
cla;
end
{some code that works by itself}
end
这是rate_create函数:
function pop = create_permutations(NVARS,FitnessFcn,options)
totalPopulationSize = sum(options.PopulationSize);
n = NVARS;
pop = cell(totalPopulationSize,1);
for i = 1:totalPopulationSize
pop{i} = randperm(n);
end
我得到的错误(但仅在包含'PlotFcn'选项时)是:
Undefined function or variable 'seq'.
Error in @(options,state,flag)rate_plot(options,state,flag,batch,seq,obs)
Error in gadsplot>callOnePlotFcn (line 179)
optimvalues = plotfcn(varargin{1:end});
Error in gadsplot (line 132)
[state,optimvalues] = callOnePlotFcn(fname, plotNames{i}, state, options, ...
optimvalues, 'init', args{i}{:});
Error in gaunc (line 54)
state = gadsplot(options,state,currentState,'Genetic Algorithm');
Error in ga (line 348)
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Error in rate_run (line 5)
[seq,objfunc,reason,output] = ga(FitnessFcn,obs,[],[],[],[],[],[],[],options);
有人有什么想法吗?坦克!