function ret = cpxcb_INCUMBENT(x,f,Prob,cbxCBInfo) CPLEX MIP Incumbent callback Called from TOMLAB /CPLEX during mixed integer optimization when a new integer solution has been found but before this solution has replaced the current best known integer solution. This file can be used to perform any desired analysis of the new integer solution and return a status flag to the solver deciding whether to stop or continue the optimization, and also whether to accept or discard the newly found solution. This callback is enabled by setting callback(14)=1 in the call to cplex.m, or Prob.MIP.callback(14)=1 if using tomRun('cplex',...) cpxcb_INCUMBENT is called by the solver with three arguments: x - the new integer solution f - the objective value at x Prob - the Tomlab problem structure cpxcb_INCUMBENT should return one of the following scalar values: 0 Continue optimization and accept new integer solution 1 Continue optimization but discard new integer solution 2 Stop optimization and accept new integer solution 3 Stop optimization adn discard new integer solution Any other return value will be interpreted as 0. If modifying this file, it is recommended to make a copy of it which is placed before the original file in the MATLAB path.
0001 % function ret = cpxcb_INCUMBENT(x,f,Prob,cbxCBInfo) 0002 % 0003 % CPLEX MIP Incumbent callback 0004 % 0005 % Called from TOMLAB /CPLEX during mixed integer optimization when a new integer 0006 % solution has been found but before this solution has replaced the current best known integer solution. 0007 % 0008 % This file can be used to perform any desired analysis of the new integer 0009 % solution and return a status flag to the solver deciding whether to stop 0010 % or continue the optimization, and also whether to accept or discard the newly 0011 % found solution. 0012 % 0013 % This callback is enabled by setting callback(14)=1 in the call to 0014 % cplex.m, or Prob.MIP.callback(14)=1 if using tomRun('cplex',...) 0015 % 0016 % cpxcb_INCUMBENT is called by the solver with three arguments: 0017 % 0018 % x - the new integer solution 0019 % f - the objective value at x 0020 % Prob - the Tomlab problem structure 0021 % 0022 % cpxcb_INCUMBENT should return one of the following scalar values: 0023 % 0024 % 0 Continue optimization and accept new integer solution 0025 % 1 Continue optimization but discard new integer solution 0026 % 2 Stop optimization and accept new integer solution 0027 % 3 Stop optimization adn discard new integer solution 0028 % 0029 % Any other return value will be interpreted as 0. 0030 % 0031 % If modifying this file, it is recommended to make a copy of it which 0032 % is placed before the original file in the MATLAB path. 0033 % 0034 0035 % Anders Goran, Tomlab Optimization Inc., E-mail: tomlab@tomopt.com 0036 % Copyright (c) 2002-2007 by Tomlab Optimization Inc., $Release: 10.1.0$ 0037 % Written Jun 1, 2007. Last modified Jun 1, 2007. 0038 0039 function ret = cpxcb_INCUMBENT(x,f,Prob) 0040 0041 % ADD USER CODE HERE. 0042 0043 % Accepted return values are: 0044 % 0045 % 0 Continue optimization and accept new integer solution 0046 % 1 Continue optimization but discard new integer solution 0047 % 2 Stop optimization and accept new integer solution 0048 % 3 Stop optimization adn discard new integer solution 0049 % 0050 % Any other return value will be interpreted as 0. 0051 0052 global MILPproblemType; 0053 0054 switch MILPproblemType 0055 case 'OptKnock' 0056 % Allow printing intermediate OptKnock solutions 0057 0058 global cobraIntSolInd; 0059 global cobraContSolInd; 0060 global selectedRxnIndIrrev; 0061 global rxnList; 0062 global irrev2rev; 0063 global biomassRxnID; 0064 global solutionFileName; 0065 0066 global OptKnockKOrxnList; 0067 global OptKnockObjective; 0068 global OptKnockGrowth; 0069 global solID; 0070 0071 % Initialize 0072 if isempty(solID) 0073 solID = 0; 0074 OptKnockObjective = []; 0075 OptKnockGrowth = []; 0076 OptKnockKOrxnList = {}; 0077 end 0078 0079 solID = solID + 1; 0080 0081 % Get the reactions 0082 OptKnockObjective(solID) = -f; 0083 optKnockRxnInd = selectedRxnIndIrrev(x(cobraIntSolInd) < 1e-4); 0084 optKnockRxns = rxnList(unique(irrev2rev(optKnockRxnInd))); 0085 OptKnockKOrxnList{solID} = optKnockRxns; 0086 0087 % Get the growth rate 0088 fluxes = x(cobraContSolInd); 0089 growth = fluxes(biomassRxnID); 0090 OptKnockGrowth(solID) = growth; 0091 0092 fprintf('OptKnock\t%f\t%f\t',-f,growth); 0093 for i = 1:length(optKnockRxns) 0094 fprintf('%s ',optKnockRxns{i}); 0095 end 0096 fprintf('\n'); 0097 save(solutionFileName,'OptKnockKOrxnList','OptKnockObjective','OptKnockGrowth'); 0098 ret = 0; 0099 0100 otherwise 0101 ret = 0; 0102 end