convertCobraLP2mps

PURPOSE ^

create an MPS (Mathematical Programming System) format ascii file

SYNOPSIS ^

function OK=convertCobraLP2mps(LPProblem,name)

DESCRIPTION ^

 create an MPS (Mathematical Programming System) format ascii file 
 representing the Linear Programming problem given by LPProblem.

 The MPS (Mathematical Programming System) file format was introduced by
 IBM in 1970s, but has also been accepted by most subsequent linear
 programming codes. To learn about MPS format, please see:
   http://lpsolve.sourceforge.net/5.5/mps-format.htm

 INPUT
 LPproblem Structure containing the following fields describing the LP
           problem to be solved
           A      LHS matrix
           b      RHS vector
           c      Objective coeff vector
           lb     Lower bound vector
           ub     Upper bound vector
           osense Objective sense (-1 max, +1 min)
           csense Constraint senses, a string containting the constraint sense for
                  each row in A ('E', equality, 'G' greater than, 'L' less than).

 OPTIONAL INPUT
 name      string giving name of LP problem     
 
 OUTPUT
 OK      1 if saving is success, 0 otherwise

 Ronan M.T. Fleming: 7 Sept 09
 Uses MPS format exporting tool by Bruno Luong 03 Sep 2009
 http://www.mathworks.com/matlabcentral/fileexchange/19618

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function OK=convertCobraLP2mps(LPProblem,name)
0002 % create an MPS (Mathematical Programming System) format ascii file
0003 % representing the Linear Programming problem given by LPProblem.
0004 %
0005 % The MPS (Mathematical Programming System) file format was introduced by
0006 % IBM in 1970s, but has also been accepted by most subsequent linear
0007 % programming codes. To learn about MPS format, please see:
0008 %   http://lpsolve.sourceforge.net/5.5/mps-format.htm
0009 %
0010 % INPUT
0011 % LPproblem Structure containing the following fields describing the LP
0012 %           problem to be solved
0013 %           A      LHS matrix
0014 %           b      RHS vector
0015 %           c      Objective coeff vector
0016 %           lb     Lower bound vector
0017 %           ub     Upper bound vector
0018 %           osense Objective sense (-1 max, +1 min)
0019 %           csense Constraint senses, a string containting the constraint sense for
0020 %                  each row in A ('E', equality, 'G' greater than, 'L' less than).
0021 %
0022 % OPTIONAL INPUT
0023 % name      string giving name of LP problem
0024 %
0025 % OUTPUT
0026 % OK      1 if saving is success, 0 otherwise
0027 %
0028 % Ronan M.T. Fleming: 7 Sept 09
0029 % Uses MPS format exporting tool by Bruno Luong 03 Sep 2009
0030 % http://www.mathworks.com/matlabcentral/fileexchange/19618
0031 
0032 if ~exist('name','var')
0033     name='CobraLPProblem';
0034 end
0035 
0036 mlt=size(LPProblem.A,1);
0037 if ~isfield(LPProblem,'csense')
0038     LPProblem.csense(1:mlt)='E';
0039 end
0040 if size(LPProblem.csense,1)>size(LPProblem.csense,2)
0041     LPProblem.csense=LPProblem.csense';
0042 end
0043 
0044 E=false(mlt,1);
0045 G=false(mlt,1);
0046 L=false(mlt,1);
0047 Eind=findstr('E',LPProblem.csense);
0048 Gind=findstr('G',LPProblem.csense);
0049 Lind=findstr('L',LPProblem.csense);
0050 E(Eind)=1;
0051 G(Gind)=1;
0052 L(Lind)=1;
0053 
0054 Aeq=LPProblem.A(E,:);
0055 beq=LPProblem.b(E,1);
0056 
0057 %need to change sign of A*x >= b constraints
0058 A2=LPProblem.A;
0059 b2=LPProblem.b;
0060 A2(G)=-A2(G);
0061 b2(G)=-b2(G);
0062 A=A2(G | L,:);
0063 b=b2(G | L,:);
0064 
0065 cost=LPProblem.c*LPProblem.osense;
0066 
0067 L=LPProblem.lb;
0068 U=LPProblem.ub;
0069 
0070 
0071 
0072 % Build ascii fixed-width MPS matrix string that contains linear
0073 % programming (LP) problem:
0074 %
0075 % Minimizing (for x in R^n): f(x) = cost'*x, subject to
0076 %       A*x <= b        (LE)
0077 %       Aeq*x = beq     (EQ)
0078 %       L <= x <= U     (BD).
0079 
0080 [Contain]=BuildMPS(A, b, Aeq, beq, cost, L, U,upper(name));
0081 
0082 % Save matrix sring Contain in file "filename"
0083 % Return OK == 1 if saving is success
0084 %        OK == 0 otherwise
0085 filename=[name '.mps'];
0086 OK=SaveMPS(filename, Contain);
0087

Generated on Thu 21-Jun-2012 15:39:23 by m2html © 2003