function [C Ceq] = MCHE_constraints_temp(x,d,parameters)

%Activate Unisim case C3MR_MCHE.usc

%This file assumes that recycles are inactive, and thus inlcudes the error
%across the recycles as equality constraints.

global h

hyCase = h.Activedocument;
sol=hyCase.Solver;
f = hyCase.Flowsheet;

sol.CanSolve = 0 ;

x = parameters.scale_x*x ;

%Reset optimization variables

f.MaterialStreams.Item('MR10').PressureValue = x(1) ;
f.MaterialStreams.Item('MR17').PressureValue = x(2) ; 
f.MaterialStreams.Item('MR10').MolarFlowValue = x(3) ;
f.MaterialStreams.Item('NG5').TemperatureValue = x(4) ;
f.MaterialStreams.Item('MR12').TemperatureValue = x(5) ;
f.MaterialStreams.Item('MR15').TemperatureValue = x(6) ;
f.MaterialStreams.Item('Subcooled NG').TemperatureValue = x(7) ;
f.MaterialStreams.Item('MR16').TemperatureValue = x(8) ;
f.MaterialStreams.Item('C2').MolarFlowValue = x(9) ;
f.MaterialStreams.Item('C3').MolarFlowValue = x(10) ;
f.MaterialStreams.Item('N2').MolarFlowValue = x(11) ;

%Reset disturbances
f.MaterialStreams.Item('NG4').TemperatureValue = d(1) ; % degrees C
f.MaterialStreams.Item('NG4').PressureValue = d(2) ; % kilopascal
f.MaterialStreams.Item('NG4').MolarFlowValue = d(3); %mol/s
f.MaterialStreams.Item('MR10').TemperatureValue = d(1);

sol.CanSolve = 1 ;

UA = parameters.ua;

if f.Operations.Item('MCHE, cold part').Duty.IsKnown == 1
    C=zeros(2,1) ;
    C(1) = (f.MaterialStreams.Item('Subcooled NG').TemperatureValue +157.1099)/10  ; % Maximum temperature of subcooled natural gas
    C(2) = (-1*f.Operations.Item('SPRDSHT-1').Cell('C1').CellValue) ; % Superheating of mixed refrigerant
    Ceq = [f.Operations.Item('MCHE, warm part').Specifications.Item('UA1').CurrentValue-UA(1);
	f.Operations.Item('MCHE, warm part').Specifications.Item('UA2').CurrentValue-UA(2);
	f.Operations.Item('MCHE, warm part').Specifications.Item('UA3').CurrentValue-UA(3) ;
	f.Operations.Item('MCHE, cold part').Specifications.Item('UA1').CurrentValue-UA(4) ;
	f.Operations.Item('MCHE, cold part').Specifications.Item('UA2').CurrentValue-UA(5)];
elseif f.Operations.Item('MCHE, cold part').Duty.IsKnown == 0
    C = ones(2,1) ;
    Ceq = ones(5,1) ;
end
end