algorithm - 在 Matlab 中通过遗传算法传递额外参数

标签 algorithm matlab genetic-algorithm

我在通过 Matlabs GA 函数传递数据时遇到问题。

我有一些数据存储在以下结构中:

param = 
               g: 9.8100
             rho: 1.2000
         mph_mps: 0.4470
        rpm2rads: 0.1047
gasoline_density: 0.7197
    liter2gallon: 0.2642
         MIN_SOC: 0.4000
         MAX_SOC: 0.8000
           grade: 0

ds1 = struct2dataset(param);
options1 = gaoptimset('InitialPopulation',1,'PopulationSize',100,'Generations',50,'PlotFcns',@gaplotbestfun,ds1);

然后我得到这个错误:

Error using gaoptimset (line 267)
Arguments must occur in name-value pairs.

我有更多的数据结构,我不想像他们所说的那样传递每个参数:

http://www.mathworks.com/help/gads/gaoptimset.html (即)

options = gaoptimset('param1',value1,'param2',value2,...)

最佳答案

使用函数句柄!!!

http://www.mathworks.com/help/optim/ug/passing-extra-parameters.html

% Set objective function
vfun=@(x)Dynamic_Programming_func(x,param);
% Set constraint function
nonlcon=@(x)constraint(x,param);

options1 = gaoptimset('InitialPopulation',ini,'PopulationSize',populations,'Generations',generations,'PlotFcns',@gaplotbestfun);

%% Solve problem 
[x,fval,exitflag,output] = ga(vfun,nvars,[],[],[],[],x_L,x_U,nonlcon,IntCon,options1)

所以,现在我的约束和目标函数正在传递它们需要的所有参数!

关于algorithm - 在 Matlab 中通过遗传算法传递额外参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29592669/

相关文章:

mysql - Matlab 损坏 MySQL 中的 blob?

matlab - 放置 MATLAB 图例,使其不重叠在图上

r - 如何从遗传算法(genalg)中获得最佳解决方案作为列

algorithm - 有向图节点邻居

algorithm - VHDL - 带串联的 N 次移位运算

algorithm - 在两组之间找到重复项的有效方法是什么?

python - 如何使用 Python 3.7 安装 MATLAB Engine API for Python?

genetic-algorithm - 旅行推销员的启发法

java - Flappy Bird 遗传算法种群改进

algorithm - 无法计算函数的增长率