|
59 | 59 |
|
60 | 60 | % Markus Herrgard 1/23/07
|
61 | 61 | % Tim Harrington 05/18/12 Added support for the Gurobi 5.0 solver
|
62 |
| -% <<<<<<< HEAD |
63 | 62 | % Ronan (16/07/2013) default MPS parameters are no longer global variables
|
64 |
| -% ======= |
65 | 63 | % Meiyappan Lakshmanan 11/14/14 Added support for the cplex_direct solver
|
66 | 64 | % cplex_direct solver accesible through CPLEX m-file and CPLEX C-interface
|
67 |
| -% >>>>>>> 987a38606db2c6c47ed5421155258bb27fd34cbe |
| 65 | +% Thomas Pfau (12/11/2015) Added support for ibm_cplex (the IBM Matlab |
| 66 | +% interface) to the solvers. |
68 | 67 |
|
69 | 68 | %% Process options
|
70 | 69 |
|
|
161 | 160 | parametersStructureFlag=0;
|
162 | 161 | [minNorm, printLevel, primalOnlyFlag, saveInput, feasTol, optTol] = ...
|
163 | 162 | getCobraSolverParams('LP',optParamNames(1:6));
|
| 163 | + %parameters will later be accessed and should be initialized. |
| 164 | + parameters = ''; |
164 | 165 | end
|
165 | 166 |
|
166 | 167 |
|
|
348 | 349 | else
|
349 | 350 | solStat = -1; % Solution not optimal or solver problem
|
350 | 351 | end
|
| 352 | + case 'ibm_cplex' |
| 353 | + cplexlp = Cplex(); |
| 354 | + if (~isempty(csense)) |
| 355 | + b_L(csense == 'E') = b(csense == 'E'); |
| 356 | + b_U(csense == 'E') = b(csense == 'E'); |
| 357 | + b_L(csense == 'G') = b(csense == 'G'); |
| 358 | + b_U(csense == 'G') = inf; |
| 359 | + b_L(csense == 'L') = -inf; |
| 360 | + b_U(csense == 'L') = b(csense == 'L'); |
| 361 | + elseif isfield(MILPproblem, 'b_L') && isfield(MILPproblem, 'b_U') |
| 362 | + b_L = MILPproblem.b_L; |
| 363 | + b_U = MILPproblem.b_U; |
| 364 | + else |
| 365 | + b_L = b; |
| 366 | + b_U = b; |
| 367 | + end |
| 368 | + intVars = (vartype == 'B') | (vartype == 'I'); |
| 369 | + %intVars |
| 370 | + %pause; |
| 371 | + cplexlp.Model.A = A; |
| 372 | + cplexlp.Model.rhs = b_U; |
| 373 | + cplexlp.Model.lhs = b_L; |
| 374 | + cplexlp.Model.ub = ub; |
| 375 | + cplexlp.Model.lb = lb; |
| 376 | + cplexlp.Model.obj = osense * c; |
| 377 | + cplexlp.Model.name = 'CobraMILP'; |
| 378 | + cplexlp.Model.ctype = vartype'; |
| 379 | + cplexlp.Start.x = x0; |
| 380 | + cplexlp.Param.mip.tolerances.mipgap.Cur = solverParams.relMipGapTol; |
| 381 | + cplexlp.Param.mip.tolerances.integrality.Cur = solverParams.intTol; |
| 382 | + cplexlp.Param.timelimit.Cur = solverParams.timeLimit; |
| 383 | + cplexlp.Param.output.writelevel.Cur = solverParams.printLevel; |
351 | 384 |
|
352 |
| - case 'gurobi5' |
| 385 | + outputfile = fopen(solverParams.logFile,'a'); |
| 386 | + cplexlp.DisplayFunc = @redirect; |
| 387 | + |
| 388 | + cplexlp.Param.simplex.tolerances.optimality.Cur = solverParams.optTol; |
| 389 | + cplexlp.Param.mip.tolerances.absmipgap.Cur = solverParams.absMipGapTol; |
| 390 | + cplexlp.Param.simplex.tolerances.feasibility.Cur = solverParams.feasTol; |
| 391 | + % Strict numerical tolerances |
| 392 | + cplexlp.Param.emphasis.numerical.Cur = solverParams.NUMERICALEMPHASIS; |
| 393 | + save('MILPProblem','cplexlp') |
| 394 | + |
| 395 | + % Set up callback to print out intermediate solutions |
| 396 | + % only set this up if you know that you actually need these |
| 397 | + % results. Otherwise do not specify intSolInd and contSolInd |
| 398 | + |
| 399 | + % Solve problem |
| 400 | + Result = cplexlp.solve(); |
| 401 | + |
| 402 | + % Get results |
| 403 | + x = Result.x; |
| 404 | + f = osense*Result.objval; |
| 405 | + stat = Result.status; |
| 406 | + if (stat == 101 || stat == 102 || stat == 1) |
| 407 | + solStat = 1; % Opt integer within tolerance |
| 408 | + elseif (stat == 103 || stat == 3) |
| 409 | + solStat = 0; % Integer infeas |
| 410 | + elseif (stat == 118 || stat == 119 || stat == 2) |
| 411 | + solStat = 2; % Unbounded |
| 412 | + elseif (stat == 106 || stat == 106 || stat == 108 || stat == 110 || stat == 112 || stat == 114 || stat == 117) |
| 413 | + solStat = -1; % No integer solution exists |
| 414 | + else |
| 415 | + solStat = 3; % Other problem, but integer solution exists |
| 416 | + end |
| 417 | + if exist([pwd filesep 'clone1.log'],'file') |
| 418 | + delete('clone1.log') |
| 419 | + end |
| 420 | + |
| 421 | + case {'gurobi5','gurobi6'} |
353 | 422 | %% gurobi 5
|
354 | 423 | % Free academic licenses for the Gurobi solver can be obtained from
|
355 | 424 | % http://www.gurobi.com/html/academic.html
|
|
417 | 486 | solStat = 2; % Unbounded
|
418 | 487 | elseif strcmp(resultgurobi.status,'INF_OR_UNBD')
|
419 | 488 | solStat = 0; % Gurobi reports infeasible *or* unbounded
|
420 |
| - elseif strcmp(resultgurobi.status,'SUBOPTIMAL') |
421 |
| - solStat = -1; % Suboptimal solution |
422 |
| - [x,f] = deal(resultgurobi.x,resultgurobi.objval); |
423 | 489 | else
|
424 | 490 | solStat = -1; % Solution not optimal or solver problem
|
425 | 491 | end
|
|
589 | 655 | %[solution] = BuildMPS(Ale, ble, Aeq, beq, c, lb, ub, PbName,'MPSfilename',MPSfilename,'EleNames',EleNames,'EqtNames',EqtNames,'VarNames',VarNames);
|
590 | 656 |
|
591 | 657 | return
|
| 658 | + |
592 | 659 | otherwise
|
593 | 660 | error(['Unknown solver: ' solver]);
|
594 | 661 | end
|
|
616 | 683 | end
|
617 | 684 | end
|
618 | 685 |
|
| 686 | +%% Redirection function such that cplex redirects its output to the defined outputfile. |
| 687 | +function redirect(l) |
| 688 | + % Write the line of log output |
| 689 | + fprintf(outputfile, '%s\n', l); |
| 690 | +end |
| 691 | + |
| 692 | +end |
| 693 | + |
0 commit comments