'too many input arguments' error in Genetic Algorithm optimization toolbox

3 次查看(过去 30 天)
I have a problem with my optimization code. I enter this code in matlab:
function Prob = objective_function()
rng default
% Indices
k = 15;
j = 2;
f = 10;
l = 5;
r0 = 6;
r = 6;
% Parameters
cr0 = randi([0 1],1,r0);
dr0f = randi([0 1],r0,f);
csl = randi([0 1],1,l);
cpjk = randi([0 1],j,k);
corj = randi([0 1],r,j);
pr0f = randi([0 1],r0,f);
cvjrk = randi([0 1],j,r,k);
% Objective Function
cb = zeros(r0,f);
cd = zeros(r,j);
cor = zeros(r0,f);
cr = zeros(j,k);
ctr = zeros(1,l);
cp2 = zeros(j,r,k);
for ii = 1:r0
for jj = 1:f
cb(ii,jj) = cr0(ii).*dr0f(ii,jj);
end
end
for ii = 1:r
for jj = 1:j
cd(ii,jj) = corj(ii,jj);
end
end
for ii = 1:r0
for jj = 1:f
cor(ii,jj) = pr0f(ii,jj);
end
end
for ii = 1:j
for jj = 1:k
cr(ii,jj) = cpjk(ii,jj);
end
end
for ii = 1:l
ctr(ii) = csl(ii);
end
for ii = 1:j
for jj = 1:r
for kk = 1:k
cp2(ii,jj,kk) = cvjrk(ii,jj,kk);
end
end
end
obj = sum([cb(:);cd(:);cor(:);cr(:);ctr(:);cp2(:)]);
Prob.obj = obj;
disp(obj);
Prob.k = k;
Prob.j = j;
Prob.f = f;
Prob.l = l;
Prob.r0 = r0;
Prob.r = r;
Prob.cr0 = cr0;
Prob.dr0f = dr0f;
Prob.csl = csl;
Prob.cpjk = cpjk;
Prob.corj = corj;
Prob.pr0f = pr0f;
Prob.cvjrk = cvjrk;
Prob.cb = cb;
Prob.cd = cd;
Prob.cor = cor;
Prob.cr = cr;
Prob.ctr = ctr;
Prob.cp2 = cp2;
Prob = obj;
end
I want to solve this problem with genetic algorithm but when I use optimization toolbox and select 'ga' for solving the model, then I encounter with ' Too many input arguments' error. Whereas when I solve this problem with 'Linprog', I haven't receive any error. How I can solve this problem with ga?

采纳的回答

Star Strider
Star Strider 2019-10-1
The ‘objective_function’ function does not take any input arguments, and it needs at least to take the vector of parameters you are optimizing as an input.
  12 个评论
S AsZ
S AsZ 2019-12-1
Not problem.You are one of the best members of this site and I am very thank you for your attention.
I thought that asking question in this site has restriction in terms of numbers because in last time that I asked a question nobody answered me and I had to remove my question.
Star Strider
Star Strider 2019-12-1
I very much appreciate your compliment!
There are no restrictions on the numbers. The more clearly you describe your problem and the question you would like to be answered, the better your chances will be to getting an answer. Also, it is quite possible that no one who saw your Question felt that they had the relevant knowledge to reply with an answer.
I am not in any way suggesting that the way you asked your Question was the problem,. however TUTORIAL: how to ask a question (on Answers) and get a fast answer may offer some suggestions on how best to construct it.

请先登录,再进行评论。

更多回答(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