| 1 | // Copyright (C) 2002, International Business Machinescxx . . $ `<file>/Cgl/src/CglGomory/CglGomory.hpp`/ |
| 2 | // Corporation and others. All Rights Reserved. |
| 3 | // This code is licensed under the terms of the Eclipse Public License (EPL). |
| 4 | |
| 5 | #ifndef CglGomory_H |
| 6 | #define CglGomory_Hcxx . . $ `Cgl/src/CglGomory/CglGomory.hpp:6:9`! |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "CglCutGenerator.hpp"cxx . . $ `<file>/Cgl/src/CglCutGenerator.hpp`/ |
| 11 | |
| 12 | class CoinWarmStartBasiscxx . . $ CoinWarmStartBasis#; |
| 13 | /** Gomory Cut Generator Class */ |
| 14 | class CglGomorycxx . . $ CglGomory# : public CglCutGeneratorcxx . . $ CglCutGenerator# { |
| 15 | friend void CglGomoryUnitTestcxx . . $ CglGomoryUnitTest(d8c7ffe7dd7e392).(const OsiSolverInterfacecxx . . $ OsiSolverInterface# * siP, |
| 16 | const stdcxx . . $ std/::stringcxx . . $ std/string# mpdDir ); |
| 17 | |
| 18 | public: |
| 19 | |
| 20 | |
| 21 | /**@name Generate Cuts */ |
| 22 | //@{ |
| 23 | /** Generate Mixed Integer Gomory cuts for the model of the |
| 24 | solver interface, si. |
| 25 | |
| 26 | Insert the generated cuts into OsiCut, cs. |
| 27 | |
| 28 | There is a limit option, which will only generate cuts with |
| 29 | less than this number of entries. |
| 30 | |
| 31 | We can also only look at 0-1 variables a certain distance |
| 32 | from integer. |
| 33 | */ |
| 34 | virtual void generateCutscxx . . $ CglGomory#generateCuts(a7cd996c3d1130d3).( const OsiSolverInterfacecxx . . $ OsiSolverInterface# & si, OsiCutscxx . . $ OsiCuts# & cs, |
| 35 | const CglTreeInfocxx . . $ CglTreeInfo# info = CglTreeInfocxx . . $ CglTreeInfo#()); |
| 36 | /** Generates cuts given matrix and solution etc, |
| 37 | returns number of cuts generated */ |
| 38 | int generateCutscxx . . $ CglGomory#generateCuts(7e48a86048072f33).( const OsiRowCutDebuggercxx . . $ OsiRowCutDebugger# * debugger, |
| 39 | OsiCutscxx . . $ OsiCuts# & cs, |
| 40 | const CoinPackedMatrixcxx . . $ CoinPackedMatrix# & columnCopy, |
| 41 | const CoinPackedMatrixcxx . . $ CoinPackedMatrix# & rowCopy, |
| 42 | const double * colsol, |
| 43 | const double * colLower, const double * colUpper, |
| 44 | const double * rowLower, const double * rowUpper, |
| 45 | const char * intVar , |
| 46 | const CoinWarmStartBasiscxx . . $ CoinWarmStartBasis#* warm, |
| 47 | const CglTreeInfocxx . . $ CglTreeInfo# info = CglTreeInfocxx . . $ CglTreeInfo#CglTreeInfo(49f6e7a06ebc5aa8).()); |
| 48 | /** Generates cuts given matrix and solution etc, |
| 49 | returns number of cuts generated (no row copy passed in) */ |
| 50 | int generateCutscxx . . $ CglGomory#generateCuts(3a1eb8e237c8613f).( const OsiRowCutDebuggercxx . . $ OsiRowCutDebugger# * debugger, |
| 51 | OsiCutscxx . . $ OsiCuts# & cs, |
| 52 | const CoinPackedMatrixcxx . . $ CoinPackedMatrix# & columnCopy, |
| 53 | const double * colsol, |
| 54 | const double * colLower, const double * colUpper, |
| 55 | const double * rowLower, const double * rowUpper, |
| 56 | const char * intVar , |
| 57 | const CoinWarmStartBasiscxx . . $ CoinWarmStartBasis#* warm, |
| 58 | const CglTreeInfocxx . . $ CglTreeInfo# info = CglTreeInfocxx . . $ CglTreeInfo#()); |
| 59 | |
| 60 | /// Return true if needs optimal basis to do cuts (will return true) |
| 61 | virtual bool needsOptimalBasiscxx . . $ CglGomory#needsOptimalBasis(50ce9a9e25b4a850).() const { return true; } |
| 62 | //@} |
| 63 | |
| 64 | /**@name Change way Gomory works */ |
| 65 | //@{ |
| 66 | /// Pass in a copy of original solver (clone it) |
| 67 | void passInOriginalSolvercxx . . $ CglGomory#passInOriginalSolver(148ed51524aa7e8b).(OsiSolverInterfacecxx . . $ OsiSolverInterface# * solver); |
| 68 | /// Returns original solver |
| 69 | inline OsiSolverInterfacecxx . . $ OsiSolverInterface# * originalSolvercxx . . $ CglGomory#originalSolver(936ede0c62590209).() const |
| 70 | { return originalSolver_cxx . . $ CglGomory#originalSolver_.;} |
| 71 | /// Set type - 0 normal, 1 add original matrix one, 2 replace |
| 72 | inline void setGomoryTypecxx . . $ CglGomory#setGomoryType(d4f767463ce0a6b3).(int type) |
| 73 | { gomoryType_cxx . . $ CglGomory#gomoryType_.=type;} |
| 74 | /// Return type |
| 75 | inline int gomoryTypecxx . . $ CglGomory#gomoryType(455f465bc33b4cdf).() const |
| 76 | { return gomoryType_cxx . . $ CglGomory#gomoryType_.;} |
| 77 | //@} |
| 78 | |
| 79 | /**@name Change limit on how many variables in cut (default 50) */ |
| 80 | //@{ |
| 81 | /// Set |
| 82 | void setLimitcxx . . $ CglGomory#setLimit(d4f767463ce0a6b3).(int limit); |
| 83 | /// Get |
| 84 | int getLimitcxx . . $ CglGomory#getLimit(455f465bc33b4cdf).() const; |
| 85 | /// Set at root (if <normal then use normal) |
| 86 | void setLimitAtRootcxx . . $ CglGomory#setLimitAtRoot(d4f767463ce0a6b3).(int limit); |
| 87 | /// Get at root |
| 88 | int getLimitAtRootcxx . . $ CglGomory#getLimitAtRoot(455f465bc33b4cdf).() const; |
| 89 | /// Return maximum length of cut in tree |
| 90 | virtual int maximumLengthOfCutInTreecxx . . $ CglGomory#maximumLengthOfCutInTree(455f465bc33b4cdf).() const; |
| 91 | //@} |
| 92 | |
| 93 | /**@name Change criterion on which variables to look at. All ones |
| 94 | more than "away" away from integrality will be investigated |
| 95 | (default 0.05) */ |
| 96 | //@{ |
| 97 | /// Set away |
| 98 | void setAwaycxx . . $ CglGomory#setAway(ba8836b59fb42830).(double value); |
| 99 | /// Get away |
| 100 | double getAwaycxx . . $ CglGomory#getAway(21b6c25e127938e2).() const; |
| 101 | /// Set away at root |
| 102 | void setAwayAtRootcxx . . $ CglGomory#setAwayAtRoot(ba8836b59fb42830).(double value); |
| 103 | /// Get away at root |
| 104 | double getAwayAtRootcxx . . $ CglGomory#getAwayAtRoot(21b6c25e127938e2).() const; |
| 105 | //@} |
| 106 | |
| 107 | /**@name Change criterion on which the cut id relaxed if the code |
| 108 | thinks the factorization has inaccuracies. The relaxation to |
| 109 | RHS is smallest of - |
| 110 | 1) 1.0e-4 |
| 111 | 2) conditionNumberMultiplier * condition number of factorization |
| 112 | 3) largestFactorMultiplier * largest (dual*element) forming tableau |
| 113 | row |
| 114 | */ |
| 115 | //@{ |
| 116 | /// Set ConditionNumberMultiplier |
| 117 | void setConditionNumberMultipliercxx . . $ CglGomory#setConditionNumberMultiplier(ba8836b59fb42830).(double value); |
| 118 | /// Get ConditionNumberMultiplier |
| 119 | double getConditionNumberMultipliercxx . . $ CglGomory#getConditionNumberMultiplier(21b6c25e127938e2).() const; |
| 120 | /// Set LargestFactorMultiplier |
| 121 | void setLargestFactorMultipliercxx . . $ CglGomory#setLargestFactorMultiplier(ba8836b59fb42830).(double value); |
| 122 | /// Get LargestFactorMultiplier |
| 123 | double getLargestFactorMultipliercxx . . $ CglGomory#getLargestFactorMultiplier(21b6c25e127938e2).() const; |
| 124 | //@} |
| 125 | |
| 126 | /**@name change factorization */ |
| 127 | //@{ |
| 128 | /// Set/unset alternative factorization |
| 129 | inline void useAlternativeFactorizationcxx . . $ CglGomory#useAlternativeFactorization(b45ddcbc8423892c).(bool yes=true) |
| 130 | { alternateFactorization_cxx . . $ CglGomory#alternateFactorization_.= (yes) ? 1 : 0;} |
| 131 | /// Get whether alternative factorization being used |
| 132 | inline bool alternativeFactorizationcxx . . $ CglGomory#alternativeFactorization(50ce9a9e25b4a850).() const |
| 133 | { return (alternateFactorization_cxx . . $ CglGomory#alternateFactorization_.!=0);} |
| 134 | //@} |
| 135 | |
| 136 | /**@name Constructors and destructors */ |
| 137 | //@{ |
| 138 | /// Default constructor |
| 139 | CglGomorycxx . . $ CglGomory#CglGomory(49f6e7a06ebc5aa8). (); |
| 140 | |
| 141 | /// Copy constructor |
| 142 | CglGomorycxx . . $ CglGomory#CglGomory(3090b40798f0a2cf). ( |
| 143 | const CglGomorycxx . . $ CglGomory# &); |
| 144 | |
| 145 | /// Clone |
| 146 | virtual CglCutGeneratorcxx . . $ CglCutGenerator# * clonecxx . . $ CglGomory#clone(ff686f57cc59f31d).() const; |
| 147 | |
| 148 | /// Assignment operator |
| 149 | CglGomorycxx . . $ CglGomory# & |
| 150 | operatorcxx . . $ CglGomory#`operator=`(a4878c148715b03f).=( |
| 151 | const CglGomorycxx . . $ CglGomory#& rhs); |
| 152 | |
| 153 | /// Destructor |
| 154 | virtual |
| 155 | ~cxx . . $ CglGomory#`~CglGomory`(ced63f7c635d850d).CglGomorycxx . . $ CglGomory# (); |
| 156 | /// Create C++ lines to get to current state |
| 157 | virtual stdcxx . . $ std/::stringcxx . . $ std/string# generateCppcxx . . $ CglGomory#generateCpp(d8c45821d4afeee5).( FILEcxx . . $ FILE# * fp); |
| 158 | /// This can be used to refresh any inforamtion |
| 159 | virtual void refreshSolvercxx . . $ CglGomory#refreshSolver(148ed51524aa7e8b).(OsiSolverInterfacecxx . . $ OsiSolverInterface# * solver); |
| 160 | //@} |
| 161 | |
| 162 | private: |
| 163 | |
| 164 | // Private member methods |
| 165 | |
| 166 | // Private member data |
| 167 | |
| 168 | /**@name Private member data */ |
| 169 | //@{ |
| 170 | /// Only investigate if more than this away from integrality |
| 171 | double away_cxx . . $ CglGomory#away_.; |
| 172 | /// Only investigate if more than this away from integrality (at root) |
| 173 | double awayAtRoot_cxx . . $ CglGomory#awayAtRoot_.; |
| 174 | /// Multiplier for conditionNumber cut relaxation |
| 175 | double conditionNumberMultiplier_cxx . . $ CglGomory#conditionNumberMultiplier_.; |
| 176 | /// Multiplier for largest factor cut relaxation |
| 177 | double largestFactorMultiplier_cxx . . $ CglGomory#largestFactorMultiplier_.; |
| 178 | /// Original solver |
| 179 | OsiSolverInterfacecxx . . $ OsiSolverInterface# * originalSolver_cxx . . $ CglGomory#originalSolver_.; |
| 180 | /// Limit - only generate if fewer than this in cut |
| 181 | int limit_cxx . . $ CglGomory#limit_.; |
| 182 | /// Limit - only generate if fewer than this in cut (at root) |
| 183 | int limitAtRoot_cxx . . $ CglGomory#limitAtRoot_.; |
| 184 | /// Dynamic limit in tree |
| 185 | int dynamicLimitInTree_cxx . . $ CglGomory#dynamicLimitInTree_.; |
| 186 | /// Number of times stalled |
| 187 | int numberTimesStalled_cxx . . $ CglGomory#numberTimesStalled_.; |
| 188 | /// nonzero to use alternative factorization |
| 189 | int alternateFactorization_cxx . . $ CglGomory#alternateFactorization_.; |
| 190 | /// Type - 0 normal, 1 add original matrix one, 2 replace |
| 191 | int gomoryType_cxx . . $ CglGomory#gomoryType_.; // note could add in cutoff as constraint |
| 192 | //@} |
| 193 | }; |
| 194 | |
| 195 | //############################################################################# |
| 196 | /** A function that tests the methods in the CglGomory class. The |
| 197 | only reason for it not to be a member method is that this way it doesn't |
| 198 | have to be compiled into the library. And that's a gain, because the |
| 199 | library should be compiled with optimization on, but this method should be |
| 200 | compiled with debugging. */ |
| 201 | void CglGomoryUnitTestcxx . . $ CglGomoryUnitTest(d8c7ffe7dd7e392).(const OsiSolverInterfacecxx . . $ OsiSolverInterface# * siP, |
| 202 | const stdcxx . . $ std/::stringcxx . . $ std/string# mpdDir ); |
| 203 | |
| 204 | #endif |