This function gets the specified parameters in paramNames from parameters, the global cobra paramters variable or default values set within this script. It will use values with the following priority parameters > global parameters > default The specified parameters will be delt to the specified output arguements. See examples below. INPUT solverType Type of solver used: 'LP', 'MILP', 'QP', 'MIQP' paramNames Cell array of strings containing parameter names OR one parameter name as string OPTIONAL INPUTS parameters Structure with fields pertaining to parameter values that should be used in place of global or default parameters. parameters can be set to 'default' to use the default values set within this script. OUTPUTS varargout Variables which each value corresponding to paramNames is outputted to. Examples parameters.saveInput = 'LPproblem.mat'; parameters.printLevel = 1; [printLevel, saveInput] = getCobraSolverParams('LP',{'printLevel', 'saveInput'},parameters); Example using default values [printLevel, saveInput] = getCobraSolverParams('LP',{'printLevel','saveInput'},'default'); Richard Que (12/01/2009)
0001 function varargout = getCobraSolverParams(solverType, paramNames, parameters) 0002 % This function gets the specified parameters in paramNames from 0003 % parameters, the global cobra paramters variable or default values set within 0004 % this script. It will use values with the following priority 0005 % parameters > global parameters > default 0006 % The specified parameters will be delt to the specified output arguements. 0007 % See examples below. 0008 % 0009 %INPUT 0010 % solverType Type of solver used: 'LP', 'MILP', 'QP', 'MIQP' 0011 % paramNames Cell array of strings containing parameter names OR one 0012 % parameter name as string 0013 % 0014 %OPTIONAL INPUTS 0015 % parameters Structure with fields pertaining to parameter values that 0016 % should be used in place of global or default parameters. 0017 % parameters can be set to 'default' to use the default 0018 % values set within this script. 0019 % 0020 %OUTPUTS 0021 % varargout Variables which each value corresponding to paramNames 0022 % is outputted to. 0023 % 0024 %Examples 0025 % parameters.saveInput = 'LPproblem.mat'; 0026 % parameters.printLevel = 1; 0027 % [printLevel, saveInput] = getCobraSolverParams('LP',{'printLevel', 'saveInput'},parameters); 0028 % 0029 %Example using default values 0030 % [printLevel, saveInput] = getCobraSolverParams('LP',{'printLevel','saveInput'},'default'); 0031 % 0032 % Richard Que (12/01/2009) 0033 0034 if nargin < 2 0035 error('getCobraSolverParams: No parameters specified') 0036 end 0037 if nargin <3 0038 parameters = ''; 0039 end 0040 0041 %% Default Values 0042 valDef.minNorm = 0; 0043 valDef.objTol = 1e-6; 0044 valDef.printLevel = 0; 0045 valDef.primalOnly = 0; 0046 valDef.timeLimit = 7*8*3600.0; 0047 valDef.iterationLimit = 1000; 0048 valDef.logFile = ['Cobra' solverType 'Solver.log']; 0049 valDef.saveInput = []; 0050 valDef.PbName = [solverType 'problem']; 0051 0052 0053 %MPS parameters 0054 valDef.MPSfilename = ''; 0055 valDef.EleNames = ''; 0056 valDef.EqtNames = ''; 0057 valDef.VarNames = ''; 0058 valDef.EleNameFun = @(m)(['LE' num2str(m)]); 0059 valDef.EqtNameFun = @(m)(['EQ' num2str(m)]); 0060 valDef.VarNameFun = @(m)(['X' num2str(m)]); 0061 0062 %CPLEX parameters 0063 valDef.DATACHECK = 1; 0064 valDef.DEPIND = 1; 0065 valDef.checkNaN = 0; 0066 valDef.warning = 0; 0067 0068 %tolerances 0069 valDef.intTol = 1e-12; 0070 valDef.relMipGapTol = 1e-12; 0071 valDef.feasTol = 1e-9; 0072 valDef.optTol = 1e-9; 0073 valDef.absMipGapTol = 1e-12; 0074 valDef.NUMERICALEMPHASIS = 1; 0075 0076 0077 %% 0078 if ~iscell(paramNames) 0079 paramNames = {paramNames}; 0080 end 0081 0082 switch solverType 0083 case 'LP' 0084 global CBT_LP_PARAMS 0085 parametersGlobal = CBT_LP_PARAMS; 0086 case 'QP' 0087 global CBT_QP_PARAMS 0088 parametersGlobal = CBT_QP_PARAMS; 0089 case 'MILP' 0090 global CBT_MILP_PARAMS 0091 parametersGlobal = CBT_MILP_PARAMS; 0092 case 'MIQP' 0093 global CBT_MIQP_PARAMS 0094 parametersGlobal = CBT_MIQP_PARAMS; 0095 case 'NLP' 0096 global CBT_NLP_PARAMS 0097 parametersGlobal = CBT_NLP_PARAMS; 0098 otherwise 0099 display('Unrecognized solver type') 0100 return; 0101 end 0102 0103 for i=1:length(paramNames) 0104 %set values to default 0105 if isfield(valDef,paramNames{i}) 0106 varargout{i} = valDef.(paramNames{i}); 0107 end 0108 if ~strcmp(parameters,'default') %skip of using default values 0109 %set values to global values 0110 if isfield(parametersGlobal,paramNames{i}) 0111 varargout{i} = parametersGlobal.(paramNames{i}); 0112 end 0113 %set values to specified values 0114 if isfield(parameters,paramNames{i}) 0115 varargout{i} = parameters.(paramNames{i}); 0116 end 0117 end 0118 end 0119 pause(eps)