How could I connect simulink model to the genetic algorithm toolbox ?

조회 수: 2 (최근 30일)
RAHUL MANKOTIA
RAHUL MANKOTIA 2017년 6월 7일
댓글: Jarin Tasnim 2023년 8월 7일
Hi, I am currently working on suspension system optimization via Genetic Algorithm. As the suspension model is in Simulink Interface, I couldn't find a way to connect simulink variables with the Population generated by genetic algorithm toolbox. Kindly help me with this.
  댓글 수: 2
wenlong Ma
wenlong Ma 2018년 6월 14일
i have the same Problem with you , do you find solution ? could you please tell me something about it ? or could you send me an mail : mwl.maschine@gmail.com
Andrea Valletta
Andrea Valletta 2020년 1월 16일
Is it possible for you to share the solution? I am currently unsuccesful to run the GA algorithm starting from the matlab script. ga function calls the objective function within which the simulink is started, as shown by Sebastian.
Thanks in advance

댓글을 달려면 로그인하십시오.

답변 (1개)

Sebastian Castro
Sebastian Castro 2017년 6월 7일
편집: Sebastian Castro 2017년 6월 7일
It's all in your cost function. For example:
function cost = costFunction(params)
myValue1 = params(1);
myValue2 = params(2);
% NOTE: This assumes the Simulink model has blocks that
% require variables named 'myValue1' and 'myValue2'
outputs = sim('modelName',<options>);
cost = <some_calculation>(outputs);
end
Hope this helps!
- Sebastian
  댓글 수: 2
Alberto Mora
Alberto Mora 2020년 3월 13일
편집: Alberto Mora 2020년 3월 13일
I did what you suggested but it seems that the function workspace cannot send the updated design variable to the Simulink workspace.
Therefore I solved the problem, as you can see below.
function cost = costFunction(params)
myValue1 = params(1);
myValue2 = params(2);
hws = get_param('modelName','modelworkspace'); % Handle the model's workspace
hws.DataSource = 'MAT-File';
hws.FileName = 'workspace';
hws.assignin('myValue1', myValue1);hws.assignin('myValue2', myValue2);% Send to Simulink the updated variables
% NOTE: This assumes the Simulink model has blocks that
% require variables named 'myValue1' and 'myValue2'
outputs = sim('modelName',<options>);
cost = <some_calculation>(outputs);
end
It works, but I am not sure that it is the most efficient way to overcome the problem. What do you think about that?
Thanks,
Alberto
Jarin Tasnim
Jarin Tasnim 2023년 8월 7일
@Alberto Mora hi, I am trying to optimize my simulink battery model parameters with genetic algorithm. Can I see your full matlab code from where the cost function is being called? I have written the cost function but I am facing some errors. It would be a great help! Thanks!
Jarin

댓글을 달려면 로그인하십시오.

카테고리

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