Population Formulation in GA

2 views (last 30 days)
Chockalingam Kasi
Chockalingam Kasi on 26 Dec 2013
Answered: Alan Weiss on 26 Dec 2013
Hi,
I am new to Genetic Algorithm and am writing the following code for the Custom Population Type to run Genetic Algorithm. I have an array of 24 by 14 which is my so called "ideal" population called "rg_dev_avail.dat" which is loaded prior to running this program.
I am trying to formulate a random set of new population for each generation of the Genetic Algorithm which is limited by the ideal population.
For some reason i am not able to run this code and i believe the "goto" function could be causing the error. I do not get any errors when i run this in matlab but i do not get any results and no variables are loaded onto my workspace as well..
The section of the code is as follows...
for j=1:1:24
for t = 1:1:14
% LABEL noD
no_of_dev = round(rand*500);
current_max_dev = rg_dev_avail(j:t);
if no_of_dev > current_max_dev
goto('noD') % If does not satisfy condition redo earlier step
return
else
new_rg_dev_list(j:t) = no_of_dev;
end
end
end
Could anyone advise on how i could modify this code to run my application please.
Much thanks in advance for the assistance!

Answers (1)

Alan Weiss
Alan Weiss on 26 Dec 2013
Indeed, 'goto' is not a valid MATLAB command. If you want to call a function named noD at that point in your program, just call it.
It seems as if you are programming with global variables. That is not usually a good idea. Generally, the scope of variables is local to a function. If you have parameters you want to change, pass them in and out of your functions like this
[out1,out2,out3] = myfcn(arg1,arg2,arg3,arg4)
You might want to read some introductory material on programming in MATLAB, such as the Getting Started guide and the function basics documentation.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

Community Treasure Hunt

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

Start Hunting!