Home > src > lp_solve.m

lp_solve

PURPOSE ^

LP_SOLVE Solves mixed integer linear programming problems.

SYNOPSIS ^

function [obj, x, duals, stat] = lp_solve(f, a, b, e, vlb, vub, xint, scalemode, keep)

DESCRIPTION ^

LP_SOLVE  Solves mixed integer linear programming problems.

  SYNOPSIS: [obj,x,duals,stat] = lp_solve(f,a,b,e,vlb,vub,xint,scalemode,keep)

     solves the MILP problem

             max v = f'*x
               a*x <> b
                 vlb <= x <= vub
                 x(int) are integer

  ARGUMENTS: The first four arguments are required:

           f: n vector of coefficients for a linear objective function.
           a: m by n matrix representing linear constraints.
           b: m vector of right sides for the inequality constraints.
           e: m vector that determines the sense of the inequalities:
                     e(i) = -1  ==> Less Than
                     e(i) =  0  ==> Equals
                     e(i) =  1  ==> Greater Than
         vlb: n vector of lower bounds. If empty or omitted,
              then the lower bounds are set to zero.
         vub: n vector of upper bounds. May be omitted or empty.
        xint: vector of integer variables. May be omitted or empty.
   scalemode: scale flag. Off when 0 or omitted.
        keep: Flag for keeping the lp problem after it's been solved.
              If omitted, the lp will be deleted when solved.

  OUTPUT: A nonempty output is returned if a solution is found:

         obj: Optimal value of the objective function.
           x: Optimal value of the decision variables.
       duals: solution of the dual problem.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %LP_SOLVE  Solves mixed integer linear programming problems.
0002 %
0003 %  SYNOPSIS: [obj,x,duals,stat] = lp_solve(f,a,b,e,vlb,vub,xint,scalemode,keep)
0004 %
0005 %     solves the MILP problem
0006 %
0007 %             max v = f'*x
0008 %               a*x <> b
0009 %                 vlb <= x <= vub
0010 %                 x(int) are integer
0011 %
0012 %  ARGUMENTS: The first four arguments are required:
0013 %
0014 %           f: n vector of coefficients for a linear objective function.
0015 %           a: m by n matrix representing linear constraints.
0016 %           b: m vector of right sides for the inequality constraints.
0017 %           e: m vector that determines the sense of the inequalities:
0018 %                     e(i) = -1  ==> Less Than
0019 %                     e(i) =  0  ==> Equals
0020 %                     e(i) =  1  ==> Greater Than
0021 %         vlb: n vector of lower bounds. If empty or omitted,
0022 %              then the lower bounds are set to zero.
0023 %         vub: n vector of upper bounds. May be omitted or empty.
0024 %        xint: vector of integer variables. May be omitted or empty.
0025 %   scalemode: scale flag. Off when 0 or omitted.
0026 %        keep: Flag for keeping the lp problem after it's been solved.
0027 %              If omitted, the lp will be deleted when solved.
0028 %
0029 %  OUTPUT: A nonempty output is returned if a solution is found:
0030 %
0031 %         obj: Optimal value of the objective function.
0032 %           x: Optimal value of the decision variables.
0033 %       duals: solution of the dual problem.
0034 
0035 function [obj, x, duals, stat] = lp_solve(f, a, b, e, vlb, vub, xint, scalemode, keep)
0036 
0037 if nargin == 0
0038         help lp_solve;
0039         return;
0040 end
0041 
0042 [m,n] = size(a);
0043 lp = mxlpsolve('make_lp', m, n);
0044 mxlpsolve('set_verbose', lp, 3);
0045 mxlpsolve('set_mat', lp, a);
0046 mxlpsolve('set_rh_vec', lp, b);
0047 mxlpsolve('set_obj_fn', lp, f);
0048 mxlpsolve('set_maxim', lp); % default is solving minimum lp.
0049 
0050 for i = 1:length(e)
0051   if e(i) < 0
0052         con_type = 1;
0053   elseif e(i) == 0
0054         con_type = 3;
0055   else
0056         con_type = 2;
0057   end
0058   mxlpsolve('set_constr_type', lp, i, con_type);
0059 end
0060 
0061 if nargin > 4
0062   for i = 1:length(vlb)
0063     mxlpsolve('set_lowbo', lp, i, vlb(i));
0064   end
0065 end
0066 
0067 if nargin > 5
0068   for i = 1:length(vub)
0069     mxlpsolve('set_upbo', lp, i, vub(i));
0070   end
0071 end
0072 
0073 if nargin > 6
0074   for i = 1:length(xint)
0075     mxlpsolve('set_int', lp, xint(i), 1);
0076   end
0077 end
0078 
0079 if nargin > 7
0080   if scalemode ~= 0
0081     mxlpsolve('set_scaling', lp, scalemode);
0082   end
0083 end
0084 
0085 result=mxlpsolve('solve', lp);
0086 if result == 0 | result == 1 | result == 11 | result == 12
0087 %  [obj, x, duals, stat] = mxlpsolve('get_solution', lp), result;
0088   [obj, x, duals] = mxlpsolve('get_solution', lp);
0089   stat = result;
0090 else
0091   obj = [];
0092   x = [];
0093   duals = [];
0094   stat = result;
0095 end
0096 
0097 if nargin < 9
0098   mxlpsolve('delete_lp', lp);
0099 end

Generated on Tue 31-May-2016 19:24:56 by m2html © 2005