Hello, I'd like to ask you something concerning optimization communicating with aspen HYSYS

8 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Mario Malic
Mario Malic el 26 de Jul. de 2020
Editada: Mario Malic el 26 de Jul. de 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 comentarios

Iniciar sesión para comentar.

Más respuestas (1)

Pedro Siscato
Pedro Siscato el 13 de Jun. de 2024
I'm trying optimizing the reflux ratio of a column. But I don't know how change the value in Hysis through MATLab. Someone can help me?

Categorías

Más información sobre Problem-Based Optimization Setup en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by