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

 1 edited
Legend:
 Unmodified
 Added
 Removed

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