Writing ga output to text file
3 views (last 30 days)
Show older comments
Hi, I am running genetic algorithm in MATLAB 2018b, the code is given below.I have some issues in writing the output to the text file. I would like to have my DV3.txt to store the decision variables, the objectives and the calculated values P1,P2 for all evaluations. At the moment it is not possible to do it this way as the output file is only appended for a short number of evaluations (less than 50). Any suggestions on why this is happening ? Let me know if my question is not clear. Thanks.
% MAINFILE
global iteration
iteration=0;
t1 = tic;
NumVar=7;
Xlow=[10 0.1 10 1 0.1 0.01 0.01];
Xup =[30 2 500 100 0.5 0.05 30];
parpool(8);
options = optimoptions('gamultiobj','UseParallel', true,...
'PopulationSize',15*NumVar,'Generations',40, 'CrossoverFraction',0.5,'CrossoverFcn',@crossoverintermediate ,'MutationFcn',...
@mutationadaptfeasible,'ParetoFraction',0.35);
[X,f,exitflag,output,final_pop]=gamultiobj(@funcfile,NumVar,[],[],[],[],...
Xlow,Xup,options);
delete(gcp('nocreate'))
time = toc(t1);
In the funcfile I am writing the following to store the output in text file
fid = fopen('DV3.txt', 'at');
fprintf(fid, '%f %f %f %f %f %f %f %f %f %f %f\r\n',...
X(1),X(2),X(3),X(4),X(5),X(6),X(7),F1,F2,P1,P2);
fclose(fid);
Where X(1) TO X(8) are my decision variables. F1 F2 are objectives and P1 and P2 are values calculated for a given set of X
3 Comments
KSSV
on 4 Oct 2018
At the moment it is not possible to do it this way as the output file is only appended for a short number of evaluations (less than 50).
why what is happening if iterations are more? You getting errors?
Answers (1)
Alan Weiss
on 4 Oct 2018
I suspect that the issue is having multiple workers trying to write to the same output file at the same time. See "Factors that Affect Results" in Improving Performance in Parallel Computing.
Alan Weiss
MATLAB mathematical toolbox documentation
2 Comments
Shreenath Krishnamurthy
on 16 Oct 2018
Edited: Shreenath Krishnamurthy
on 16 Oct 2018
Alan Weiss
on 16 Oct 2018
I am not sure what is wrong. It is possible that ga starts to sample points that cause the ODE solver to fail, and that this halts the process. Have you tried running in serial to see what occurs? Have you tried running the ODE solver at the points where ga seems to run into trouble?
Sorry, I am not an expert at debugging parallel programs, so I might not have the best suggestions.
Alan Weiss
MATLAB mathematical toolbox documentation
See Also
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!