【发布时间】:2014-07-03 07:31:57
【问题描述】:
我正在尝试使用 MATLAB ga() 函数解决优化问题。
我会尽量简短。它基本上是一个最小二乘拟合问题,我在其中操纵一些输入来尝试匹配目标函数。问题有 40 个变量。有界约束、线性等式、线性不等式和非线性约束。
在我让 MATLAB 选择初始种群之前,但结果很差。我觉得这是由于 MATLAB 的选择缺乏多样性。所以我编写了一个函数来创建一个满足除非线性约束之外的所有约束的初始种群(这些是在模拟后计算的)。
我在 MATLAB Central Exchange 上搜索了一个与同一主题相关的问题,并且是从 2007 年开始的,从未得到解决。
这是可能有问题的代码部分。我很抱歉它这么大,但我认为它的布局很合乎逻辑。我正在使用 ga(problem),这段代码的大部分只是列出了所有的约束。
ineq_con_tau_LB = [zeros(1,nInjections) zeros(1,nInjections) tau_LB/60/1e6 tau_LB/60/1e6 tau_LB/60/1e6 0]
ineq_con_tau_UB = [zeros(1,nInjections) zeros(1,nInjections) 0 0 -tau_UB/60/1e6 0]
problem_structure.Aineq = [ineq_con_tau_LB; ineq_con_tau_UB];
problem_structure.bineq = [nInjections*CP.reactorVolume;-nInjections*CP.reactorVolume];
eq_con_antisolvent = [ones(1,nInjections) zeros(1,nInjections) -1 0 0 0];
eq_con_puresolvent = [zeros(1,nInjections) ones(1,nInjections) 0 -1 0 0];
problem_structure.Aeq = [eq_con_antisolvent; eq_con_puresolvent];
problem_structure.beq = [0 0]';
%Upper and lower bounds.
Atotal_min = 10; Atotal_max = 1000;
Stotal_min = 10; Stotal_max = 1000;
Vfeed_min = 10; Vfeed_max = 1000;
ypercent_min = 0.02;
ypercent_max = 0.07;
problem_structure.lb = [ zeros(1,nInjections) zeros(1,nInjections) Atotal_min Stotal_min Vfeed_min ypercent_min];
problem_structure.ub = [repmat(inf,1,nInjections) repmat(inf,1,nInjections) Atotal_max Stotal_max Vfeed_max ypercent_max];
problem_structure.nonlcon = @constr;
problem_structure.nvars = 2*nInjections + 4;
problem_structure.fitnessfcn = @objfun;
problem_structure.intcon = [];
populationsize = 5;
gapop = dissolution_optimization_initialpop(populationsize,nInjections,problem_structure.Aineq, ...
problem_structure.bineq, ...
problem_structure.lb(:), ...
problem_structure.ub(:), ...
tau_LB, ...
tau_UB, ...
ypercent_min, ...
ypercent_max);
problem_structure.options = gaoptimset('Generations', 25,...
'PopulationSize',populationsize, ...
'InitialPopulation',gapop, ...
'OutputFcn', @sse_outputfcn, ...
'MutationFcn', {@mutationadaptfeasible});
problem_structure.options
save('gapop_save','gapop')
[x,fval,exitflag,output] = ga(problem_structure)
非常感谢您提供的任何帮助。请帮忙! :(((
【问题讨论】:
标签: matlab constraints genetic-algorithm constraint-programming