Email: helpdesk@telkomuniversity.ac.id

This Portal for internal use only!

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • Visual Paradigm
  • IBM
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Categories
  • Microsoft
    • Microsoft Apps
    • Office
    • Operating System
    • VLS
    • Developer Tools
    • Productivity Tools
    • Database
    • AI + Machine Learning
    • Middleware System
    • Learning Services
    • Analytics
    • Networking
    • Compute
    • Security
    • Internet Of Things
  • Adobe
  • Matlab
  • Google
  • Visual Paradigm
  • WordPress
    • Plugin WP
    • Themes WP
  • Opensource
  • Others
More Categories Less Categories
  • Get Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • My Account
    • Download
    • Cart
    • Checkout
    • Login
  • About Us
    • Contact
    • Forum
    • Frequently Questions
    • Privacy Policy
  • Forum
    • News
      • Category
      • News Tag

iconTicket Service Desk

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • Visual Paradigm
  • IBM
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Menu
  • Home
    • Download Application Package Repository Telkom University
    • Application Package Repository Telkom University
    • Download Official License Telkom University
    • Download Installer Application Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • All Pack
    • Microsoft
      • Operating System
      • Productivity Tools
      • Developer Tools
      • Database
      • AI + Machine Learning
      • Middleware System
      • Networking
      • Compute
      • Security
      • Analytics
      • Internet Of Things
      • Learning Services
    • Microsoft Apps
      • VLS
    • Adobe
    • Matlab
    • WordPress
      • Themes WP
      • Plugin WP
    • Google
    • Opensource
    • Others
  • My account
    • Download
    • Get Pack
    • Cart
    • Checkout
  • News
    • Category
    • News Tag
  • Forum
  • About Us
    • Privacy Policy
    • Frequently Questions
    • Contact
Home/Matlab/Genetic Algorithm Custom Output

Genetic Algorithm Custom Output

PuTI / 2025-01-27
Genetic Algorithm Custom Output
Matlab News

Hello, I’m trying to optimize a simple Simulink model output by using Genetic Algorithm. Three different output values are implemented in this model. The first one is used as cost value. Hovewer, the other two values are not assigned to anything. I want to get these outputs as timeseries after the Genetic Algorithm calculations, like "The second output of Generation XX Individual YY is …". When the calculations are done with single core, I can get all the results I want, but when the parallel toolbox is used, only the last generation and last individual is visible after the calculations. How can I fix that parallel calculation? Here is my simple code that gives all individuals and cost values for me, but I need the other two outputs of simulation. Thanks.

clear all;clc;,
%%
tic
saveFlag = 0;
rng(‘shuffle’);
objectiveFunction = @(params) nlaSimResults(params);

lowerBound = [1000 0.2];
upperBound = [25000 0.8];

popSize = 10;
genSize = 20;

options = optimoptions(‘ga’,’UseParallel’,true,’UseVectorized’,false,’PopulationSize’,popSize,’MaxGenerations’,genSize,’OutputFcn’,@gaOutputFunction,’Display’,’iter’);

[bestParams, minCost, ~, optResults, optPop, optScores] = ga(objectiveFunction,2,[],[],[],[],lowerBound,upperBound,[],options);
optimTime = toc;

if saveFlag == 1; save(‘OptimResulst’,’bestParams’,’minCost’,’optResults’,’optScores’,’optimTime’,’popSize’,’genSize’); end

function cost = nlaSimResults(params)
global otherVars

Altitude = params(1);
Mach = params(2);

assignin(‘base’,’Altitude’,Altitude);
assignin(‘base’,’Mach’,Mach);

sim(‘debugModel’,10); % Simulation Model with Altitude and Mach inputs
cost = logsout{1}.Values.Data(1); % The first output of the model is assigned as cost

if isempty(otherVars)
otherVars = {};
end

otherVars = [otherVars; logsout{2}.Values.Data logsout{3}.Values.Data];

assignin(‘base’,’otherVars’,otherVars);
end

function [state, options, flag] = gaOutputFunction(options, state, flag)
persistent popHistory bestValues bestIndividuals otherVarsHistory
global otherVars

if isempty(popHistory)
popHistory = {};
bestValues = [];
bestIndividuals = [];
otherVarsHistory = {};
end

[bestScore, bestIdx] = min(state.Score);
bestValues = [bestValues; bestScore];
bestIndividuals = [bestIndividuals; state.Population(bestIdx, :)];

popHistory(state.Generation + 1) = {state.Population};

otherVarsHistory{state.Generation + 1} = otherVars;
otherVars = [];

assignin(‘base’,’popHistory’,popHistory);
assignin(‘base’,’bestValues’,bestValues);
assignin(‘base’,’bestIndividuals’,bestIndividuals);
assignin(‘base’,’otherVarsHistory’,otherVarsHistory);
end

My model is so simple, just returning the sum, product and division of the altitude and mach values.Hello, I’m trying to optimize a simple Simulink model output by using Genetic Algorithm. Three different output values are implemented in this model. The first one is used as cost value. Hovewer, the other two values are not assigned to anything. I want to get these outputs as timeseries after the Genetic Algorithm calculations, like "The second output of Generation XX Individual YY is …". When the calculations are done with single core, I can get all the results I want, but when the parallel toolbox is used, only the last generation and last individual is visible after the calculations. How can I fix that parallel calculation? Here is my simple code that gives all individuals and cost values for me, but I need the other two outputs of simulation. Thanks.

clear all;clc;,
%%
tic
saveFlag = 0;
rng(‘shuffle’);
objectiveFunction = @(params) nlaSimResults(params);

lowerBound = [1000 0.2];
upperBound = [25000 0.8];

popSize = 10;
genSize = 20;

options = optimoptions(‘ga’,’UseParallel’,true,’UseVectorized’,false,’PopulationSize’,popSize,’MaxGenerations’,genSize,’OutputFcn’,@gaOutputFunction,’Display’,’iter’);

[bestParams, minCost, ~, optResults, optPop, optScores] = ga(objectiveFunction,2,[],[],[],[],lowerBound,upperBound,[],options);
optimTime = toc;

if saveFlag == 1; save(‘OptimResulst’,’bestParams’,’minCost’,’optResults’,’optScores’,’optimTime’,’popSize’,’genSize’); end

function cost = nlaSimResults(params)
global otherVars

Altitude = params(1);
Mach = params(2);

assignin(‘base’,’Altitude’,Altitude);
assignin(‘base’,’Mach’,Mach);

sim(‘debugModel’,10); % Simulation Model with Altitude and Mach inputs
cost = logsout{1}.Values.Data(1); % The first output of the model is assigned as cost

if isempty(otherVars)
otherVars = {};
end

otherVars = [otherVars; logsout{2}.Values.Data logsout{3}.Values.Data];

assignin(‘base’,’otherVars’,otherVars);
end

function [state, options, flag] = gaOutputFunction(options, state, flag)
persistent popHistory bestValues bestIndividuals otherVarsHistory
global otherVars

if isempty(popHistory)
popHistory = {};
bestValues = [];
bestIndividuals = [];
otherVarsHistory = {};
end

[bestScore, bestIdx] = min(state.Score);
bestValues = [bestValues; bestScore];
bestIndividuals = [bestIndividuals; state.Population(bestIdx, :)];

popHistory(state.Generation + 1) = {state.Population};

otherVarsHistory{state.Generation + 1} = otherVars;
otherVars = [];

assignin(‘base’,’popHistory’,popHistory);
assignin(‘base’,’bestValues’,bestValues);
assignin(‘base’,’bestIndividuals’,bestIndividuals);
assignin(‘base’,’otherVarsHistory’,otherVarsHistory);
end

My model is so simple, just returning the sum, product and division of the altitude and mach values. Hello, I’m trying to optimize a simple Simulink model output by using Genetic Algorithm. Three different output values are implemented in this model. The first one is used as cost value. Hovewer, the other two values are not assigned to anything. I want to get these outputs as timeseries after the Genetic Algorithm calculations, like "The second output of Generation XX Individual YY is …". When the calculations are done with single core, I can get all the results I want, but when the parallel toolbox is used, only the last generation and last individual is visible after the calculations. How can I fix that parallel calculation? Here is my simple code that gives all individuals and cost values for me, but I need the other two outputs of simulation. Thanks.

clear all;clc;,
%%
tic
saveFlag = 0;
rng(‘shuffle’);
objectiveFunction = @(params) nlaSimResults(params);

lowerBound = [1000 0.2];
upperBound = [25000 0.8];

popSize = 10;
genSize = 20;

options = optimoptions(‘ga’,’UseParallel’,true,’UseVectorized’,false,’PopulationSize’,popSize,’MaxGenerations’,genSize,’OutputFcn’,@gaOutputFunction,’Display’,’iter’);

[bestParams, minCost, ~, optResults, optPop, optScores] = ga(objectiveFunction,2,[],[],[],[],lowerBound,upperBound,[],options);
optimTime = toc;

if saveFlag == 1; save(‘OptimResulst’,’bestParams’,’minCost’,’optResults’,’optScores’,’optimTime’,’popSize’,’genSize’); end

function cost = nlaSimResults(params)
global otherVars

Altitude = params(1);
Mach = params(2);

assignin(‘base’,’Altitude’,Altitude);
assignin(‘base’,’Mach’,Mach);

sim(‘debugModel’,10); % Simulation Model with Altitude and Mach inputs
cost = logsout{1}.Values.Data(1); % The first output of the model is assigned as cost

if isempty(otherVars)
otherVars = {};
end

otherVars = [otherVars; logsout{2}.Values.Data logsout{3}.Values.Data];

assignin(‘base’,’otherVars’,otherVars);
end

function [state, options, flag] = gaOutputFunction(options, state, flag)
persistent popHistory bestValues bestIndividuals otherVarsHistory
global otherVars

if isempty(popHistory)
popHistory = {};
bestValues = [];
bestIndividuals = [];
otherVarsHistory = {};
end

[bestScore, bestIdx] = min(state.Score);
bestValues = [bestValues; bestScore];
bestIndividuals = [bestIndividuals; state.Population(bestIdx, :)];

popHistory(state.Generation + 1) = {state.Population};

otherVarsHistory{state.Generation + 1} = otherVars;
otherVars = [];

assignin(‘base’,’popHistory’,popHistory);
assignin(‘base’,’bestValues’,bestValues);
assignin(‘base’,’bestIndividuals’,bestIndividuals);
assignin(‘base’,’otherVarsHistory’,otherVarsHistory);
end

My model is so simple, just returning the sum, product and division of the altitude and mach values. genetic algorithm, parallel computing toolbox MATLAB Answers — New Questions

​

Tags: matlab

Share this!

Related posts

Optimal decimation to Log Simulation Data
2025-05-18

Optimal decimation to Log Simulation Data

I need to use a scope to display the current i and the power P as functions of the voltage V, with the curves obtained for various irradiance levels and temperatures
2025-05-18

I need to use a scope to display the current i and the power P as functions of the voltage V, with the curves obtained for various irradiance levels and temperatures

Break in and break away points on Root Locus
2025-05-18

Break in and break away points on Root Locus

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Categories

  • Matlab
  • Microsoft
  • News
  • Other
Application Package Repository Telkom University

Tags

matlab microsoft opensources
Application Package Download License

Application Package Download License

Adobe
Google for Education
IBM
Matlab
Microsoft
Wordpress
Visual Paradigm
Opensource

Sign Up For Newsletters

Be the First to Know. Sign up for newsletter today

Application Package Repository Telkom University

Portal Application Package Repository Telkom University, for internal use only, empower civitas academica in study and research.

Information

  • Telkom University
  • About Us
  • Contact
  • Forum Discussion
  • FAQ
  • Helpdesk Ticket

Contact Us

  • Ask: Any question please read FAQ
  • Mail: helpdesk@telkomuniversity.ac.id
  • Call: +62 823-1994-9941
  • WA: +62 823-1994-9943
  • Site: Gedung Panambulai. Jl. Telekomunikasi

Copyright © Telkom University. All Rights Reserved. ch

  • FAQ
  • Privacy Policy
  • Term

This Application Package for internal Telkom University only (students and employee). Chiers... Dismiss