summaryrefslogtreecommitdiff
path: root/macros/mps_linprog.sci
diff options
context:
space:
mode:
Diffstat (limited to 'macros/mps_linprog.sci')
-rw-r--r--macros/mps_linprog.sci90
1 files changed, 90 insertions, 0 deletions
diff --git a/macros/mps_linprog.sci b/macros/mps_linprog.sci
new file mode 100644
index 0000000..55f3edf
--- /dev/null
+++ b/macros/mps_linprog.sci
@@ -0,0 +1,90 @@
+// Copyright (C) 2015 - IIT Bombay - FOSSEE
+//
+// Author: Bhanu Priya Sayal, Guru Pradeep Reddy
+// Organization: FOSSEE, IIT Bombay
+// Email:bhanupriyasayal@gmail.com,gurupradeept@gmail.com
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+
+function [xopt,fopt,exitflag,output,lambda] =mps_linprog(varargin)
+
+ //To check the number of input and output argument
+ [lhs , rhs] = argn();
+
+ //To check the number of argument given by user
+ if ( rhs < 1 | rhs > 2) then
+ errmsg = msprintf(gettext("%s: Unexpected number of input arguments : %d provided while should be in the set of [1 2]"),"linprog",rhs);
+ error(errmsg)
+ end
+ mpsFile = varargin(1);
+
+ [sizeFile isFile] = fileinfo(mpsFile);
+ if(isFile ~= 0) then
+ errmsg = msprintf(gettext("%s: File is not present at the given location"),"linprog",rhs);
+ error(errmsg)
+ end
+
+ if ( rhs<2 | size(varargin(2)) ==0 ) then
+ param = list();
+ else
+ param =varargin(2);
+ end
+
+ if (type(param) ~= 15) then
+ errmsg = msprintf(gettext("%s: options should be a list "), "mps_linprog");
+ error(errmsg);
+ end
+
+ if (modulo(size(param),2)) then
+ errmsg = msprintf(gettext("%s: Size of parameters should be even"), "mps_linprog");
+ error(errmsg);
+ end
+ options = list("MaxIter" , [3000],);
+
+ for i = 1:(size(param))/2
+ select param(2*i-1)
+ case "MaxIter" then
+ options(2*i) = param(2*i);
+ end
+ end
+ //Calling the function by passing the required parameters
+
+ [xopt,fopt,status,iter,Zl,dual] = rmps(mpsFile,options);
+
+ xopt = xopt';
+ fopt=fopt;
+ exitflag = status;
+ output = struct("Iterations" , []);
+ output.Iterations = iter;
+ lambda = struct("reduced_cost" , [], ..
+ "dual" ,[]);
+
+ lambda.reduced_cost = Zl;
+ lambda.dual =dual;
+
+ select status
+
+ case 0 then
+ printf("\nOptimal Solution.\n");
+ case 1 then
+ printf("\nPrimal Infeasible.\n");
+ case 2 then
+ printf("\nDual Infeasible.\n");
+ case 3 then
+ printf("\nIteration limit reached.\n");
+ case 4 then
+ printf("\nNumerical Difficulties.\n");
+ case 5 then
+ printf("\nPrimal Objective limit reached.\n");
+ case 6 then
+ printf("\nDual Objective limit reached.\n");
+ else
+ printf("\nInvalid status returned. Notify the Toolbox authors\n");
+ break;
+ end
+
+endfunction