Changeset 191 for branches/pre
- Timestamp:
- Aug 7, 2003 2:49:43 AM (18 years ago)
- Location:
- branches/pre
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/pre/ClpSimplexPrimalQuadratic.cpp
r190 r191 565 565 // may factorize, checks if problem finished 566 566 statusOfProblemInPrimal(lastCleaned,factorType,progress_,info); 567 if (problemStatus_>=0) 568 break; // declare victory 567 569 568 570 // Compute objective function from scratch … … 1138 1140 } 1139 1141 { 1142 double oldValue = objectiveValue_; 1140 1143 // Compute objective function from scratch 1141 1144 const CoinPackedMatrix * quadratic = … … 1192 1195 printf("After Housekeeping True objective is %g, infeas cost %g, sum %g\n", 1193 1196 objectiveValue_,infeasCost,objectiveValue_+infeasCost); 1197 if (objectiveValue_>oldValue) { 1198 // make less likely this one will come in again 1199 double multiplier = CoinDrand48(); 1200 int iSequence; 1201 if (!cleanupIteration) { 1202 iSequence = sequenceIn_; 1203 } else { 1204 int iSequence = info->crucialSj(); 1205 if (iSequence>numberRows_) 1206 iSequence -= numberRows_; 1207 else 1208 iSequence = numberColumns_ +(iSequence-numberXColumns); 1209 } 1210 info->djWeight()[iSequence] /= (5.0+multiplier); 1211 } 1194 1212 } 1195 1213 if (sequenceOut_>=numberXColumns&&sequenceOut_<numberColumns_) { … … 1214 1232 cleanupIteration = true; 1215 1233 // may not be correct on second time 1216 if (result&&(returnCode==-1||returnCode==-2 )) {1234 if (result&&(returnCode==-1||returnCode==-2||returnCode==-3)) { 1217 1235 assert(sequenceOut_<numberXColumns|| 1218 1236 sequenceOut_>=numberColumns_); … … 1556 1574 double upperTheta = maximumMovement; 1557 1575 bool throwAway=false; 1558 if (numberIterations_ ==700||numberIterations_==694) {1576 if (numberIterations_>=2007) { 1559 1577 printf("Bad iteration coming up after iteration %d\n",numberIterations_); 1560 1578 } … … 1645 1663 maximumSwapped = max(maximumSwapped,numberSwapped); 1646 1664 1647 double dualCheck = - 2.0*coeff2*tentativeTheta - coeff1 - 0.1*infeasibilityCost_; 1648 // but make a bit more pessimistic 1649 dualCheck=max(dualCheck-100.0*dualTolerance_,0.99*dualCheck); 1665 //double dualCheck = - 2.0*coeff2*tentativeTheta - coeff1 - 0.1*infeasibilityCost_; 1666 double dualCheck = - 2.0*coeff2*tentativeTheta - coeff1; 1667 // but make a bit more pessimistic if pivot 1668 //if (bestPivot>acceptablePivot) 1669 //dualCheck=max(dualCheck-100.0*dualTolerance_,0.99*dualCheck); 1650 1670 //dualCheck=0.0; 1651 1671 if (totalThru+thruThis>=dualCheck) { … … 2472 2492 int numberXColumns = info->numberXColumns(); 2473 2493 int numberXRows = info->numberXRows(); 2474 int iSequence;2475 2494 int start=numberXColumns+numberXRows; 2476 2495 numberDualInfeasibilities_=0; 2477 2496 sumDualInfeasibilities_=0.0; 2478 2497 const int * which = info->quadraticSequence(); 2479 for (iSequence=0;iSequence<numberXColumns;iSequence++) { 2480 int jSequence = which[iSequence]; 2481 double value=dj_[iSequence]; 2482 ClpSimplex::Status status = getColumnStatus(iSequence); 2498 // Compute objective function from scratch 2499 const CoinPackedMatrix * quadratic = 2500 info->originalModel()->quadraticObjective(); 2501 const int * columnQuadratic = quadratic->getIndices(); 2502 const int * columnQuadraticStart = quadratic->getVectorStarts(); 2503 const int * columnQuadraticLength = quadratic->getVectorLengths(); 2504 const double * quadraticElement = quadratic->getElements(); 2505 const double * originalCost = info->originalObjective(); 2506 int iColumn; 2507 objectiveValue_=0.0; 2508 double infeasCost=0.0; 2509 double linearCost=0.0; 2510 for (iColumn=0;iColumn<numberXColumns;iColumn++) { 2511 double valueI = solution_[iColumn]; 2512 linearCost += valueI*originalCost[iColumn]; 2513 double diff =cost_[iColumn]-originalCost[iColumn]; 2514 // WE are always feasible so look at low not up! 2515 if (diff>0.0) { 2516 double above = valueI-lower_[iColumn]; 2517 assert(above>=0.0); 2518 infeasCost += diff*above; 2519 } else if (diff<0.0) { 2520 double below = upper_[iColumn]-valueI; 2521 assert(below>=0.0); 2522 infeasCost -= diff*below; 2523 } 2524 int j; 2525 for (j=columnQuadraticStart[iColumn]; 2526 j<columnQuadraticStart[iColumn]+columnQuadraticLength[iColumn];j++) { 2527 int jColumn = columnQuadratic[j]; 2528 double valueJ = solution_[jColumn]; 2529 double elementValue = 0.5*quadraticElement[j]; 2530 objectiveValue_ += valueI*valueJ*elementValue; 2531 } 2532 int jSequence = which[iColumn]; 2533 double value=dj_[iColumn]; 2534 ClpSimplex::Status status = getColumnStatus(iColumn); 2483 2535 2484 2536 switch(status) { … … 2489 2541 if (getColumnStatus(jSequence)==basic) 2490 2542 handler_->message(CLP_QUADRATIC_BOTH,messages_) 2491 <<"Structural"<<i Sequence2492 <<solution_[i Sequence]<<jSequence<<solution_[jSequence]2543 <<"Structural"<<iColumn 2544 <<solution_[iColumn]<<jSequence<<solution_[jSequence] 2493 2545 <<CoinMessageEol; 2494 2546 } … … 2517 2569 } 2518 2570 int offset = numberXColumns; 2519 for (iSequence=0;iSequence<numberXRows;iSequence++) { 2520 int jSequence = iSequence+offset; 2521 double value=dj_[iSequence+numberColumns_]; 2522 ClpSimplex::Status status = getRowStatus(iSequence); 2571 int iRow; 2572 for (iRow=0;iRow<numberXRows;iRow++) { 2573 int iColumn = iRow + numberColumns_; 2574 double diff =cost_[iColumn]; 2575 double valueI = solution_[iColumn]; 2576 if (diff>0.0) { 2577 double above = valueI-lower_[iColumn]; 2578 assert(above>=0.0); 2579 infeasCost += diff*above; 2580 } else if (diff<0.0) { 2581 double below = upper_[iColumn]-valueI; 2582 assert(below>=0.0); 2583 infeasCost -= diff*below; 2584 } 2585 int jSequence = iRow+offset; 2586 double value=dj_[iRow+numberColumns_]; 2587 ClpSimplex::Status status = getRowStatus(iRow); 2523 2588 2524 2589 switch(status) { … … 2527 2592 if (getColumnStatus(jSequence)==basic) 2528 2593 printf("Row %d (%g) and %d (%g) both basic\n", 2529 i Sequence,solution_[iSequence],jSequence,solution_[jSequence]);2594 iRow,solution_[iColumn],jSequence,solution_[jSequence]); 2530 2595 break; 2531 2596 case ClpSimplex::isFixed: … … 2551 2616 } 2552 2617 } 2618 objectiveValue_ += linearCost+infeasCost; 2619 assert (infeasCost>=0.0); 2553 2620 sumOfRelaxedDualInfeasibilities_ =sumDualInfeasibilities_; 2621 numberDualInfeasibilitiesWithoutFree_= numberDualInfeasibilities_; 2554 2622 return numberDualInfeasibilities_; 2555 2623 } … … 2947 3015 setColumnStatus(iColumn,status); 2948 3016 if (status==basic) { 2949 assert(fabs(value)<1.0e- 7);3017 assert(fabs(value)<1.0e-2); 2950 3018 } 2951 3019 int j; … … 2996 3064 validPhase_(-1), 2997 3065 validSolution_(NULL), 3066 djWeight_(NULL), 2998 3067 numberXRows_(-1), 2999 3068 numberXColumns_(-1), … … 3014 3083 validPhase_(-1), 3015 3084 validSolution_(NULL), 3085 djWeight_(NULL), 3016 3086 numberXRows_(-1), 3017 3087 numberXColumns_(-1), … … 3029 3099 backSequence_[i]=i; 3030 3100 } 3101 int numberColumns = numberXRows_+numberXColumns_+numberQuadraticColumns_; 3102 int numberRows = numberXRows_+numberQuadraticColumns_; 3103 int size = numberRows+numberColumns; 3104 djWeight_ = new double [size]; 3105 for (i=0;i<size;i++) 3106 djWeight_[i]=1.0; 3031 3107 } 3032 3108 } … … 3038 3114 delete [] currentSolution_; 3039 3115 delete [] validSolution_; 3116 delete [] djWeight_; 3040 3117 } 3041 3118 // Copy … … 3076 3153 validSolution_ = NULL; 3077 3154 } 3155 if (rhs.djWeight_) { 3156 djWeight_ = new double [size]; 3157 memcpy(djWeight_,rhs.djWeight_,size*sizeof(double)); 3158 } else { 3159 djWeight_ = NULL; 3160 } 3078 3161 } 3079 3162 } … … 3088 3171 delete [] currentSolution_; 3089 3172 delete [] validSolution_; 3173 delete [] djWeight_; 3090 3174 currentSequenceIn_ = rhs.currentSequenceIn_; 3091 3175 crucialSj_ = rhs.crucialSj_; … … 3122 3206 } else { 3123 3207 validSolution_ = NULL; 3208 } 3209 if (rhs.djWeight_) { 3210 djWeight_ = new double [size]; 3211 memcpy(djWeight_,rhs.djWeight_,size*sizeof(double)); 3212 } else { 3213 djWeight_ = NULL; 3124 3214 } 3125 3215 } -
branches/pre/include/ClpSimplexPrimalQuadratic.hpp
r186 r191 174 174 /// Restore previous 175 175 void restoreStatus(); 176 ///Dj weights 177 inline double * djWeight() const 178 { return djWeight_;}; 176 179 //@} 177 180 … … 201 204 /// Valid saved solution 202 205 double * validSolution_; 206 /// Dj weights to stop looping 207 double * djWeight_; 203 208 /// Number of original rows 204 209 int numberXRows_;
Note: See TracChangeset
for help on using the changeset viewer.