Changeset 2385 for trunk/Clp/src/ClpPrimalColumnDantzig.cpp
 Timestamp:
 Jan 6, 2019 2:43:06 PM (4 months ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/Clp/src/ClpPrimalColumnDantzig.cpp
r1732 r2385 22 22 // Default Constructor 23 23 // 24 ClpPrimalColumnDantzig::ClpPrimalColumnDantzig 25 26 { 27 24 ClpPrimalColumnDantzig::ClpPrimalColumnDantzig() 25 : ClpPrimalColumnPivot() 26 { 27 type_ = 1; 28 28 } 29 29 … … 31 31 // Copy constructor 32 32 // 33 ClpPrimalColumnDantzig::ClpPrimalColumnDantzig (const ClpPrimalColumnDantzig & source) 34 : ClpPrimalColumnPivot(source) 35 { 36 33 ClpPrimalColumnDantzig::ClpPrimalColumnDantzig(const ClpPrimalColumnDantzig &source) 34 : ClpPrimalColumnPivot(source) 35 { 37 36 } 38 37 … … 40 39 // Destructor 41 40 // 42 ClpPrimalColumnDantzig::~ClpPrimalColumnDantzig () 43 { 44 41 ClpPrimalColumnDantzig::~ClpPrimalColumnDantzig() 42 { 45 43 } 46 44 … … 49 47 // 50 48 ClpPrimalColumnDantzig & 51 ClpPrimalColumnDantzig::operator=(const ClpPrimalColumnDantzig &rhs)52 { 53 54 55 56 49 ClpPrimalColumnDantzig::operator=(const ClpPrimalColumnDantzig &rhs) 50 { 51 if (this != &rhs) { 52 ClpPrimalColumnPivot::operator=(rhs); 53 } 54 return *this; 57 55 } 58 56 59 57 // Returns pivot column, 1 if none 60 int 61 ClpPrimalColumnDantzig::pivotColumn(CoinIndexedVector * updates, 62 CoinIndexedVector * /*spareRow1*/, 63 CoinIndexedVector * spareRow2, 64 CoinIndexedVector * spareColumn1, 65 CoinIndexedVector * spareColumn2) 66 { 67 assert(model_); 68 int iSection, j; 69 int number; 70 int * index; 71 double * updateBy; 72 double * reducedCost; 73 74 bool anyUpdates; 75 76 if (updates>getNumElements()) { 77 anyUpdates = true; 78 } else { 79 // sub flip  nothing to do 80 anyUpdates = false; 81 } 82 if (anyUpdates) { 83 model_>factorization()>updateColumnTranspose(spareRow2, updates); 84 // put row of tableau in rowArray and columnArray 85 model_>clpMatrix()>transposeTimes(model_, 1.0, 86 updates, spareColumn2, spareColumn1); 87 for (iSection = 0; iSection < 2; iSection++) { 88 89 reducedCost = model_>djRegion(iSection); 90 91 if (!iSection) { 92 number = updates>getNumElements(); 93 index = updates>getIndices(); 94 updateBy = updates>denseVector(); 95 } else { 96 number = spareColumn1>getNumElements(); 97 index = spareColumn1>getIndices(); 98 updateBy = spareColumn1>denseVector(); 99 } 100 101 for (j = 0; j < number; j++) { 102 int iSequence = index[j]; 103 double value = reducedCost[iSequence]; 104 value = updateBy[j]; 105 updateBy[j] = 0.0; 106 reducedCost[iSequence] = value; 107 } 108 109 } 110 updates>setNumElements(0); 111 spareColumn1>setNumElements(0); 112 } 113 114 115 // update of duals finished  now do pricing 116 117 double largest = model_>currentPrimalTolerance(); 118 // we can't really trust infeasibilities if there is primal error 119 if (model_>largestDualError() > 1.0e8) 120 largest *= model_>largestDualError() / 1.0e8; 121 122 123 124 double bestDj = model_>dualTolerance(); 125 int bestSequence = 1; 126 127 double bestFreeDj = model_>dualTolerance(); 128 int bestFreeSequence = 1; 129 130 number = model_>numberRows() + model_>numberColumns(); 131 int iSequence; 132 reducedCost = model_>djRegion(); 133 134 #ifndef CLP_PRIMAL_SLACK_MULTIPLIER 135 for (iSequence = 0; iSequence < number; iSequence++) { 136 // check flagged variable 137 if (!model_>flagged(iSequence)) { 138 double value = reducedCost[iSequence]; 139 ClpSimplex::Status status = model_>getStatus(iSequence); 140 141 switch(status) { 142 143 case ClpSimplex::basic: 144 case ClpSimplex::isFixed: 145 break; 146 case ClpSimplex::isFree: 147 case ClpSimplex::superBasic: 148 if (fabs(value) > bestFreeDj) { 149 bestFreeDj = fabs(value); 150 bestFreeSequence = iSequence; 151 } 152 break; 153 case ClpSimplex::atUpperBound: 154 if (value > bestDj) { 155 bestDj = value; 156 bestSequence = iSequence; 157 } 158 break; 159 case ClpSimplex::atLowerBound: 160 if (value < bestDj) { 161 bestDj = value; 162 bestSequence = iSequence; 163 } 164 } 165 } 166 } 58 int ClpPrimalColumnDantzig::pivotColumn(CoinIndexedVector *updates, 59 CoinIndexedVector * /*spareRow1*/, 60 CoinIndexedVector *spareRow2, 61 CoinIndexedVector *spareColumn1, 62 CoinIndexedVector *spareColumn2) 63 { 64 assert(model_); 65 int iSection, j; 66 int number; 67 int *index; 68 double *updateBy; 69 double *reducedCost; 70 71 bool anyUpdates; 72 73 if (updates>getNumElements()) { 74 anyUpdates = true; 75 } else { 76 // sub flip  nothing to do 77 anyUpdates = false; 78 } 79 if (anyUpdates) { 80 model_>factorization()>updateColumnTranspose(spareRow2, updates); 81 // put row of tableau in rowArray and columnArray 82 model_>clpMatrix()>transposeTimes(model_, 1.0, 83 updates, spareColumn2, spareColumn1); 84 for (iSection = 0; iSection < 2; iSection++) { 85 86 reducedCost = model_>djRegion(iSection); 87 88 if (!iSection) { 89 number = updates>getNumElements(); 90 index = updates>getIndices(); 91 updateBy = updates>denseVector(); 92 } else { 93 number = spareColumn1>getNumElements(); 94 index = spareColumn1>getIndices(); 95 updateBy = spareColumn1>denseVector(); 96 } 97 98 for (j = 0; j < number; j++) { 99 int iSequence = index[j]; 100 double value = reducedCost[iSequence]; 101 value = updateBy[j]; 102 updateBy[j] = 0.0; 103 reducedCost[iSequence] = value; 104 } 105 } 106 updates>setNumElements(0); 107 spareColumn1>setNumElements(0); 108 } 109 110 // update of duals finished  now do pricing 111 112 double largest = model_>currentPrimalTolerance(); 113 // we can't really trust infeasibilities if there is primal error 114 if (model_>largestDualError() > 1.0e8) 115 largest *= model_>largestDualError() / 1.0e8; 116 117 double bestDj = model_>dualTolerance(); 118 int bestSequence = 1; 119 120 double bestFreeDj = model_>dualTolerance(); 121 int bestFreeSequence = 1; 122 123 number = model_>numberRows() + model_>numberColumns(); 124 int iSequence; 125 reducedCost = model_>djRegion(); 126 127 #ifndef CLP_PRIMAL_SLACK_MULTIPLIER 128 for (iSequence = 0; iSequence < number; iSequence++) { 129 // check flagged variable 130 if (!model_>flagged(iSequence)) { 131 double value = reducedCost[iSequence]; 132 ClpSimplex::Status status = model_>getStatus(iSequence); 133 134 switch (status) { 135 136 case ClpSimplex::basic: 137 case ClpSimplex::isFixed: 138 break; 139 case ClpSimplex::isFree: 140 case ClpSimplex::superBasic: 141 if (fabs(value) > bestFreeDj) { 142 bestFreeDj = fabs(value); 143 bestFreeSequence = iSequence; 144 } 145 break; 146 case ClpSimplex::atUpperBound: 147 if (value > bestDj) { 148 bestDj = value; 149 bestSequence = iSequence; 150 } 151 break; 152 case ClpSimplex::atLowerBound: 153 if (value < bestDj) { 154 bestDj = value; 155 bestSequence = iSequence; 156 } 157 } 158 } 159 } 167 160 #else 168 169 170 171 172 173 174 175 176 switch(status) {177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 for (; iSequence < number; iSequence++) {204 205 206 207 208 209 switch(status) {210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 161 // Columns 162 int numberColumns = model_>numberColumns(); 163 for (iSequence = 0; iSequence < numberColumns; iSequence++) { 164 // check flagged variable 165 if (!model_>flagged(iSequence)) { 166 double value = reducedCost[iSequence]; 167 ClpSimplex::Status status = model_>getStatus(iSequence); 168 169 switch (status) { 170 171 case ClpSimplex::basic: 172 case ClpSimplex::isFixed: 173 break; 174 case ClpSimplex::isFree: 175 case ClpSimplex::superBasic: 176 if (fabs(value) > bestFreeDj) { 177 bestFreeDj = fabs(value); 178 bestFreeSequence = iSequence; 179 } 180 break; 181 case ClpSimplex::atUpperBound: 182 if (value > bestDj) { 183 bestDj = value; 184 bestSequence = iSequence; 185 } 186 break; 187 case ClpSimplex::atLowerBound: 188 if (value < bestDj) { 189 bestDj = value; 190 bestSequence = iSequence; 191 } 192 } 193 } 194 } 195 // Rows 196 for (; iSequence < number; iSequence++) { 197 // check flagged variable 198 if (!model_>flagged(iSequence)) { 199 double value = reducedCost[iSequence] * CLP_PRIMAL_SLACK_MULTIPLIER; 200 ClpSimplex::Status status = model_>getStatus(iSequence); 201 202 switch (status) { 203 204 case ClpSimplex::basic: 205 case ClpSimplex::isFixed: 206 break; 207 case ClpSimplex::isFree: 208 case ClpSimplex::superBasic: 209 if (fabs(value) > bestFreeDj) { 210 bestFreeDj = fabs(value); 211 bestFreeSequence = iSequence; 212 } 213 break; 214 case ClpSimplex::atUpperBound: 215 if (value > bestDj) { 216 bestDj = value; 217 bestSequence = iSequence; 218 } 219 break; 220 case ClpSimplex::atLowerBound: 221 if (value < bestDj) { 222 bestDj = value; 223 bestSequence = iSequence; 224 } 225 } 226 } 227 } 235 228 #endif 236 237 238 239 229 // bias towards free 230 if (bestFreeSequence >= 0 && bestFreeDj > 0.1 * bestDj) 231 bestSequence = bestFreeSequence; 232 return bestSequence; 240 233 } 241 234 … … 243 236 // Clone 244 237 // 245 ClpPrimalColumnPivot * ClpPrimalColumnDantzig::clone(bool CopyData) const 246 { 247 if (CopyData) { 248 return new ClpPrimalColumnDantzig(*this); 249 } else { 250 return new ClpPrimalColumnDantzig(); 251 } 252 } 253 238 ClpPrimalColumnPivot *ClpPrimalColumnDantzig::clone(bool CopyData) const 239 { 240 if (CopyData) { 241 return new ClpPrimalColumnDantzig(*this); 242 } else { 243 return new ClpPrimalColumnDantzig(); 244 } 245 } 246 247 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2 248 */
Note: See TracChangeset
for help on using the changeset viewer.