Saving/Reading variables based on ga optimization results

13 次查看(过去 30 天)
I have a question with regards to the ga solver in which I want to get the output of specific intermediate variables within the problem I am trying to solve. I only want to see the results corresponding to the optimal values.
In my objective function, I am trying to minimize the electricity cost of a building by optimizing the resistance of the insulation materials of the walls. The optimization works fine and I can get the x values and the cost of electricity by default. The script is long but lets say I have the zone indoor temperature (ZoneTemp) and the electricity end use (ElecUse) as intermediate variables that the final electricity cost depends on, how can I get these 2 variables as an output from the ga solver? I am sure there is a way to store these values to be read after the optimization is done. I tried to look at the "Custom Output Function for Genetic Algorithm" documentation but I am somehow lost as I am new to MATLAB.
I will just give a simple example of what I am trying to get
%This is my objective function in which I am using ga to minimize the toal cost of electricity
%To calculate the TotalCost there are too many variables and equations, these include ElecUse and ZoneTemp.
TotalCost = ElecUse * ElecRate
ElecUse = LightLoad + HVACLoad + PplLoad ... etc...
HVACLoad = ZoneTemp*...... etc...
I hope this is clear...
Any hints or examples would be appreciated. Thank you!
  4 个评论
Ameer Hamza
Ameer Hamza 2020-5-5
So if you get the value of x at each iteration, you can then use those values to find the values of ZoneTemp and ElecUse at each iteration. Is that correct?
Amde
Amde 2020-5-5
Yes, ZoneTemp depends directly on resistance (x) and then ZoneTemp is used to calculate ElecUse which is eventually used to calculate the final cost. So basically, the ga solver has already done the calculations for all variables to get x, I just need to store the values of ZoneTemp and ElecUse for the best iteration.

请先登录,再进行评论。

采纳的回答

Ameer Hamza
Ameer Hamza 2020-5-5
See my code here: https://www.mathworks.com/matlabcentral/answers/514594-plot-the-function-value-according-to-the-value-of-the-optimized-parameter-by-genetic-algorithm to see how to extract the best values of x for all iterations. The once extracted, you can use those to the values of x to calculate ZoneTemp and ElecUse according to their formula.
  4 个评论
Amde
Amde 2020-5-5
Yes this is exactly What I was doing, I thought there is a way to get the intemediate values from the optimization run. I also came across this Custom Output documentation, not sure if it would be helpful. I guess I will continue doing what I am doing. Thank you agian, Ameer!
Ameer Hamza
Ameer Hamza 2020-5-5
The outputFcn is only used to analyze the states of the optimizer itself. The code in my other answer is also a custom output function. They are still not aware of the internal mechanism of the objective function. They are used to analyze states of the optimizer, e.g., population size, current population members, their fitness values, etc.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Particle Swarm 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by