Changeset 138 for trunk


Ignore:
Timestamp:
May 20, 2005 10:45:30 AM (15 years ago)
Author:
forrest
Message:

change asserts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Samples/CbcHeuristicUser.cpp

    r133 r138  
    515515    }
    516516    if (bestChange+newSolutionValue<solutionValue) {
    517       // new solution
    518       memcpy(betterSolution,newSolution,numberColumns*sizeof(double));
    519       returnCode=1;
    520       solutionValue = newSolutionValue + bestChange;
    521       if (bestChange>1.0e-12)
    522         printf("Local search heuristic improved solution by %g\n",
    523              -bestChange);
    524517      // paranoid check
    525518      memset(rowActivity,0,numberRows*sizeof(double));
     
    536529        }
    537530      }
     531      int numberBad=0;
     532      double sumBad=0.0;
    538533      // check was approximately feasible
    539534      for (i=0;i<numberRows;i++) {
    540535        if(rowActivity[i]<rowLower[i]) {
    541           assert (rowActivity[i]>rowLower[i]-10.0*primalTolerance);
     536          sumBad += rowLower[i]-rowActivity[i];
     537          if (rowActivity[i]<rowLower[i]-10.0*primalTolerance)
     538            numberBad++;
    542539        } else if(rowActivity[i]>rowUpper[i]) {
    543           assert (rowActivity[i]<rowUpper[i]+10.0*primalTolerance);
     540          sumBad += rowUpper[i]-rowActivity[i];
     541          if (rowActivity[i]>rowUpper[i]+10.0*primalTolerance)
     542            numberBad++;
    544543        }
    545544      }
    546       for (i=0;i<numberIntegers;i++) {
    547         int iColumn = integerVariable[i];
    548         const CbcObject * object = model_->object(i);
    549         const CbcSimpleInteger * integerObject =
    550           dynamic_cast<const  CbcSimpleInteger *> (object);
    551         // get original bounds
    552         double originalLower = integerObject->originalLowerBound();
    553         //double originalUpper = integerObject->originalUpperBound();
    554 
    555         double value=newSolution[iColumn];
    556         // if away from lower bound mark that fact
    557         if (value>originalLower) {
    558           used_[iColumn]=1;
    559         }
     545      if (!numberBad) {
     546        for (i=0;i<numberIntegers;i++) {
     547          int iColumn = integerVariable[i];
     548          const CbcObject * object = model_->object(i);
     549          const CbcSimpleInteger * integerObject =
     550            dynamic_cast<const  CbcSimpleInteger *> (object);
     551          // get original bounds
     552          double originalLower = integerObject->originalLowerBound();
     553          //double originalUpper = integerObject->originalUpperBound();
     554         
     555          double value=newSolution[iColumn];
     556          // if away from lower bound mark that fact
     557          if (value>originalLower) {
     558            used_[iColumn]=1;
     559          }
     560        }
     561        // new solution
     562        memcpy(betterSolution,newSolution,numberColumns*sizeof(double));
     563        returnCode=1;
     564        solutionValue = newSolutionValue + bestChange;
     565        if (bestChange>1.0e-12)
     566          printf("Local search heuristic improved solution by %g\n",
     567                 -bestChange);
     568      } else {
     569        // bad solution - should not happen so debug if see message
     570        printf("Local search got bad solution with %d infeasibilities summing to %g\n",
     571               numberBad,sumBad);
    560572      }
    561573    }
Note: See TracChangeset for help on using the changeset viewer.