[1370] | 1 | /* $Id: ClpDualRowDantzig.cpp 1402 2009-07-25 08:39:55Z forrest $ */ |
---|
[2] | 2 | // Copyright (C) 2002, International Business Machines |
---|
| 3 | // Corporation and others. All Rights Reserved. |
---|
| 4 | |
---|
[63] | 5 | #include "CoinPragma.hpp" |
---|
[2] | 6 | #include "ClpSimplex.hpp" |
---|
| 7 | #include "ClpDualRowDantzig.hpp" |
---|
[1197] | 8 | #include "ClpFactorization.hpp" |
---|
[50] | 9 | #include "CoinIndexedVector.hpp" |
---|
[399] | 10 | #include "CoinHelperFunctions.hpp" |
---|
[2] | 11 | |
---|
| 12 | //############################################################################# |
---|
| 13 | // Constructors / Destructor / Assignment |
---|
| 14 | //############################################################################# |
---|
| 15 | |
---|
| 16 | //------------------------------------------------------------------- |
---|
| 17 | // Default Constructor |
---|
| 18 | //------------------------------------------------------------------- |
---|
| 19 | ClpDualRowDantzig::ClpDualRowDantzig () |
---|
| 20 | : ClpDualRowPivot() |
---|
| 21 | { |
---|
| 22 | type_=1; |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | //------------------------------------------------------------------- |
---|
| 26 | // Copy constructor |
---|
| 27 | //------------------------------------------------------------------- |
---|
| 28 | ClpDualRowDantzig::ClpDualRowDantzig (const ClpDualRowDantzig & source) |
---|
| 29 | : ClpDualRowPivot(source) |
---|
| 30 | { |
---|
| 31 | |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | //------------------------------------------------------------------- |
---|
| 35 | // Destructor |
---|
| 36 | //------------------------------------------------------------------- |
---|
| 37 | ClpDualRowDantzig::~ClpDualRowDantzig () |
---|
| 38 | { |
---|
| 39 | |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | //---------------------------------------------------------------- |
---|
| 43 | // Assignment operator |
---|
| 44 | //------------------------------------------------------------------- |
---|
| 45 | ClpDualRowDantzig & |
---|
| 46 | ClpDualRowDantzig::operator=(const ClpDualRowDantzig& rhs) |
---|
| 47 | { |
---|
| 48 | if (this != &rhs) { |
---|
| 49 | ClpDualRowPivot::operator=(rhs); |
---|
| 50 | } |
---|
| 51 | return *this; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | // Returns pivot row, -1 if none |
---|
| 55 | int |
---|
| 56 | ClpDualRowDantzig::pivotRow() |
---|
| 57 | { |
---|
| 58 | assert(model_); |
---|
| 59 | int iRow; |
---|
| 60 | const int * pivotVariable = model_->pivotVariable(); |
---|
| 61 | double largest=model_->currentPrimalTolerance(); |
---|
| 62 | // we can't really trust infeasibilities if there is primal error |
---|
| 63 | if (model_->largestPrimalError()>1.0e-8) |
---|
| 64 | largest *= model_->largestPrimalError()/1.0e-8; |
---|
| 65 | int chosenRow=-1; |
---|
| 66 | for (iRow=0;iRow<model_->numberRows();iRow++) { |
---|
| 67 | int iPivot=pivotVariable[iRow]; |
---|
| 68 | double value = model_->solution(iPivot); |
---|
| 69 | double lower = model_->lower(iPivot); |
---|
| 70 | double upper = model_->upper(iPivot); |
---|
[399] | 71 | if (CoinMax(value-upper,lower-value)>largest) { |
---|
[2] | 72 | int iSequence = pivotVariable[iRow]; |
---|
| 73 | if (!model_->flagged(iSequence)) { |
---|
| 74 | chosenRow=iRow; |
---|
[399] | 75 | largest=CoinMax(value-upper,lower-value); |
---|
[2] | 76 | } |
---|
| 77 | } |
---|
| 78 | } |
---|
| 79 | return chosenRow; |
---|
| 80 | } |
---|
[1197] | 81 | // FT update and returns pivot alpha |
---|
[225] | 82 | double |
---|
[1402] | 83 | ClpDualRowDantzig::updateWeights(CoinIndexedVector * /*input*/, |
---|
[225] | 84 | CoinIndexedVector * spare, |
---|
[1402] | 85 | CoinIndexedVector * /*spare2*/, |
---|
[225] | 86 | CoinIndexedVector * updatedColumn) |
---|
| 87 | { |
---|
[1197] | 88 | // Do FT update |
---|
| 89 | model_->factorization()->updateColumnFT(spare,updatedColumn); |
---|
[225] | 90 | // pivot element |
---|
| 91 | double alpha=0.0; |
---|
| 92 | // look at updated column |
---|
| 93 | double * work = updatedColumn->denseVector(); |
---|
| 94 | int number = updatedColumn->getNumElements(); |
---|
| 95 | int * which = updatedColumn->getIndices(); |
---|
| 96 | int i; |
---|
| 97 | int pivotRow = model_->pivotRow(); |
---|
| 98 | |
---|
| 99 | if (updatedColumn->packedMode()) { |
---|
| 100 | for (i =0; i < number; i++) { |
---|
| 101 | int iRow = which[i]; |
---|
| 102 | if (iRow==pivotRow) { |
---|
| 103 | alpha = work[i]; |
---|
| 104 | break; |
---|
| 105 | } |
---|
| 106 | } |
---|
| 107 | } else { |
---|
| 108 | alpha = work[pivotRow]; |
---|
| 109 | } |
---|
| 110 | return alpha; |
---|
| 111 | } |
---|
[2] | 112 | |
---|
| 113 | /* Updates primal solution (and maybe list of candidates) |
---|
| 114 | Uses input vector which it deletes |
---|
| 115 | Computes change in objective function |
---|
| 116 | */ |
---|
| 117 | void |
---|
[50] | 118 | ClpDualRowDantzig::updatePrimalSolution(CoinIndexedVector * primalUpdate, |
---|
[2] | 119 | double primalRatio, |
---|
| 120 | double & objectiveChange) |
---|
| 121 | { |
---|
| 122 | double * work = primalUpdate->denseVector(); |
---|
| 123 | int number = primalUpdate->getNumElements(); |
---|
| 124 | int * which = primalUpdate->getIndices(); |
---|
| 125 | int i; |
---|
| 126 | double changeObj=0.0; |
---|
| 127 | const int * pivotVariable = model_->pivotVariable(); |
---|
[225] | 128 | if (primalUpdate->packedMode()) { |
---|
| 129 | for (i=0;i<number;i++) { |
---|
| 130 | int iRow=which[i]; |
---|
| 131 | int iPivot=pivotVariable[iRow]; |
---|
| 132 | double & value = model_->solutionAddress(iPivot); |
---|
| 133 | double cost = model_->cost(iPivot); |
---|
| 134 | double change = primalRatio*work[i]; |
---|
| 135 | value -= change; |
---|
| 136 | changeObj -= change*cost; |
---|
| 137 | work[i]=0.0; |
---|
| 138 | } |
---|
| 139 | } else { |
---|
| 140 | for (i=0;i<number;i++) { |
---|
| 141 | int iRow=which[i]; |
---|
| 142 | int iPivot=pivotVariable[iRow]; |
---|
| 143 | double & value = model_->solutionAddress(iPivot); |
---|
| 144 | double cost = model_->cost(iPivot); |
---|
| 145 | double change = primalRatio*work[iRow]; |
---|
| 146 | value -= change; |
---|
| 147 | changeObj -= change*cost; |
---|
| 148 | work[iRow]=0.0; |
---|
| 149 | } |
---|
[2] | 150 | } |
---|
| 151 | primalUpdate->setNumElements(0); |
---|
| 152 | objectiveChange += changeObj; |
---|
| 153 | } |
---|
| 154 | //------------------------------------------------------------------- |
---|
| 155 | // Clone |
---|
| 156 | //------------------------------------------------------------------- |
---|
| 157 | ClpDualRowPivot * ClpDualRowDantzig::clone(bool CopyData) const |
---|
| 158 | { |
---|
| 159 | if (CopyData) { |
---|
| 160 | return new ClpDualRowDantzig(*this); |
---|
| 161 | } else { |
---|
| 162 | return new ClpDualRowDantzig(); |
---|
| 163 | } |
---|
| 164 | } |
---|
| 165 | |
---|