[2] | 1 | // Copyright (C) 2004, International Business Machines |
---|
| 2 | // Corporation and others. All Rights Reserved. |
---|
| 3 | #ifndef CbcBranchLotsize_H |
---|
| 4 | #define CbcBranchLotsize_H |
---|
| 5 | |
---|
| 6 | #include "CbcBranchBase.hpp" |
---|
| 7 | |
---|
| 8 | /** Lotsize class */ |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | class CbcLotsize : public CbcObject { |
---|
| 12 | |
---|
| 13 | public: |
---|
| 14 | |
---|
| 15 | // Default Constructor |
---|
| 16 | CbcLotsize (); |
---|
| 17 | |
---|
| 18 | /* Useful constructor - passed model index. |
---|
| 19 | Also passed valid values - if range then pairs |
---|
| 20 | */ |
---|
| 21 | CbcLotsize (CbcModel * model, int iColumn, |
---|
| 22 | int numberPoints, const double * points, bool range=false); |
---|
| 23 | |
---|
| 24 | // Copy constructor |
---|
| 25 | CbcLotsize ( const CbcLotsize &); |
---|
| 26 | |
---|
| 27 | /// Clone |
---|
| 28 | virtual CbcObject * clone() const; |
---|
| 29 | |
---|
| 30 | // Assignment operator |
---|
| 31 | CbcLotsize & operator=( const CbcLotsize& rhs); |
---|
| 32 | |
---|
| 33 | // Destructor |
---|
| 34 | ~CbcLotsize (); |
---|
| 35 | |
---|
[765] | 36 | using CbcObject::infeasibility ; |
---|
[2] | 37 | /// Infeasibility - large is 0.5 |
---|
| 38 | virtual double infeasibility(int & preferredWay) const; |
---|
| 39 | |
---|
[765] | 40 | using CbcObject::feasibleRegion ; |
---|
[2] | 41 | /** Set bounds to contain the current solution. |
---|
| 42 | |
---|
| 43 | More precisely, for the variable associated with this object, take the |
---|
| 44 | value given in the current solution, force it within the current bounds |
---|
| 45 | if required, then set the bounds to fix the variable at the integer |
---|
| 46 | nearest the solution value. |
---|
| 47 | */ |
---|
| 48 | virtual void feasibleRegion(); |
---|
| 49 | |
---|
[765] | 50 | using CbcObject::createBranch ; |
---|
[2] | 51 | /// Creates a branching object |
---|
[129] | 52 | virtual CbcBranchingObject * createBranch(int way) ; |
---|
[2] | 53 | |
---|
| 54 | /** \brief Given a valid solution (with reduced costs, etc.), |
---|
| 55 | return a branching object which would give a new feasible |
---|
| 56 | point in the good direction. |
---|
| 57 | |
---|
| 58 | The preferred branching object will force the variable to be +/-1 from |
---|
| 59 | its current value, depending on the reduced cost and objective sense. If |
---|
| 60 | movement in the direction which improves the objective is impossible due |
---|
| 61 | to bounds on the variable, the branching object will move in the other |
---|
| 62 | direction. If no movement is possible, the method returns NULL. |
---|
| 63 | |
---|
| 64 | Only the bounds on this variable are considered when determining if the new |
---|
| 65 | point is feasible. |
---|
| 66 | */ |
---|
| 67 | virtual CbcBranchingObject * preferredNewFeasible() const; |
---|
| 68 | |
---|
| 69 | /** \brief Given a valid solution (with reduced costs, etc.), |
---|
| 70 | return a branching object which would give a new feasible |
---|
| 71 | point in a bad direction. |
---|
| 72 | |
---|
| 73 | As for preferredNewFeasible(), but the preferred branching object will |
---|
| 74 | force movement in a direction that degrades the objective. |
---|
| 75 | */ |
---|
| 76 | virtual CbcBranchingObject * notPreferredNewFeasible() const ; |
---|
| 77 | |
---|
| 78 | /** Reset original upper and lower bound values from the solver. |
---|
| 79 | |
---|
| 80 | Handy for updating bounds held in this object after bounds held in the |
---|
| 81 | solver have been tightened. |
---|
| 82 | */ |
---|
[640] | 83 | virtual void resetBounds(const OsiSolverInterface * solver); |
---|
[2] | 84 | |
---|
| 85 | /** Finds range of interest so value is feasible in range range_ or infeasible |
---|
| 86 | between hi[range_] and lo[range_+1]. Returns true if feasible. |
---|
| 87 | */ |
---|
| 88 | bool findRange(double value) const; |
---|
| 89 | |
---|
| 90 | /** Returns floor and ceiling |
---|
| 91 | */ |
---|
| 92 | virtual void floorCeiling(double & floorLotsize, double & ceilingLotsize, double value, |
---|
| 93 | double tolerance) const; |
---|
| 94 | |
---|
| 95 | /// Model column number |
---|
| 96 | inline int modelSequence() const |
---|
[706] | 97 | {return columnNumber_;} |
---|
[2] | 98 | |
---|
[74] | 99 | /** Column number if single column object -1 otherwise, |
---|
| 100 | so returns >= 0 |
---|
| 101 | Used by heuristics |
---|
| 102 | */ |
---|
| 103 | virtual int columnNumber() const; |
---|
[2] | 104 | /// Original bounds |
---|
| 105 | inline double originalLowerBound() const |
---|
[706] | 106 | { return bound_[0];} |
---|
[2] | 107 | inline double originalUpperBound() const |
---|
[706] | 108 | { return bound_[rangeType_*numberRanges_-1];} |
---|
[2] | 109 | /// Type - 1 points, 2 ranges |
---|
| 110 | inline int rangeType() const |
---|
[706] | 111 | { return rangeType_;} |
---|
[2] | 112 | /// Number of points |
---|
| 113 | inline int numberRanges() const |
---|
[706] | 114 | { return numberRanges_;} |
---|
[2] | 115 | /// Ranges |
---|
| 116 | inline double * bound() const |
---|
[706] | 117 | { return bound_;} |
---|
[640] | 118 | /** \brief Return true if object can take part in normal heuristics |
---|
| 119 | */ |
---|
| 120 | virtual bool canDoHeuristics() const |
---|
[706] | 121 | {return false;} |
---|
[2] | 122 | |
---|
[72] | 123 | private: |
---|
| 124 | /// Just for debug (CBC_PRINT defined in CbcBranchLotsize.cpp) |
---|
| 125 | void printLotsize(double value,bool condition,int type) const; |
---|
[2] | 126 | |
---|
| 127 | private: |
---|
| 128 | /// data |
---|
| 129 | |
---|
| 130 | /// Column number in model |
---|
| 131 | int columnNumber_; |
---|
| 132 | /// Type - 1 points, 2 ranges |
---|
| 133 | int rangeType_; |
---|
| 134 | /// Number of points |
---|
| 135 | int numberRanges_; |
---|
| 136 | // largest gap |
---|
| 137 | double largestGap_; |
---|
| 138 | /// Ranges |
---|
| 139 | double * bound_; |
---|
| 140 | /// Current range |
---|
| 141 | mutable int range_; |
---|
| 142 | }; |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | /** Lotsize branching object |
---|
| 146 | |
---|
| 147 | This object can specify a two-way branch on an integer variable. For each |
---|
| 148 | arm of the branch, the upper and lower bounds on the variable can be |
---|
| 149 | independently specified. |
---|
| 150 | |
---|
| 151 | Variable_ holds the index of the integer variable in the integerVariable_ |
---|
| 152 | array of the model. |
---|
| 153 | */ |
---|
| 154 | |
---|
| 155 | class CbcLotsizeBranchingObject : public CbcBranchingObject { |
---|
| 156 | |
---|
| 157 | public: |
---|
| 158 | |
---|
| 159 | /// Default constructor |
---|
| 160 | CbcLotsizeBranchingObject (); |
---|
| 161 | |
---|
| 162 | /** Create a lotsize floor/ceiling branch object |
---|
| 163 | |
---|
| 164 | Specifies a simple two-way branch. Let \p value = x*. One arm of the |
---|
| 165 | branch will be is lb <= x <= valid range below(x*), the other valid range above(x*) <= x <= ub. |
---|
| 166 | Specify way = -1 to set the object state to perform the down arm first, |
---|
| 167 | way = 1 for the up arm. |
---|
| 168 | */ |
---|
| 169 | CbcLotsizeBranchingObject (CbcModel *model, int variable, |
---|
| 170 | int way , double value,const CbcLotsize * lotsize) ; |
---|
| 171 | |
---|
| 172 | /** Create a degenerate branch object |
---|
| 173 | |
---|
| 174 | Specifies a `one-way branch'. Calling branch() for this object will |
---|
| 175 | always result in lowerValue <= x <= upperValue. Used to fix in valid range |
---|
| 176 | */ |
---|
| 177 | |
---|
| 178 | CbcLotsizeBranchingObject (CbcModel *model, int variable, int way, |
---|
| 179 | double lowerValue, double upperValue) ; |
---|
| 180 | |
---|
| 181 | /// Copy constructor |
---|
| 182 | CbcLotsizeBranchingObject ( const CbcLotsizeBranchingObject &); |
---|
| 183 | |
---|
| 184 | /// Assignment operator |
---|
| 185 | CbcLotsizeBranchingObject & operator= (const CbcLotsizeBranchingObject& rhs); |
---|
| 186 | |
---|
| 187 | /// Clone |
---|
| 188 | virtual CbcBranchingObject * clone() const; |
---|
| 189 | |
---|
| 190 | /// Destructor |
---|
| 191 | virtual ~CbcLotsizeBranchingObject (); |
---|
| 192 | |
---|
[765] | 193 | using CbcBranchingObject::branch ; |
---|
[2] | 194 | /** \brief Sets the bounds for the variable according to the current arm |
---|
| 195 | of the branch and advances the object state to the next arm. |
---|
| 196 | */ |
---|
[640] | 197 | virtual double branch(); |
---|
[2] | 198 | |
---|
[765] | 199 | using CbcBranchingObject::print ; |
---|
[2] | 200 | /** \brief Print something about branch - only if log level high |
---|
| 201 | */ |
---|
[640] | 202 | virtual void print(); |
---|
[2] | 203 | |
---|
[213] | 204 | protected: |
---|
[2] | 205 | /// Lower [0] and upper [1] bounds for the down arm (way_ = -1) |
---|
| 206 | double down_[2]; |
---|
| 207 | /// Lower [0] and upper [1] bounds for the up arm (way_ = 1) |
---|
| 208 | double up_[2]; |
---|
| 209 | }; |
---|
| 210 | |
---|
| 211 | |
---|
| 212 | #endif |
---|