function Result = optimal_design(x0, sc, DTmin, Qvap, nair, u, d)
disp('Find optimal design')
Tgco_air = u(1);
Tvap_air = u(2);
aux.sc = sc;
aux.d = d;
aux.u = u;
res = Heatpump(x0, aux);
%f = 'ObjectiveFunction';
f = 'shaft_work';
g = [];
H = [];
HessPattern = [];
xcom_L = [0; -inf; 0; 0]./sc.com.x;
xcom_U = [inf; inf; inf; inf]./sc.com.x;
xgco_L = [zeros(d.ngco,1)+0.001; zeros(d.ngco,1); -inf*ones(d.ngco,1); zeros(d.ngco, 1); 0; 0; 0.001]./sc.gco.x;
xgco_U = [inf*ones(d.ngco,1); inf*ones(d.ngco,1); inf*ones(d.ngco,1); inf*ones(d.ngco, 1); inf; inf; inf]./sc.gco.x;
xval_L = [0; 0; -inf]./sc.val.x;
xval_U = [1; inf; inf]./sc.val.x;
xvap_L = [0; 0.0001; 0.0001; 0.0001; 0; 0.001; 0]./sc.vap.x;
xvap_U = [inf; inf; inf; d.Vvap-0.0001; inf; inf; inf]./sc.vap.x;
xihx_L = [zeros(d.nihx, 1); zeros(d.nihx, 1); zeros(d.nihx, 1); zeros(d.nihx, 1); zeros(d.nihx, 1); 0]./sc.ihx.x;
xihx_U = [inf*ones(d.nihx, 1); inf*ones(d.nihx, 1); inf*ones(d.nihx, 1); inf*ones(d.nihx, 1); inf*ones(d.nihx, 1); inf]./sc.ihx.x;
x_L = [xcom_L; xgco_L; xval_L; xvap_L; xihx_L];
x_U = [xcom_U; xgco_U; xval_U; xvap_U; xihx_U];
Name = 'CO2 optimal design';
pSepFunc = [];
fLowBnd = [];
b_L = [Tvap_air-inf; 
       DTmin*ones(d.ngco, 1);
       DTmin*ones(d.nihx, 1); 
       Qvap;
       nair;
       ];
b_U = [Tvap_air-DTmin;
       inf*ones(d.ngco, 1);
       inf*ones(d.nihx, 1);
       Qvap;
       nair;
       ];
A = xlsread('A.xls','Design');
SCALER = [];
for i=1:size(A,1)
    SCALER = [SCALER; sc.x'];
end
A=A.*SCALER;
c = 'Heatpump';
dc = [];
d2c = [];
ConsPattern = [];
c_L = zeros(size(res));
c_U = zeros(size(res));
x_min = []		;
x_max = []		;
f_opt = []		;
x_opt = []		;


A*x0-b_L	;
A*x0-b_U	;
x0-x_L  	;
x0-x_U  	;

Prob = ProbDef;
Prob = conAssign(f, g, H, HessPattern, x_L, x_U, Name, x0, pSepFunc, fLowBnd, A, b_L, b_U, c, dc, d2c, ConsPattern, c_L, c_U, x_min, x_max, f_opt, x_opt);
Prob.d=d;
Prob.sc=sc;
Prob.u = u;

Result = tomRun('minos', Prob);
disp(Result.ExitText)
x = Result.x_k;
A*x-b_L;
A*x-b_U;
xopt = x.*sc.x;
