| 1 | /* $Id: ClpPrimalColumnPivot.hpp 1753 2011-06-19 16:27:26Z stefan $ */ |
| 2 | // Copyright (C) 2002, International Business Machines |
| 3 | // Corporation and others. All Rights Reserved. |
| 4 | // This code is licensed under the terms of the Eclipse Public License (EPL). |
| 5 | |
| 6 | #ifndef ClpPrimalcolumnPivot_H |
| 7 | #define ClpPrimalcolumnPivot_H |
| 8 | |
| 9 | class ClpSimplex; |
| 10 | class CoinIndexedVector; |
| 11 | |
| 12 | //############################################################################# |
| 13 | |
| 14 | /** Primal Column Pivot Abstract Base Class |
| 15 | |
| 16 | Abstract Base Class for describing an interface to an algorithm |
| 17 | to choose column pivot in primal simplex algorithm. For some algorithms |
| 18 | e.g. Dantzig choice then some functions may be null. For Dantzig |
| 19 | the only one of any importance is pivotColumn. |
| 20 | |
| 21 | If you wish to inherit from this look at ClpPrimalColumnDantzig.cpp |
| 22 | as that is simplest version. |
| 23 | */ |
| 24 | |
| 25 | class ClpPrimalColumnPivot { |
| 26 | |
| 27 | public: |
| 28 | |
| 29 | ///@name Algorithmic methods |
| 30 | //@{ |
| 31 | |
| 32 | /** Returns pivot column, -1 if none |
| 33 | |
| 34 | Normally updates reduced costs using result of last iteration |
| 35 | before selecting incoming column. |
| 36 | |
| 37 | The Packed CoinIndexedVector updates has cost updates - for normal LP |
| 38 | that is just +-weight where a feasibility changed. It also has |
| 39 | reduced cost from last iteration in pivot row |
| 40 | |
| 41 | Inside pivotColumn the pivotRow_ and reduced cost from last iteration |
| 42 | are also used. |
| 43 | |
| 44 | So in the simplest case i.e. feasible we compute the row of the |
| 45 | tableau corresponding to last pivot and add a multiple of this |
| 46 | to current reduced costs. |
| 47 | |
| 48 | We can use other arrays to help updates |
| 49 | */ |
| 50 | virtual int pivotColumn(CoinIndexedVector * updates, |
| 51 | CoinIndexedVector * spareRow1, |
| 52 | CoinIndexedVector * spareRow2, |
| 53 | CoinIndexedVector * spareColumn1, |
| 54 | CoinIndexedVector * spareColumn2) = 0; |
| 55 | |
| 56 | /// Updates weights - part 1 (may be empty) |
| 57 | virtual void updateWeights(CoinIndexedVector * input); |
| 58 | |
| 59 | /** Saves any weights round factorization as pivot rows may change |
| 60 | Will be empty unless steepest edge (will save model) |
| 61 | May also recompute infeasibility stuff |
| 62 | 1) before factorization |
| 63 | 2) after good factorization (if weights empty may initialize) |
| 64 | 3) after something happened but no factorization |
| 65 | (e.g. check for infeasible) |
| 66 | 4) as 2 but restore weights from previous snapshot |
| 67 | 5) forces some initialization e.g. weights |
| 68 | Also sets model |
| 69 | */ |
| 70 | virtual void saveWeights(ClpSimplex * model, int mode) = 0; |
| 71 | /** Signals pivot row choice: |
| 72 | -2 (default) - use normal pivot row choice |
| 73 | -1 to numberRows-1 - use this (will be checked) |
| 74 | way should be -1 to go to lower bound, +1 to upper bound |
| 75 | */ |
| 76 | virtual int pivotRow(double & way) { |
| 77 | way = 0; |
| 78 | return -2; |
| 79 | } |
| 80 | /// Gets rid of all arrays (may be empty) |
| 81 | virtual void clearArrays(); |
| 82 | /// Returns true if would not find any column |
| 83 | virtual bool looksOptimal() const { |
| 84 | return looksOptimal_; |
| 85 | } |
| 86 | /// Sets optimality flag (for advanced use) |
| 87 | virtual void setLooksOptimal(bool flag) { |
| 88 | looksOptimal_ = flag; |
| 89 | } |
| 90 | //@} |
| 91 | |
| 92 | |
| 93 | ///@name Constructors and destructors |
| 94 | //@{ |
| 95 | /// Default Constructor |
| 96 | ClpPrimalColumnPivot(); |
| 97 | |
| 98 | /// Copy constructor |
| 99 | ClpPrimalColumnPivot(const ClpPrimalColumnPivot &); |
| 100 | |
| 101 | /// Assignment operator |
| 102 | ClpPrimalColumnPivot & operator=(const ClpPrimalColumnPivot& rhs); |
| 103 | |
| 104 | /// Destructor |
| 105 | virtual ~ClpPrimalColumnPivot (); |
| 106 | |
| 107 | /// Clone |
| 108 | virtual ClpPrimalColumnPivot * clone(bool copyData = true) const = 0; |
| 109 | |
| 110 | //@} |
| 111 | |
| 112 | ///@name Other |
| 113 | //@{ |
| 114 | /// Returns model |
| 115 | inline ClpSimplex * model() { |
| 116 | return model_; |
| 117 | } |
| 118 | /// Sets model |
| 119 | inline void setModel(ClpSimplex * newmodel) { |
| 120 | model_ = newmodel; |
| 121 | } |
| 122 | |
| 123 | /// Returns type (above 63 is extra information) |
| 124 | inline int type() { |
| 125 | return type_; |
| 126 | } |
| 127 | |
| 128 | /** Returns number of extra columns for sprint algorithm - 0 means off. |
| 129 | Also number of iterations before recompute |
| 130 | */ |
| 131 | virtual int numberSprintColumns(int & numberIterations) const; |
| 132 | /// Switch off sprint idea |
| 133 | virtual void switchOffSprint(); |
| 134 | /// Called when maximum pivots changes |
| 135 | virtual void maximumPivotsChanged() {} |
| 136 | |
| 137 | //@} |
| 138 | |
| 139 | //--------------------------------------------------------------------------- |
| 140 | |
| 141 | protected: |
| 142 | ///@name Protected member data |
| 143 | //@{ |
| 144 | /// Pointer to model |
| 145 | ClpSimplex * model_; |
| 146 | /// Type of column pivot algorithm |
| 147 | int type_; |
| 148 | /// Says if looks optimal (normally computed) |
| 149 | bool looksOptimal_; |
| 150 | //@} |
| 151 | }; |
| 152 | #ifndef CLP_PRIMAL_SLACK_MULTIPLIER |
| 153 | #define CLP_PRIMAL_SLACK_MULTIPLIER 1.01 |
| 154 | #endif |
| 155 | #endif |
| 156 | |