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

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?

 Akzeptierte Antwort

Star Strider
Star Strider am 1 Okt. 2019
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 Kommentare

Thank you very much.
My pleasure.
If my Answer helped you solve your problem, please Accept it!
S AsZ
S AsZ am 2 Okt. 2019
Bearbeitet: S AsZ am 2 Okt. 2019
Excuse me, I execute your help on my model code and the error resolved. But the software shows another error again: 'Undefiened function 'objective_function' for input arguments of type 'double'.
Can you help me again please?
I need more information. If the error resolved, that means the ga function was able to find and execute your ‘objective_function’ function.
What line is throwing the new error?
S AsZ
S AsZ am 2 Okt. 2019
Bearbeitet: S AsZ am 2 Okt. 2019
Thank you so much for your very good help. I check the file again and solve the issue. Now my model working very good. Thanks a lot
As always, my pleasure!
Excuse me so much I have a question again: How can I write multi objective functions with optimproblem format? My mean is using problem based method not using solver based method. ????????
I am not certain that the Optimization Toolbox can do multi-objective optimisation. To thje best of my knowledge, multi-objective optimizations require the gamultiobj function in the Global Optimization Toolbox.
I suggest that you post this as a new Question, since I have limited experience with multi-objective optimisation. Others here may have significantly more experience witth them.
Ok thank you ?
My pleasure.
I am sorry that I could not be of more help with your new problem.
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.
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by