Hello, I'd like to ask you something concerning optimization communicating with aspen HYSYS
8 views (last 30 days)
Show older comments
Hello, I'm struggling with MATLAB for learning optimization
But it's quite hard to do and need some help with my code.
I've made the code like the follow but MATLAB specified 'Unrecognized function or variable 'x''
So I was trying to use 'global x' before or blank variable.
And as you're expecting, it surely didn't work
Is there anyone who could give me advise for me please?
Thank you for reading my asking
function y = Objective
MyObject=actxserver('Hysys.Application');
% global simcase;
FileNamePath='Test_Compressor stage_simplified';
MySimCase=MyObject.SimulationCases.Open('C:\Users\PSE_7\Desktop\LNG liquefaction sytem\N2 expander cycle\Multi-objective optimization\Aspen HYSYS\Test_Compressor stage_simplified.hsc');
MySimCase.Visible=true; % The case is opened in Aspen HYSYS
MyOperations=MySimCase.Flowsheet.Operations; % Getting data from our simcase operations
MyFlowSheet=MySimCase.get('flowsheet'); %accessing to flowsheet
MyMaterialStreams=MyFlowSheet.get('MaterialStreams'); %accessing to simulated material streams
MyEnergyStreams=MyFlowSheet.get('EnergyStreams'); % Energy streams
MyK1=get(MyOperations,'Item','K-1');
MyK2=get(MyOperations,'Item','K-2');
MyE1=get(MyOperations,'Item','E-1');
MyStreams=MySimCase.Flowsheet.Streams;
MyM0=get(MyStreams,'Item','M0');
MyM1=get(MyStreams,'Item','M1');
MyM2=get(MyStreams,'Item','M2');
MyM3=get(MyStreams,'Item','M3');
MyW_1=get(MyStreams,'Item','W-1');
MyW_2=get(MyStreams,'Item','W-2');
MyQ_1=get(MyStreams,'Item','Q-1');
MyK1_Energy = MyK1.EnergyValue
MyK2_Energy = MyK2.EnergyValue
lb = [107];
ub = [1000];
A = [];
b = [];
Aeq = [];
beq = [];
x0 = [150];
nonlincon = @GA_Con_Comps;
% opts = optimoptions('ga','Display','iter','Algorithm','interior-point');
MyM1.PressureValue = x;
if MyM2.TemperatureValue < 30
MyM3.TemperatureValue = MyM2.TemperatureValue;
else
MyM3.TemperatureValue = 30;
end
Objective = MyK1_Energy + MyK2_Energy
x = ga(Objective,1,A,b,Aeq,beq,lb,ub,nonlincon,opts);
disp(x)
disp(['Final objective:' num2str(Objective(x))])
end
0 Comments
Accepted Answer
Mario Malic
on 26 Jul 2020
Edited: Mario Malic
on 26 Jul 2020
I did something similar, you should put all this code related to Hysys into your function 'Objective', and then call it as an anonymous function.
[x, fval] = ga(@(x)Objective(x),1,A,b,Aeq,beq,lb,ub,nonlincon,opts);
You don't have to have declared x variable for ga.
function fobj = Objective(x)
% Hysis code here
% Send x into simulation
% Get value that you want to optimize into fobj
fobj = MyK1_Energy + MyK2_Energy;
end
13 Comments
Md Nur Islam Sarker Nayan
on 27 May 2021
@Jiwon Choi Thank you for your reply. I will try to solve the problem.
More Answers (0)
See Also
Categories
Find more on Get Started with Optimization Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!