type milp1.m function [f_nlp,g_nlp] = nlp(x,y) if size(x,2) > 1 y = x(2:4); % NLP com integralidade relaxada end % * * * exemplo 1 (MILP) solved as MINLP - Floudas (1995) * * * f_nlp = 2*x(1)-3*y(1)-2*y(2)-3*y(3); g_nlp(1) = 2-x(1)-y(1)-y(2)-y(3); g_nlp(2) = 10*x(1)+5*y(1)+3*y(2)+4*y(3)-10; % [wo,St,x0,y0] = minlp('milp1','gmilp1',1,3,1,0,0,[0 0 0],0) type gmilp1.m function [gf_nlp,gg_nlp,C,B] = grad (x,y) if size(x,2) > 1 y = x(2:4); % NLP com integralidade relaxada end % * * * exemplo 1 (MILP) solved as MINLP - Floudas (1995) * * * gf_nlp(1)=2; gg_nlp(1,1)=-1; gg_nlp(2,1)=10; if nargout > 2 | size(x,2) > 1 C = [-3, -2, -3]; B = [-1, -1, -1; 5, 3, 4]; end if size(x,2) > 1 % NLP com integralidade relaxada gf_nlp = [gf_nlp C]; gg_nlp = [gg_nlp B]; end gg_nlp=gg_nlp'; help minlp * * * Solution of MINLP * * * Z = min(y,x) F(x,y) = C'y + f(x) s.t. G(x,y) = By + g(x) <= 0 x in X in R^n y in Y = {0,1}^m usage: [wo,St,x0,y0] = minlp(NLP,GRAD,n,m,rx,fig,x0,y0,xlb,xub,M,epsR,epsI,epsC,epsZ) wo : best solution found [x,y,u,Z] where u is the maximum constraint violation St : matrix = (number of constraints, number of LPs) for each NLP NLP : M file describing the NLP: [F,G] = nlp(x,y) with the first line: if size(x,2) > n, y = x(n+1:n+m); end GRAD : M file for gradients: [Fx,Gx,C,B] = grad(x,y) with the first line: if size(x,2) > n, y = x(n+1:n+m); end and last lines: if size(x,2) > n, Fx = [Fx C]; Gx = [Gx B]; end Gx = Gx'; rx : = 1 : relaxed initial NLP. = 0 : unrelaxed initial NLP (default) fig : = 1 : plot constraints surfaces. = 0 : no plots (default). x0 : initial guess for x (default = zeros(1,n)). Returns first solution. y0 : initial guess for y (default = round(rand(1,m))) xlb : lower bound for x (default = zeros(1,n)) xub : upper bound for x (default = inf * ones(1,n)) M > 0 : constraint violation penalization (default = 1e3) epsR : real variable tolerance (default = 1e-4) epsI : integer variable tolerance (default = 1e-4) epsC : constraint violation tolerance (default = 1e-6) epsZ : objective function tolerance (default = 1e-4) [wo,St,x0,y0] = minlp('milp1','gmilp1',1,3,1,0,0,[0 0 0],0) f-COUNT FUNCTION MAX{g} STEP Procedures 1 0 2 1 2 -6.73529 -3.55271e-015 1 Hessian modified twice 3 -6.76512 0 1 Hessian modified twice 4 -6.8 0 1 Hessian modified twice 5 -6.8 0 1 Hessian modified twice Optimization Converged Successfully Active Constraints: 2 f-COUNT FUNCTION MAX{g} STEP Procedures 1 -8 2 1 infeasible 2 -8.2 1 1 Hessian modified twice; infeasible 3 -8.2 1 1 Hessian modified twice; infeasible Warning: No feasible solution found. f-COUNT FUNCTION MAX{g} STEP Procedures 1 -5 0 1 2 -5 0 1 Optimization Converged Successfully Active Constraints: 1 f-COUNT FUNCTION MAX{g} STEP Procedures 1 -6 0 1 2 -6 0 1 Optimization Converged Successfully Active Constraints: 1 wo = 0.0000 1.0000 0 1.0000 0 -6.0000 St = 3 2 4 3 5 4 x0 = -0.1000 y0 = 1 1 1 what M-files in the current directory v:\cursos\pos\otimiza\aulas CATALIS ex_qp1 gtest9 pareto19 test13 EXTRATOR ex_qp2 hkjeeves pareto20 test14 LUCRO ex_qp3 htest1 pareto21 test15 MINQUA ex_swarm htest2 powell test16 MODELO fmincon1 interior qpsub test17 OPT_RES fminunc1 karmarkar refino test18 PLANOS fminusub lmarqua restr test19 READ2 fun lp_nlp restr1 test2 SEMIDEF gmilp1 milp1 restr14 test20 SMODELO gminlp1 minlp restr15 test21 aurea gminlp2 minlp1 restr16 test3 bandem1 gminlp3 minlp2 restr17 test4 bfgs gminlp4 minlp3 restr20 test5 bracket gminlp5 minlp4 restr21 test6 buscarnd gminlp6 minlp5 rosembr test7 cgrad gmodelagem minlp6 set1 test8 checkbounds gmurray minlpn setoptim test9 coggins grad modelagem sqp univar compdir grg newton steepdes varmetr complex gtest1 newton_h swarm writearq dfp gtest10 newtont test1 xplot dual gtest12 nlconst test10 ex2_karm gtest13 nlp_internal test11 ex_karma gtest2 pareto18 test12 type minlp1 function [f_nlp,g_nlp] = nlp(x,y) if size(x,2) > 3 y = x(4:6); % NLP com integralidade relaxada end % * * * exemplo 1 - Kocis e Grossmann(1987) * * * f_nlp = -2.9*x(3)-8.9*log(1+x(1))-10.44*log(1+x(2))+1.8*x(1)+1.8*x(2)+3.5*y(1)+y(2)+1.5*y(3); g_nlp(1) = -y(1)+0.9*log(1+x(1))+1.08*log(1+x(2))+0.9*x(3); g_nlp(2) = -10*y(2)+log(1+x(1)); g_nlp(3) = -10*y(3)+1.2*log(1+x(2)); g_nlp(4) = y(2) + y(3) -1; type minlp2 function [f_nlp,g_nlp] = nlp(x,y) if size(x,2) > 1 y = x(2:4); % NLP com integralidade relaxada end % * * * exemplo 6 - Floudas pag.133 * * * f_nlp = y(1) + y(2) + y(3) + 5*(x(1)^2); g_nlp(1) = 3*x(1) - y(1) - y(2); g_nlp(2) = - x(1) + 0.1*y(2) + 0.25*y(3); g_nlp(3) = - y(1) - y(2) - y(3) + 2; g_nlp(4) = - y(1) - y(2) - 2*y(3) + 2; type minlp3 function [f_nlp,g_nlp] = nlp(x,y) if size(x,2) > 1 y = x(2); % NLP com integralidade relaxada end % * * * exemplo 8 - Floudas pag.157 * * * f_nlp = - y(1) + 4*exp(-x(1)) + x(1); g_nlp(1) = -2*exp(-x(1)) + x(1) + y(1); type minlp4 function [f_nlp,g_nlp] = nlp(x,y) if size(x,2) > 3 y = x(4:6); % NLP com integralidade relaxada end % * * * exemplo 1 - Kocis e Grossmann(1987) * * * f_nlp = -2.9*x(3)-8.9*log(1+x(1))-10.44*log(1+x(2))+1.8*x(1)+1.8*x(2)+3.5*y(1)+y(2)+1.5*y(3); g_nlp(1) = -y(1)+0.9*log(1+x(1))+1.08*log(1+x(2))+0.9*x(3); g_nlp(2) = -10*y(2)+log(1+x(1)); g_nlp(3) = -10*y(3)+1.2*log(1+x(2)); g_nlp(4) = y(2) + y(3) -1; type minlp5 function [f_nlp,g_nlp] = nlp(x,y) if size(x,2) > 1 y = x(2:2); % NLP com integralidade relaxada end % * * * exemplo 7 - Floudas pag.141 * * * f_nlp = 2*x(1) + y(1); g_nlp(1) = 1.25 - (x(1)^2) - y(1); g_nlp(2) = x(1) + y(1) - 1.6; type minlp6 function [f_nlp,g_nlp] = nlp(x,y) if size(x,2) > 1 y = x(2); % NLP com integralidade relaxada end % * * * exemplo 2 - Smith(tese) - pag.263 * * * % 0 <= x <= 1 f_nlp = -0.7*y + 5*((x(1)-0.5)^2) + 0.8; g_nlp(1) = -exp(x(1)-0.2)+1.1*y + 1; g_nlp(2) = x(1) - 1.2*y -0.2; type minlp7 ??? Error using ==> type minlp7.m: File not found. type minlp1 function [f_nlp,g_nlp] = nlp(x,y) if size(x,2) > 3 y = x(4:6); % NLP com integralidade relaxada end % * * * exemplo 1 - Kocis e Grossmann(1987) * * * f_nlp = -2.9*x(3)-8.9*log(1+x(1))-10.44*log(1+x(2))+1.8*x(1)+1.8*x(2)+3.5*y(1)+y(2)+1.5*y(3); g_nlp(1) = -y(1)+0.9*log(1+x(1))+1.08*log(1+x(2))+0.9*x(3); g_nlp(2) = -10*y(2)+log(1+x(1)); g_nlp(3) = -10*y(3)+1.2*log(1+x(2)); g_nlp(4) = y(2) + y(3) -1; quit