In GA optimisation, how to pass arguments about generation and individual number into the fitness function?

1 view (last 30 days)
Hello,
I'm trying to run a gamultiobj optimisation in parallel. It runs fine in series, however I get an error when setting up a parallel computing scheme. I believe it stems from a function within my fitness function which has to create some text files. It runs fine in series as the text files get overwritten however the same text file is being accessed simultaneously by different cores when run in parallel. Therefore, I was thinking of adding a tag name made of the current generation number and individual number to the files to differentiate them. But I'm not sure how to pass these variables to the fitness function and if it's even feasible.
I'm also open to other suggestions.
Many thanks in advance for your help.

Answers (1)

Matt J
Matt J on 5 Nov 2013
You could use labindex() to help generate a worker-dependent tag for your text files.
  2 Comments
Meonnebula
Meonnebula on 8 Nov 2013
Edited: Meonnebula on 8 Nov 2013
Hi thanks for your help. Unfortunately the labindex doesn't work with the parfor loop used by the ga algorithm (always set to 1 as exchange of information between workers isn't supported). But I have found an answer in the following discussion: http://www.mathworks.co.uk/matlabcentral/answers/30294
The following line of code acts in a similar manner by returning the current task ID, which is a number between 1 and the number of workers or cores used.
t = getCurrentTask(); t.ID
Many thanks though as you pointed me towards the right direction.
Matt J
Matt J on 8 Nov 2013
The following line of code acts in a similar manner by returning the current task ID, which is a number between 1 and the number of workers or cores used.
Now that I know that you're using PARFOR and not SPMD, I no longer think it's a good idea to generate a worker-dependent tag, even with getCurrentTask(). You should probably generate a tag based on iteration number as was also suggested in that link you posted.
The order in which parfor iterations are executed is not to be counted on. I'm not sure you can even count on them to be sequential within a worker. So, iteration-dependent tags would be safer.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!