cd V:\Cursos\Pos\Otimiza\Aulas help milprog %MILPROG Linear programming by exaustive search. % X=MILPROG(f,n,m,A,b) solves the mixed integer linear programming problem: % % min f'*X subject to: A*X <= b % x,y % x real % y integer % X=[x;y] % n=number of real variables % m=number of integer variables % X=MILPPROG(f,n,m,A,b,Aeq,beq) solves the problem above while additionally % satisfying the equality constraints Aeq*[x;y] = beq. % % X=MILPROG(f,n,m,A,b,Aeq,beq,LB,UB) defines a set of lower and upper % bounds on the design variables, real x, so that the solution is in % the range LB <= x <= UB. Use empty matrices for LB and UB % if no bounds exist. Set LB(i) = -Inf if x(i) is unbounded below; % set UB(i) = Inf if x(i) is unbounded above. % % X=MILPROG(f,n,m,A,b,Aeq,beq,LB,UB,x0) sets the starting point of real % variables to x0. This option is only available with the active-set algorithm. The default % interior point algorithm will ignore any non-empty starting point. % % X=MILPROG(f,n,m,A,b,Aeq,Beq,LB,UB,x0,OPTIONS) minimizes with the default % optimization parameters replaced by values in the structure OPTIONS, an % argument created with the OPTIMSET function. See OPTIMSET for details. % Use options are Display, Diagnostics, TolFun, LargeScale, MaxIter. % Currently, only 'final' and 'off' are valid values for the parameter % Display when LargeScale is 'off' ('iter' is valid when LargeScale is 'on'). % % [X,FVAL]=MILPROG(f,n,m,A,b) returns the value of the objective function at X: % FVAL = f'*X. % % [X,FVAL,EXITFLAG] = MILPROG(f,A,b) returns EXITFLAG that % describes the exit condition of LINPROG. % If EXITFLAG is: % > 0 then LINPROG converged with a solution X. % 0 then LINPROG reached the maximum number of iterations without converging. % < 0 then the problem was infeasible or LINPROG failed. % % [X,FVAL,EXITFLAG,OUTPUT] = MILPROG(f,n,m,A,b) returns a structure % OUTPUT with the number of iterations taken in OUTPUT.iterations, the type % of algorithm used in OUTPUT.algorithm, the number of conjugate gradient % iterations (if used) in OUTPUT.cgiterations. % % [X,FVAL,EXITFLAG,OUTPUT,LAMBDA,NLP,POS]=MILPROG(f,n,m,A,b) returns the set of % Lagrangian multipliers LAMBDA, at the solution: LAMBDA.ineqlin for the % linear inequalities A, LAMBDA.eqlin for the linear equalities Aeq, % LAMBDA.lower for LB, and LAMBDA.upper for UB.NLP returns the number of % LINPTOG evaluations.POS returns the position of the the solution, use to % analize the results. % % NOTE: the LargeScale (the default) version of MILPROG uses LINPROG that use a primal-dual % method. Both the primal problem and the dual problem must be feasible % for convergence. Infeasibility messages of either the primal or dual, % or both, are given as appropriate. The primal problem in standard % form is % min f'*x such that A*x = b, x >= 0. % The dual problem is % max b'*y such that A'*y + s = f, s >= 0. % Authors: Argimiro R. Secchi & % Marcelo Escobar % Chemical Engineering Department % Applied Math Department % Universidade Federal do Rio Grande do Sul, Brasil % arge@enq.ufrgs.br | escobar@enq.ufrgs.br % % version 1.0: 15/agosto/2004 If just 'defaults' passed in, return the default options in X op=optimset('LargeScale','off'); [X,FVAL,EXITFLAG,OUTPUT,LAMBDA,NLP,POS]=MILPROG([2;-3;-2;-3],1,3,[-1 -1 -1 -1;10 5 3 4],[-2;10],0,inf,[],op) ??? Error using ==> > Function '>' not defined for variables of class 'struct'. Error in ==> V:\Cursos\Pos\Otimiza\Aulas\checkbounds.m On line 45 ==> if any( lb( (1:len)' ) > ub( (1:len)' ) ) Error in ==> V:\Cursos\Pos\Otimiza\Aulas\milprog.m On line 108 ==> [x0,lb,ub,msg] = checkbounds(x0,lb,ub,n); [X,FVAL,EXITFLAG,OUTPUT,LAMBDA,NLP,POS]=MILPROG([2;-3;-2;-3],1,3,[-1 -1 -1 -1;10 5 3 4],[-2;10],[],[],[0;0;0;0],[inf;1;1;1],[],op) Warning: Length of lower bounds is > length(x); ignoring extra bounds > In V:\Cursos\Pos\Otimiza\Aulas\checkbounds.m at line 26 In V:\Cursos\Pos\Otimiza\Aulas\milprog.m at line 108 Warning: Length of upper bounds is > length(x); ignoring extra bounds > In V:\Cursos\Pos\Otimiza\Aulas\checkbounds.m at line 35 In V:\Cursos\Pos\Otimiza\Aulas\milprog.m at line 108 ??? Error using ==> * Inner matrix dimensions must agree. Error in ==> V:\Cursos\Pos\Otimiza\Aulas\milprog.m On line 171 ==> Bm=B-f(nv-m+1:end)*M(i,:)'; [X,FVAL,EXITFLAG,OUTPUT,LAMBDA,NLP,POS]=MILPROG([2;-3;-2;-3],1,3,[-1 -1 -1 -1;10 5 3 4],[-2;10],[],[],0,inf,[],op) ??? Error using ==> * Inner matrix dimensions must agree. Error in ==> V:\Cursos\Pos\Otimiza\Aulas\milprog.m On line 171 ==> Bm=B-f(nv-m+1:end)*M(i,:)'; [X,FVAL,EXITFLAG,OUTPUT,LAMBDA,NLP,POS]=MILPROG([2 -3 -2 -3],1,3,[-1 -1 -1 -1;10 5 3 4],[-2;10],[],[],[0 0 0 0],[inf 1 1 1],[],op) Warning: Length of lower bounds is > length(x); ignoring extra bounds > In V:\Cursos\Pos\Otimiza\Aulas\checkbounds.m at line 26 In V:\Cursos\Pos\Otimiza\Aulas\milprog.m at line 108 Warning: Length of upper bounds is > length(x); ignoring extra bounds > In V:\Cursos\Pos\Otimiza\Aulas\checkbounds.m at line 35 In V:\Cursos\Pos\Otimiza\Aulas\milprog.m at line 108 Exiting: The constraints are overly stringent; no feasible starting point found. Optimization terminated successfully. Optimization terminated successfully. Optimization terminated successfully. Optimization terminated successfully. Optimization terminated successfully. Optimization terminated successfully. Optimization terminated successfully. Warning: X == [] is technically incorrect. Use isempty(X) instead. > In V:\Cursos\Pos\Otimiza\Aulas\milprog.m at line 187 ??? Index exceeds matrix dimensions. Error in ==> V:\Cursos\Pos\Otimiza\Aulas\milprog.m On line 187 ==> x= Mxy(pos(find(fv==min(fv))),:)'; [X,FVAL,EXITFLAG,OUTPUT,LAMBDA,NLP,POS]=MILPROG([2 -3 -2 -3],1,3,[-1 -1 -1 -1;10 5 3 4],[-2;10],[],[],[0 0 0 0],[inf 1 1 1],[0 0 0 0],op) Warning: Length of lower bounds is > length(x); ignoring extra bounds > In V:\Cursos\Pos\Otimiza\Aulas\checkbounds.m at line 26 In V:\Cursos\Pos\Otimiza\Aulas\milprog.m at line 108 Warning: Length of upper bounds is > length(x); ignoring extra bounds > In V:\Cursos\Pos\Otimiza\Aulas\checkbounds.m at line 35 In V:\Cursos\Pos\Otimiza\Aulas\milprog.m at line 108 ??? Error using ==> * Inner matrix dimensions must agree. Error in ==> C:\Apps\Matlab\toolbox\optim\private\qpsub.m On line 223 ==> cstr = A*X-B; Error in ==> C:\Apps\Matlab\toolbox\optim\linprog.m On line 160 ==> [x,lambdaqp,exitflag,output]= ... Error in ==> V:\Cursos\Pos\Otimiza\Aulas\milprog.m On line 172 ==> [X,FVAL,EXITFLAG,OUTPUT,LAMBDA]=linprog(c,Am,Bm,Aeq,Beq,lb,ub,x0,op); [X,FVAL,EXITFLAG,OUTPUT,LAMBDA,NLP,POS]=MILPROG([2 -3 -2 -3],1,3,[-1 -1 -1 -1;10 5 3 4],[-2;10],[],[],[0 0 0 0],[inf 1 1 1],[0;0;0;0],op) Warning: Length of lower bounds is > length(x); ignoring extra bounds > In V:\Cursos\Pos\Otimiza\Aulas\checkbounds.m at line 26 In V:\Cursos\Pos\Otimiza\Aulas\milprog.m at line 108 Warning: Length of upper bounds is > length(x); ignoring extra bounds > In V:\Cursos\Pos\Otimiza\Aulas\checkbounds.m at line 35 In V:\Cursos\Pos\Otimiza\Aulas\milprog.m at line 108 ??? Error using ==> * Inner matrix dimensions must agree. Error in ==> C:\Apps\Matlab\toolbox\optim\private\qpsub.m On line 223 ==> cstr = A*X-B; Error in ==> C:\Apps\Matlab\toolbox\optim\linprog.m On line 160 ==> [x,lambdaqp,exitflag,output]= ... Error in ==> V:\Cursos\Pos\Otimiza\Aulas\milprog.m On line 172 ==> [X,FVAL,EXITFLAG,OUTPUT,LAMBDA]=linprog(c,Am,Bm,Aeq,Beq,lb,ub,x0,op); [X,FVAL,EXITFLAG,OUTPUT,LAMBDA,NLP,POS]=MILPROG([2 -3 -2 -3],1,3,[-1 -1 -1 -1;10 5 3 4],[-2;10],[],[],[0 0 0 0],[inf 1 1 1],[0;0;0;0]) Warning: Length of lower bounds is > length(x); ignoring extra bounds > In V:\Cursos\Pos\Otimiza\Aulas\checkbounds.m at line 26 In V:\Cursos\Pos\Otimiza\Aulas\milprog.m at line 108 Warning: Length of upper bounds is > length(x); ignoring extra bounds > In V:\Cursos\Pos\Otimiza\Aulas\checkbounds.m at line 35 In V:\Cursos\Pos\Otimiza\Aulas\milprog.m at line 108 Warning: Interior Point method is ignoring starting point > In C:\Apps\Matlab\toolbox\optim\linprog.m at line 148 In V:\Cursos\Pos\Otimiza\Aulas\milprog.m at line 172 Exiting: One or more of the residuals, duality gap, or total relative error has stalled: the primal appears to be infeasible (and the dual unbounded). (The dual residual < TolFun=1.00e-008.) Warning: Interior Point method is ignoring starting point > In C:\Apps\Matlab\toolbox\optim\linprog.m at line 148 In V:\Cursos\Pos\Otimiza\Aulas\milprog.m at line 172 Optimization terminated successfully. Warning: Interior Point method is ignoring starting point > In C:\Apps\Matlab\toolbox\optim\linprog.m at line 148 In V:\Cursos\Pos\Otimiza\Aulas\milprog.m at line 172 Optimization terminated successfully. Warning: Interior Point method is ignoring starting point > In C:\Apps\Matlab\toolbox\optim\linprog.m at line 148 In V:\Cursos\Pos\Otimiza\Aulas\milprog.m at line 172 Optimization terminated successfully. Warning: Interior Point method is ignoring starting point > In C:\Apps\Matlab\toolbox\optim\linprog.m at line 148 In V:\Cursos\Pos\Otimiza\Aulas\milprog.m at line 172 Optimization terminated successfully. Warning: Interior Point method is ignoring starting point > In C:\Apps\Matlab\toolbox\optim\linprog.m at line 148 In V:\Cursos\Pos\Otimiza\Aulas\milprog.m at line 172 Optimization terminated successfully. Warning: Interior Point method is ignoring starting point > In C:\Apps\Matlab\toolbox\optim\linprog.m at line 148 In V:\Cursos\Pos\Otimiza\Aulas\milprog.m at line 172 Optimization terminated successfully. Warning: Interior Point method is ignoring starting point > In C:\Apps\Matlab\toolbox\optim\linprog.m at line 148 In V:\Cursos\Pos\Otimiza\Aulas\milprog.m at line 172 Optimization terminated successfully. ==================================== ==================================== RESULTADOS OBTIDOS: X = 0.0000 1.0000 0 1.0000 FVAL = -6.0000 EXITFLAG = [-1] [1] [1] [1] [1] [1] [1] [1] OUTPUT = Columns 1 through 4 [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] Columns 5 through 8 [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] LAMBDA = Columns 1 through 4 [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] Columns 5 through 8 [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] NLP = 7 POS = 6 [X,FVAL,EXITFLAG,OUTPUT,LAMBDA,NLP,POS]=MILPROG([2 -3 -2 -3],1,3,[-1 -1 -1 -1;10 5 3 4],[-2;10],[],[],[0 0 0 0],[inf 1 1 1]) Warning: Length of lower bounds is > length(x); ignoring extra bounds > In V:\Cursos\Pos\Otimiza\Aulas\checkbounds.m at line 26 In V:\Cursos\Pos\Otimiza\Aulas\milprog.m at line 108 Warning: Length of upper bounds is > length(x); ignoring extra bounds > In V:\Cursos\Pos\Otimiza\Aulas\checkbounds.m at line 35 In V:\Cursos\Pos\Otimiza\Aulas\milprog.m at line 108 Exiting: One or more of the residuals, duality gap, or total relative error has stalled: the primal appears to be infeasible (and the dual unbounded). (The dual residual < TolFun=1.00e-008.) Optimization terminated successfully. Optimization terminated successfully. Optimization terminated successfully. Optimization terminated successfully. Optimization terminated successfully. Optimization terminated successfully. Optimization terminated successfully. ==================================== ==================================== RESULTADOS OBTIDOS: X = 0.0000 1.0000 0 1.0000 FVAL = -6.0000 EXITFLAG = [-1] [1] [1] [1] [1] [1] [1] [1] OUTPUT = Columns 1 through 4 [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] Columns 5 through 8 [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] LAMBDA = Columns 1 through 4 [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] Columns 5 through 8 [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] NLP = 7 POS = 6 [X,FVAL,EXITFLAG,OUTPUT,LAMBDA,NLP,POS]=MILPROG([2 -3 -2 -3],1,3,[-1 -1 -1 -1;10 5 3 4],[-2;10],[],[],[0 0 0 0],[inf 1 1 1]) Warning: Length of lower bounds is > length(x); ignoring extra bounds > In V:\Cursos\Pos\Otimiza\Aulas\checkbounds.m at line 26 In V:\Cursos\Pos\Otimiza\Aulas\milprog.m at line 108 Warning: Length of upper bounds is > length(x); ignoring extra bounds > In V:\Cursos\Pos\Otimiza\Aulas\checkbounds.m at line 35 In V:\Cursos\Pos\Otimiza\Aulas\milprog.m at line 108 Exiting: One or more of the residuals, duality gap, or total relative error has stalled: the primal appears to be infeasible (and the dual unbounded). (The dual residual < TolFun=1.00e-008.) Optimization terminated successfully. Optimization terminated successfully. Optimization terminated successfully. Optimization terminated successfully. Optimization terminated successfully. Optimization terminated successfully. Optimization terminated successfully. ==================================== ==================================== RESULTADOS OBTIDOS: X = 0.0000 1.0000 0 1.0000 FVAL = -6.0000 EXITFLAG = [-1] [1] [1] [1] [1] [1] [1] [1] OUTPUT = Columns 1 through 4 [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] Columns 5 through 8 [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] LAMBDA = Columns 1 through 4 [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] Columns 5 through 8 [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] NLP = 7 POS = 6 OUTPUT{6} ans = iterations: 5 cgiterations: 0 algorithm: 'lipsol' X{6} ??? Cell contents reference from a non-cell array object. X X = 0.0000 1.0000 0 1.0000 LAMBDA{6} ans = ineqlin: [2x1 double] eqlin: [0x1 double] upper: 0 lower: 2.0000 help milp MILP Mixed-integer linear programming. Branch Bound Algorithm. [y,x,FVAL,nevals,XFlg] = milp(c,A,b,vlb,vub,N,R,opt) % % min c'*X subject to: A*X <= | = b % x real % y integer % X=[y;x] % Last R variables not integer. % VLB & VUB defines a set of lower and upper % bounds on the design variables, X, so that the solution is in % the range VLB <= X <= VUB. Use empty matrices for VLB and VUB % if no bounds exist. Set LB(i) = -Inf if X(i) is unbounded below; % set VUB(i) = Inf if X(i) is unbounded above. N = First N constraints equality constraints (=0, default) R = Last R variables not integer constrained (=0, default) varargin define a options vector. Options: opt = options structure, with fields: .Display =-1, no warning messages = 0, initial LP message (default) = 1, show steps of B&B evalutation = 2, also show TolFun changes .Martin = 0, don't use Martin cuts = 1, use Martin cuts if possible (default) .SOS = Special Ordered Sets of type one (SOS1) = 0, don't use (default) = 1, use if possible (and don't use Martin cuts) .RCthresh = reduced cost threshold percent of obj for Martin cuts = 0.05 (default) .TolInt = integer tolerance for ISINT = [1e-8], default .ExTolFun = opt.LPopt.TolFun expansion factor for LINPROG feasible = 10 (default) .LPopt = option structure for LINPROG, with MCNF default: .Display = 'none' = 'Field1',value1,'Field2',value2, ..., where multiple input arguments or single cell array can be used instead of the full options structure to change only selected fields opt = MILP('defaults'), to get defaults values for option structure OUTPUTS: y returns the value of the integers variables x returns the value of the real variables FVAL returns the value of the objective function nevals = number of LP evaluations XFlg = 2, initial LP solution feasible = 1, solution found =-1, no feasible integer solution found =-2, initial LINPROG exitflag <= 0 op=milp('Defaults') op = Display: 0 Martin: 1 SOS: 0 RCthresh: 0.0500 TolInt: 1.4901e-010 ExTolFun: 10 LPopt: [1x1 struct] op.Display=1 op = Display: 1 Martin: 1 SOS: 0 RCthresh: 0.0500 TolInt: 1.4901e-010 ExTolFun: 10 LPopt: [1x1 struct] [y,x,FVAL,nevals,XFlg] = milp([-3 -2 -3 2],[-1 -1 -1 -1;5 3 4 10],[-2;10],0,inf,0,1,op) ??? Error using ==> milp Variable bounds not the same dimension as c. [y,x,FVAL,nevals,XFlg] = milp([-3 -2 -3 2]',[-1 -1 -1 -1;5 3 4 10],[-2;10],0,inf,0,1,op) ??? Error using ==> milp Variable bounds not the same dimension as c. [y,x,FVAL,nevals,XFlg] = milp([-3 -2 -3 2]',[-1 -1 -1 -1;5 3 4 10],[-2;10],[0 0 0 0],[inf 1 1 1],0,1,op) NODE PRNT OBJ BND VAR 0 -6.8000 1 0 -5.0000 0 UB of 1 Incumbent 2 0 -6.6667 1 LB of 1 3 2 -6.6000 0 UB of 2 4 2 -6.5000 1 LB of 2 5 3 -6.0000 1 UB of 1 Incumbent 6 3 -6.0000 2 LB of 1 Fathomed: value dominance 7 4 -6.2000 0 UB of 3 8 4 -8.0000 1 LB of 3 Fathomed: infeasible 9 7 -5.0000 1 UB of 1 Fathomed: value dominance 10 7 -8.0000 2 LB of 1 Fathomed: infeasible Optimization terminated successfully. y = 1 0 1 x = 0 FVAL = -6 nevals = 11 XFlg = 1 [y,x,FVAL,nevals,XFlg] = milp([-3 -2 -3 2]',[-1 -1 -1 -1;5 3 4 10],[-2;10],[0 0 0 0],[1 1 1 inf],0,1,op) NODE PRNT OBJ BND VAR 0 -6.8000 1 0 -5.0000 0 UB of 1 Incumbent 2 0 -6.6667 1 LB of 1 3 2 -6.0000 0 UB of 2 Incumbent 4 2 -6.5000 1 LB of 2 5 4 -5.0000 0 UB of 3 Fathomed: value dominance 6 4 -8.0000 1 LB of 3 Fathomed: infeasible Optimization terminated successfully. y = 1 0 1 x = 0 FVAL = -6 nevals = 7 XFlg = 1 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) type milp1 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 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'; type milp1 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) [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 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 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 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 gminlp1 function [gf_nlp,gg_nlp,C,B] = grad (x,y) if size(x,2) > 3 y = x(4:6); % NLP com integralidade relaxada end % * * * exemplo 1 - Kocis e Grossmann(1987) * * * gf_nlp(1) =-8.9/(1+x(1))+1.8; gf_nlp(2) =-10.44/(1+x(2))+1.8; gf_nlp(3) =-2.9; gg_nlp(1,1) =0.9/(1+x(1)); gg_nlp(1,2) =1.08/(1+x(2)); gg_nlp(1,3) =0.9; gg_nlp(2,1) =1/(1+x(1)); gg_nlp(2,2) =0; gg_nlp(2,3) =0; gg_nlp(3,1) =0; gg_nlp(3,2) =1.2/(1+x(2)); gg_nlp(3,3) =0; gg_nlp(4,1) =0; gg_nlp(4,2) =0; gg_nlp(4,3) =0; if nargout > 2 | size(x,2) > 3 C = [3.5, 1, 1.5]; B = [-1, 0, 0; 0, -10, 0; 0, 0, -10; 0, 1, 1]; end if size(x,2) > 3 % 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('minlp1','gminlp1',3,3,1,0,[0 0 0],[0 0 0],[0 0 0]) f-COUNT FUNCTION MAX{g} STEP Procedures 1 0 0 1 2 -2.43454 -0.0715388 1 3 -3.70504 -0.00376023 1 4 -3.76538 -6.12932e-005 1 5 -3.76688 -1.25446e-007 1 Hessian modified 6 -3.76688 -1.007e-010 1 Hessian modified Optimization Converged Successfully Active Constraints: 1 2 3 f-COUNT FUNCTION MAX{g} STEP Procedures 1 -3.91104 0.65524 1 infeasible 2 4.74262 -0.0340467 1 infeasible 3 3.54757 -0.00303953 1 infeasible 4 3.49975 -2.30502e-006 1 Hessian modified; overly constrained 5 3.49971 -1.32838e-012 1 Hessian modified; overly constrained Optimization Converged Successfully Active Constraints: 3 f-COUNT FUNCTION MAX{g} STEP Procedures 1 -0.176071 0 1 2 -1.73758 0 1 3 -1.92031 0 1 4 -1.9231 0 1 Hessian modified 5 -1.9231 0 1 Hessian modified Optimization Converged Successfully Active Constraints: 1 2 f-COUNT FUNCTION MAX{g} STEP Procedures 1 -0.150208 0 1 2 -1.52948 0 1 3 -1.71621 0 1 4 -1.72097 0 1 Hessian modified 5 -1.72097 0 1 Hessian modified Optimization Converged Successfully Active Constraints: 1 3 wo = Columns 1 through 7 0 1.5242 0 1.0000 0 1.0000 0 Column 8 -1.9231 St = 5 2 6 3 7 2 x0 = 1.0e-003 * -0.0000 -0.0000 0.1000 y0 = 1 0 0 [wo,St,x0,y0] = minlp('minlp1','gminlp1',3,3,1,0,[0 0 0],[0 0 0],[0 0 0]) f-COUNT FUNCTION MAX{g} STEP Procedures 1 0 0 1 2 -2.43454 -0.0715388 1 3 -3.70504 -0.00376023 1 4 -3.76538 -6.12932e-005 1 5 -3.76688 -1.25446e-007 1 Hessian modified 6 -3.76688 -1.007e-010 1 Hessian modified Optimization Converged Successfully Active Constraints: 1 2 3 f-COUNT FUNCTION MAX{g} STEP Procedures 1 -3.91104 0.65524 1 infeasible 2 4.74262 -0.0340467 1 infeasible 3 3.54757 -0.00303953 1 infeasible 4 3.49975 -2.30502e-006 1 Hessian modified; overly constrained 5 3.49971 -1.32838e-012 1 Hessian modified; overly constrained Optimization Converged Successfully Active Constraints: 3 f-COUNT FUNCTION MAX{g} STEP Procedures 1 -0.176071 0 1 2 -1.73758 0 1 3 -1.92031 0 1 4 -1.9231 0 1 Hessian modified 5 -1.9231 0 1 Hessian modified Optimization Converged Successfully Active Constraints: 1 2 f-COUNT FUNCTION MAX{g} STEP Procedures 1 -0.150208 0 1 2 -1.52948 0 1 3 -1.71621 0 1 4 -1.72097 0 1 Hessian modified 5 -1.72097 0 1 Hessian modified Optimization Converged Successfully Active Constraints: 1 3 wo = Columns 1 through 7 0 1.5242 0 1.0000 0 1.0000 0 Column 8 -1.9231 St = 5 2 6 3 7 2 x0 = 1.0e-003 * -0.0000 -0.0000 0.1000 y0 = 1 0 0 quit