Skip to content

Commit

Permalink
Merge pull request #2367 from rmtfleming/develop
Browse files Browse the repository at this point in the history
updates to solvers
  • Loading branch information
rmtfleming authored Nov 7, 2024
2 parents ebef82f + ab3ca80 commit c23dce3
Show file tree
Hide file tree
Showing 31 changed files with 1,544 additions and 1,020 deletions.
53 changes: 18 additions & 35 deletions initCobraToolbox.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ function initCobraToolbox(updateToolbox)
%
% initCobraToolbox
% -or-
% changeCobraSolver('gurobi');
% changeCobraSolver('gurobi', 'MILP');
% changeCobraSolver('tomlab_cplex', 'QP');
% changeCobraSolver('tomlab_cplex', 'MIQP');
% changeCbMapOutput('svg');
% changeCobraSolver('gurobi','all');
% changeCobraSolver('mosek', 'CLP');
%
% Maintained by Ronan M.T. Fleming

Expand Down Expand Up @@ -362,18 +359,7 @@ function initCobraToolbox(updateToolbox)
% requires the solver compatibility to be re-read at each initialisation
clear isCompatible

%These default tolerances are based on the default values for the Gurobi LP
%solver. Do not change them without first consulting with other developers.
%https://www.gurobi.com/documentation/9.0/refman/parameters.html
% (primal) feasibility tolerance
changeCobraSolverParams('LP', 'feasTol', 1e-6);
% (dual) optimality tolerance
changeCobraSolverParams('LP', 'optTol', 1e-6);

% (primal) feasibility tolerance
changeCobraSolverParams('EP', 'feasTol', 1e-8);
% (dual) optimality tolerance
changeCobraSolverParams('EP', 'optTol', 1e-12);

% Check that SBML toolbox is installed and accessible
if ~exist('TranslateSBML', 'file')
Expand Down Expand Up @@ -409,10 +395,8 @@ function initCobraToolbox(updateToolbox)
%Define a set of "use first" solvers, other supported solvers will also be added to the struct.
%This allows to assign them in any order but keep the most commonly used ones on top of the struct.
SOLVERS = struct('gurobi',struct(),...
'ibm_cplex',struct(),...
'tomlab_cplex',struct(),...
'glpk',struct(),...
'mosek',struct(),...
'glpk',struct(),...
'matlab',struct());

% active support - supported solvers
Expand All @@ -423,25 +407,24 @@ function initCobraToolbox(updateToolbox)
SOLVERS.quadMinos.type = {'LP'};
SOLVERS.dqqMinos.type = {'LP','QP'};
SOLVERS.matlab.type = {'LP', 'NLP'};
% active support of cplex interfaces - supported solvers
SOLVERS.cplex_direct.type = {'LP', 'MILP', 'QP'};
SOLVERS.ibm_cplex.type = {'LP', 'MILP', 'QP', 'MIQP'};
SOLVERS.cplexlp.type = {'LP'};
SOLVERS.tomlab_cplex.type = {'LP', 'MILP', 'QP', 'MIQP'};


% passive support - solver interfaces
SOLVERS.qpng.type = {'QP'};
SOLVERS.tomlab_snopt.type = {'NLP'};

% legacy solvers
SOLVERS.cplex_direct.type = {'LP', 'MILP', 'QP'};
SOLVERS.ibm_cplex.type = {'LP', 'MILP', 'QP', 'MIQP'};
SOLVERS.cplexlp.type = {'LP'};
SOLVERS.tomlab_cplex.type = {'LP', 'MILP', 'QP', 'MIQP'};
%SOLVERS.gurobi_mex.type = {'LP', 'MILP', 'QP', 'MIQP'};
%SOLVERS.lindo_old.type = {'LP'};
%SOLVERS.lindo_legacy.type = {'LP'};
SOLVERS.lp_solve.type = {'LP'};
%SOLVERS.opti.type = {'LP', 'MILP', 'QP', 'MIQP', 'NLP'};

% definition of category of solvers with active support

SOLVERS.dqqMinos.categ = 'active';
SOLVERS.glpk.categ = 'active';
SOLVERS.gurobi.categ = 'active';
Expand All @@ -450,11 +433,6 @@ function initCobraToolbox(updateToolbox)
SOLVERS.pdco.categ = 'active';
SOLVERS.quadMinos.categ = 'active';

SOLVERS.cplex_direct.categ = 'active';
SOLVERS.ibm_cplex.categ = 'active';
SOLVERS.cplexlp.categ = 'active';
SOLVERS.tomlab_cplex.categ = 'active';

% definition of category of solvers with passive support
SOLVERS.qpng.categ = 'passive';
SOLVERS.tomlab_snopt.categ = 'passive';
Expand All @@ -464,6 +442,10 @@ function initCobraToolbox(updateToolbox)
%SOLVERS.lindo_old.categ = 'legacy';
%SOLVERS.lindo_legacy.categ = 'legacy';
SOLVERS.lp_solve.categ = 'legacy';
SOLVERS.cplex_direct.categ = 'legacy';
SOLVERS.ibm_cplex.categ = 'legacy';
SOLVERS.cplexlp.categ = 'legacy';
SOLVERS.tomlab_cplex.categ = 'legacy';
%SOLVERS.opti.categ = 'legacy';

% definition of categories of solvers
Expand All @@ -484,17 +466,19 @@ function initCobraToolbox(updateToolbox)
end
end

% check the installation of the solver
supportedSolversNames = setdiff(supportedSolversNames,{'cplex_direct','ibm_cplex','cplexlp','tomlab_cplex'});

% check the installation of the solver - except cplex
for i = 1:length(supportedSolversNames)
if 0 %set to 1 to debug a new solver
disp(supportedSolversNames{i})
if strcmp(supportedSolversNames{i},'quadMinos')
pause(0.1)
if strcmp(supportedSolversNames{i},'quadMinos')
disp(supportedSolversNames{i})
end
end
%We will validate all solvers in init. After this, all solvers are
%checked, whether they actually work and the SOLVERS field is set.
[solverOK,solverInstalled] = changeCobraSolver(supportedSolversNames{i},SOLVERS.(supportedSolversNames{i}).type{1},0, 2);
[solverOK,solverInstalled] = changeCobraSolver(supportedSolversNames{i},SOLVERS.(supportedSolversNames{i}).type{1},0, 1);
if strcmp(supportedSolversNames{i},'gurobi') && 0%use fordebugging
disp(supportedSolversNames{i});
end
Expand Down Expand Up @@ -667,7 +651,6 @@ function initCobraToolbox(updateToolbox)

% use Gurobi (if installed) as the default solver for LP, QP and MILP problems
changeCobraSolver('gurobi', 'ALL', 0);
%changeCobraSolver('ibm_cplex', 'QP', 0); %until problem with gurobi QP sorted

% check if a new update exists
if installedGit && ENV_VARS.printLevel && status_curl == 0 && contains(result_curl, ' 200') && updateToolbox
Expand Down
Loading

0 comments on commit c23dce3

Please sign in to comment.