Ignore:
Timestamp:
Jan 6, 2019 2:43:06 PM (4 months ago)
Author:
unxusr
Message:

formatting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Clp/src/AbcSimplexDual.cpp

    r2078 r2385  
    210210//#define FORCE_FOLLOW
    211211#ifdef FORCE_FOLLOW
    212 static FILE * fpFollow = NULL;
    213 static const char * forceFile = NULL;
     212static FILE *fpFollow = NULL;
     213static const char *forceFile = NULL;
    214214static int force_in = -1;
    215215static int force_out = -1;
     
    217217static int force_way_out = -1;
    218218static int force_iterations = 0;
    219 int force_argc=0;
    220 const char ** force_argv=NULL;
    221 #endif
    222 void
    223 AbcSimplexDual::startupSolve()
     219int force_argc = 0;
     220const char **force_argv = NULL;
     221#endif
     222void AbcSimplexDual::startupSolve()
    224223{
    225224#ifdef FORCE_FOLLOW
    226225  int ifld;
    227   for (ifld=1;ifld<force_argc;ifld++) {
    228     if (strstr(argv[ifld],".log")) {
    229       forceFile=argv[ifld];
     226  for (ifld = 1; ifld < force_argc; ifld++) {
     227    if (strstr(argv[ifld], ".log")) {
     228      forceFile = argv[ifld];
    230229      break;
    231230    }
     
    233232  if (!fpFollow && strlen(forceFile)) {
    234233    fpFollow = fopen(forceFile, "r");
    235     assert (fpFollow);
     234    assert(fpFollow);
    236235  }
    237236  if (fpFollow) {
    238     int numberRead= atoi(argv[ifld+1]);
    239     force_iterations=atoi(argv[ifld+1]);
    240     printf("skipping %d iterations and then doing %d\n",numberRead,force_iterations);
    241     for (int iteration=0;iteration<numberRead;iteration++) {
     237    int numberRead = atoi(argv[ifld + 1]);
     238    force_iterations = atoi(argv[ifld + 1]);
     239    printf("skipping %d iterations and then doing %d\n", numberRead, force_iterations);
     240    for (int iteration = 0; iteration < numberRead; iteration++) {
    242241      // read to next Clp0102
    243242      char temp[300];
    244243      while (fgets(temp, 250, fpFollow)) {
    245         if (!strncmp(temp, "dirOut", 6))
    246           break;
    247       }
    248       sscanf(temp+7 , "%d%*s%d%*s%*s%d",
    249              &force_way_out, &force_way_in);
     244        if (!strncmp(temp, "dirOut", 6))
     245          break;
     246      }
     247      sscanf(temp + 7, "%d%*s%d%*s%*s%d",
     248        &force_way_out, &force_way_in);
    250249      fgets(temp, 250, fpFollow);
    251250      char cin, cout;
    252251      int whichIteration;
    253       sscanf(temp , "%d%*f%*s%*c%c%d%*s%*c%c%d",
    254              &whichIteration, &cin, &force_in, &cout, &force_out);
    255       assert (whichIterations==iteration+1);
     252      sscanf(temp, "%d%*f%*s%*c%c%d%*s%*c%c%d",
     253        &whichIteration, &cin, &force_in, &cout, &force_out);
     254      assert(whichIterations == iteration + 1);
    256255      if (cin == 'C')
    257         force_in += numberColumns_;
     256        force_in += numberColumns_;
    258257      if (cout == 'C')
    259         force_out += numberColumns_;
     258        force_out += numberColumns_;
    260259      printf("Iteration %d will force %d out (way %d) and %d in (way %d)\n",
    261              whichIteration, force_out, force_way_out,force_in,force_way_in);
    262       assert (getInternalStatus(force_out)==basic);
    263       assert (getInternalStatus(force_in)!=basic);
    264       setInternalStatus(force_in,basic);
    265       if (force_way_out==-1)
    266         setInternalStatus(force_out,atUpperBound);
     260        whichIteration, force_out, force_way_out, force_in, force_way_in);
     261      assert(getInternalStatus(force_out) == basic);
     262      assert(getInternalStatus(force_in) != basic);
     263      setInternalStatus(force_in, basic);
     264      if (force_way_out == -1)
     265        setInternalStatus(force_out, atUpperBound);
    267266      else
    268         setInternalStatus(force_out,atLowerBound);
     267        setInternalStatus(force_out, atLowerBound);
    269268    }
    270269    // clean up
    271     int numberBasic=0;
    272     for (int i=0;i<numberTotal_;i++) {
    273       if (getInternalStatus(i)==basic) {
    274         abcPivotVariable_[numberBasic++]=i;
    275       } else if (getInternalStatus(i)==atLowerBound) {
    276         if (abcLower_[i]<-1.0e30) {
    277           abcLower_[i]=abcUpper_[i]-dualBound_;
    278           setFakeLower(i);
    279         }
    280       } else if (getInternalStatus(i)==atUpperBound) {
    281         if (abcUpper_[i]>1.0e30) {
    282           abcUpper_[i]=abcLower_[i]+dualBound_;
    283           setFakeUpper(i);
    284         }
    285       }
    286     }
    287     assert (numberBasic==numberRows_);
     270    int numberBasic = 0;
     271    for (int i = 0; i < numberTotal_; i++) {
     272      if (getInternalStatus(i) == basic) {
     273        abcPivotVariable_[numberBasic++] = i;
     274      } else if (getInternalStatus(i) == atLowerBound) {
     275        if (abcLower_[i] < -1.0e30) {
     276          abcLower_[i] = abcUpper_[i] - dualBound_;
     277          setFakeLower(i);
     278        }
     279      } else if (getInternalStatus(i) == atUpperBound) {
     280        if (abcUpper_[i] > 1.0e30) {
     281          abcUpper_[i] = abcLower_[i] + dualBound_;
     282          setFakeUpper(i);
     283        }
     284      }
     285    }
     286    assert(numberBasic == numberRows_);
    288287  }
    289288#endif
     
    298297  statusOfProblemInDual(0);
    299298}
    300 void
    301 AbcSimplexDual::finishSolve()
     299void AbcSimplexDual::finishSolve()
    302300{
    303   assert (problemStatus_ || !sumPrimalInfeasibilities_);
     301  assert(problemStatus_ || !sumPrimalInfeasibilities_);
    304302}
    305 void
    306 AbcSimplexDual::gutsOfDual()
     303void AbcSimplexDual::gutsOfDual()
    307304{
    308305  double largestPrimalError = 0.0;
    309306  double largestDualError = 0.0;
    310307  lastCleaned_ = 0; // last time objective or bounds cleaned up
    311   numberDisasters_=0;
    312  
     308  numberDisasters_ = 0;
     309
    313310  // This says whether to restore things etc
    314311  //startupSolve();
     
    320317  // Say last objective infinite
    321318  //lastObjectiveValue_=-COIN_DBL_MAX;
    322   if ((stateOfProblem_&VALUES_PASS)!=0) {
     319  if ((stateOfProblem_ & VALUES_PASS) != 0) {
    323320    // modify costs so nonbasic dual feasible with fake
    324321    for (int iSequence = 0; iSequence < numberTotal_; iSequence++) {
    325       switch(getInternalStatus(iSequence)) {
     322      switch (getInternalStatus(iSequence)) {
    326323      case basic:
    327324      case AbcSimplex::isFixed:
    328         break;
     325        break;
    329326      case isFree:
    330327      case superBasic:
    331         //abcCost_[iSequence]-=djSaved_[iSequence];
    332         //abcDj_[iSequence]-=djSaved_[iSequence];
    333         djSaved_[iSequence]=0.0;
    334         break;
     328        //abcCost_[iSequence]-=djSaved_[iSequence];
     329        //abcDj_[iSequence]-=djSaved_[iSequence];
     330        djSaved_[iSequence] = 0.0;
     331        break;
    335332      case atLowerBound:
    336         if (djSaved_[iSequence]<0.0) {
    337           //abcCost_[iSequence]-=djSaved_[iSequence];
    338           //abcDj_[iSequence]-=djSaved_[iSequence];
    339           djSaved_[iSequence]=0.0;
    340         }
    341         break;
     333        if (djSaved_[iSequence] < 0.0) {
     334          //abcCost_[iSequence]-=djSaved_[iSequence];
     335          //abcDj_[iSequence]-=djSaved_[iSequence];
     336          djSaved_[iSequence] = 0.0;
     337        }
     338        break;
    342339      case atUpperBound:
    343         if (djSaved_[iSequence]>0.0) {
    344           //abcCost_[iSequence]-=djSaved_[iSequence];
    345           //abcDj_[iSequence]-=djSaved_[iSequence];
    346           djSaved_[iSequence]=0.0;
    347         }
    348         break;
     340        if (djSaved_[iSequence] > 0.0) {
     341          //abcCost_[iSequence]-=djSaved_[iSequence];
     342          //abcDj_[iSequence]-=djSaved_[iSequence];
     343          djSaved_[iSequence] = 0.0;
     344        }
     345        break;
    349346      }
    350347    }
     
    361358    -4 - looks infeasible
    362359  */
    363   int factorizationType=1;
    364   double pivotTolerance=abcFactorization_->pivotTolerance();
     360  int factorizationType = 1;
     361  double pivotTolerance = abcFactorization_->pivotTolerance();
    365362  while (problemStatus_ < 0) {
    366363    // If getting nowhere - return
    367364    double limit = numberRows_ + numberColumns_;
    368     limit = 10000.0 +2000.0 * limit;
    369 #if ABC_NORMAL_DEBUG>0
     365    limit = 10000.0 + 2000.0 * limit;
     366#if ABC_NORMAL_DEBUG > 0
    370367    if (numberIterations_ > limit) {
    371368      printf("Set flag so ClpSimplexDual done\n");
     
    378375      disaster = true;
    379376    }
    380     if (numberIterations_>baseIteration_) {
     377    if (numberIterations_ > baseIteration_) {
    381378      // may factorize, checks if problem finished
    382379      statusOfProblemInDual(factorizationType);
    383       factorizationType=1;
     380      factorizationType = 1;
    384381      largestPrimalError = CoinMax(largestPrimalError, largestPrimalError_);
    385382      largestDualError = CoinMax(largestDualError, largestDualError_);
    386383      if (disaster)
    387         problemStatus_ = 3;
    388     }
    389     int saveNumberIterations=numberIterations_;
     384        problemStatus_ = 3;
     385    }
     386    int saveNumberIterations = numberIterations_;
    390387    // exit if victory declared
    391388    if (problemStatus_ >= 0)
    392389      break;
    393    
     390
    394391    // test for maximum iterations
    395392    if (hitMaximumIterations()) {
     
    404401      break;
    405402    }
    406     if (!numberPrimalInfeasibilities_&&problemStatus_<0) {
    407 #if ABC_NORMAL_DEBUG>0
    408       printf("Primal feasible - sum dual %g - go to primal\n",sumDualInfeasibilities_);
    409 #endif
    410       problemStatus_=10;
     403    if (!numberPrimalInfeasibilities_ && problemStatus_ < 0) {
     404#if ABC_NORMAL_DEBUG > 0
     405      printf("Primal feasible - sum dual %g - go to primal\n", sumDualInfeasibilities_);
     406#endif
     407      problemStatus_ = 10;
    411408      break;
    412409    }
    413410    // Do iterations ? loop round
    414 #if PARTITION_ROW_COPY==1
     411#if PARTITION_ROW_COPY == 1
    415412    stateOfProblem_ |= NEED_BASIS_SORT;
    416413#endif
    417414    while (true) {
    418 #if PARTITION_ROW_COPY==1
    419       if ((stateOfProblem_&NEED_BASIS_SORT)!=0) {
    420         int iVector=getAvailableArray();
    421         abcMatrix_->sortUseful(usefulArray_[iVector]);
    422         setAvailableArray(iVector);
    423         stateOfProblem_ &= ~NEED_BASIS_SORT;
    424       }
    425 #endif
    426       problemStatus_=-1;
    427       if ((stateOfProblem_&VALUES_PASS)!=0) {
    428         assert (djSaved_-abcDj_==numberTotal_);
    429         abcDj_=djSaved_;
    430         djSaved_=NULL;
     415#if PARTITION_ROW_COPY == 1
     416      if ((stateOfProblem_ & NEED_BASIS_SORT) != 0) {
     417        int iVector = getAvailableArray();
     418        abcMatrix_->sortUseful(usefulArray_[iVector]);
     419        setAvailableArray(iVector);
     420        stateOfProblem_ &= ~NEED_BASIS_SORT;
     421      }
     422#endif
     423      problemStatus_ = -1;
     424      if ((stateOfProblem_ & VALUES_PASS) != 0) {
     425        assert(djSaved_ - abcDj_ == numberTotal_);
     426        abcDj_ = djSaved_;
     427        djSaved_ = NULL;
    431428      }
    432429#if ABC_PARALLEL
    433       if (parallelMode_==0) {
    434 #endif
    435         whileIteratingSerial();
     430      if (parallelMode_ == 0) {
     431#endif
     432        whileIteratingSerial();
    436433#if ABC_PARALLEL
    437434      } else {
    438 #if ABC_PARALLEL==1
    439         whileIteratingThread();
     435#if ABC_PARALLEL == 1
     436        whileIteratingThread();
    440437#else
    441         whileIteratingCilk();
    442 #endif
    443       }
    444 #endif
    445       if ((stateOfProblem_&VALUES_PASS)!=0) {
    446         djSaved_=abcDj_;
    447         abcDj_=djSaved_-numberTotal_;
    448       }
    449       if (pivotRow_!=-100) {
    450         if (numberIterations_>saveNumberIterations||problemStatus_>=0) {
    451           if (problemStatus_==10&&abcFactorization_->pivots()&&numberTimesOptimal_<3) {
    452             factorizationType=5;
    453             problemStatus_=-4;
    454             if (!numberPrimalInfeasibilities_)
    455               factorizationType=9;
    456           } else if (problemStatus_==-2) {
    457             factorizationType=5;
    458           }
    459           break;
    460         } else if (abcFactorization_->pivots()||problemStatus_==-6||
    461                    pivotTolerance<abcFactorization_->pivotTolerance()) {
    462           factorizationType=5;
    463           if (pivotTolerance<abcFactorization_->pivotTolerance()) {
    464             pivotTolerance=abcFactorization_->pivotTolerance();
    465             if (!abcFactorization_->pivots())
    466               abcFactorization_->minimumPivotTolerance(CoinMin(0.25,1.05*abcFactorization_->minimumPivotTolerance()));
    467           }
    468           break;
    469         } else {
    470           bool tryFake=numberAtFakeBound()>0&&currentDualBound_<1.0e17;
    471           if (problemStatus_==-5||tryFake) {
    472             if (numberTimesOptimal_>10)
    473               problemStatus_=4;
    474             numberTimesOptimal_++;
    475             int numberChanged=-1;
    476             if (numberFlagged_) {
    477               numberFlagged_=0;
    478               for (int iRow = 0; iRow < numberRows_; iRow++) {
    479                 int iPivot = abcPivotVariable_[iRow];
    480                 if (flagged(iPivot)) {
    481                   clearFlagged(iPivot);
    482                 }
    483               }
    484               numberChanged=0;
    485             } else if (tryFake) {
    486               double dummyChange;
    487               numberChanged = changeBounds(0,dummyChange);
    488               if (numberChanged>0) {
    489                 handler_->message(CLP_DUAL_ORIGINAL, messages_)
    490                   << CoinMessageEol;
    491                 bounceTolerances(3 /*(numberChanged>0) ? 3 : 1*/);
    492                 // temp
    493 #if ABC_NORMAL_DEBUG>0
    494                 //printf("should not need to break out of loop\n");
    495 #endif
    496                 abcProgress_.reset();
    497                 break;
    498               } else if (numberChanged<-1) {
    499                 // some flipped
    500                 bounceTolerances(3);
    501                 abcProgress_.reset();
    502               }
    503             } else if (numberChanged<0) {
    504               // what now
    505               printf("No iterations since last inverts A - nothing done - think\n");
    506               abort();
    507             }
    508           } else if (problemStatus_!=-4) {
    509             // what now
    510             printf("No iterations since last inverts B - nothing done - think\n");
    511             abort();
    512           }
    513         }
     438        whileIteratingCilk();
     439#endif
     440      }
     441#endif
     442      if ((stateOfProblem_ & VALUES_PASS) != 0) {
     443        djSaved_ = abcDj_;
     444        abcDj_ = djSaved_ - numberTotal_;
     445      }
     446      if (pivotRow_ != -100) {
     447        if (numberIterations_ > saveNumberIterations || problemStatus_ >= 0) {
     448          if (problemStatus_ == 10 && abcFactorization_->pivots() && numberTimesOptimal_ < 3) {
     449            factorizationType = 5;
     450            problemStatus_ = -4;
     451            if (!numberPrimalInfeasibilities_)
     452              factorizationType = 9;
     453          } else if (problemStatus_ == -2) {
     454            factorizationType = 5;
     455          }
     456          break;
     457        } else if (abcFactorization_->pivots() || problemStatus_ == -6 || pivotTolerance < abcFactorization_->pivotTolerance()) {
     458          factorizationType = 5;
     459          if (pivotTolerance < abcFactorization_->pivotTolerance()) {
     460            pivotTolerance = abcFactorization_->pivotTolerance();
     461            if (!abcFactorization_->pivots())
     462              abcFactorization_->minimumPivotTolerance(CoinMin(0.25, 1.05 * abcFactorization_->minimumPivotTolerance()));
     463          }
     464          break;
     465        } else {
     466          bool tryFake = numberAtFakeBound() > 0 && currentDualBound_ < 1.0e17;
     467          if (problemStatus_ == -5 || tryFake) {
     468            if (numberTimesOptimal_ > 10)
     469              problemStatus_ = 4;
     470            numberTimesOptimal_++;
     471            int numberChanged = -1;
     472            if (numberFlagged_) {
     473              numberFlagged_ = 0;
     474              for (int iRow = 0; iRow < numberRows_; iRow++) {
     475                int iPivot = abcPivotVariable_[iRow];
     476                if (flagged(iPivot)) {
     477                  clearFlagged(iPivot);
     478                }
     479              }
     480              numberChanged = 0;
     481            } else if (tryFake) {
     482              double dummyChange;
     483              numberChanged = changeBounds(0, dummyChange);
     484              if (numberChanged > 0) {
     485                handler_->message(CLP_DUAL_ORIGINAL, messages_)
     486                  << CoinMessageEol;
     487                bounceTolerances(3 /*(numberChanged>0) ? 3 : 1*/);
     488                // temp
     489#if ABC_NORMAL_DEBUG > 0
     490                //printf("should not need to break out of loop\n");
     491#endif
     492                abcProgress_.reset();
     493                break;
     494              } else if (numberChanged < -1) {
     495                // some flipped
     496                bounceTolerances(3);
     497                abcProgress_.reset();
     498              }
     499            } else if (numberChanged < 0) {
     500              // what now
     501              printf("No iterations since last inverts A - nothing done - think\n");
     502              abort();
     503            }
     504          } else if (problemStatus_ != -4) {
     505            // what now
     506            printf("No iterations since last inverts B - nothing done - think\n");
     507            abort();
     508          }
     509        }
    514510      } else {
    515         // end of values pass
    516         // we need to tell statusOf.. to restore costs etc
    517         // and take off flag
    518         bounceTolerances(2);
    519         assert (!solution_);
    520         delete [] solution_;
    521         solution_=NULL;
    522         gutsOfSolution(3);
    523         makeNonFreeVariablesDualFeasible();
    524         stateOfProblem_ &= ~VALUES_PASS;
    525         problemStatus_=-2;
    526         factorizationType=5;
    527         break;
    528       }
    529     }
    530     if (problemStatus_ == 1 && (progressFlag_&8) != 0 &&
    531         fabs(rawObjectiveValue_) > 1.0e10 ) {
    532 #if ABC_NORMAL_DEBUG>0
     511        // end of values pass
     512        // we need to tell statusOf.. to restore costs etc
     513        // and take off flag
     514        bounceTolerances(2);
     515        assert(!solution_);
     516        delete[] solution_;
     517        solution_ = NULL;
     518        gutsOfSolution(3);
     519        makeNonFreeVariablesDualFeasible();
     520        stateOfProblem_ &= ~VALUES_PASS;
     521        problemStatus_ = -2;
     522        factorizationType = 5;
     523        break;
     524      }
     525    }
     526    if (problemStatus_ == 1 && (progressFlag_ & 8) != 0 && fabs(rawObjectiveValue_) > 1.0e10) {
     527#if ABC_NORMAL_DEBUG > 0
    533528      printf("fix looks infeasible when has been\n"); // goto primal
    534529#endif
     
    545540}
    546541/// The duals are updated by the given arrays.
    547 static void updateDualsInDualBit2(CoinPartitionedVector & row,
    548                                   double * COIN_RESTRICT djs,
    549                                   double theta, int iBlock)
     542static void updateDualsInDualBit2(CoinPartitionedVector &row,
     543  double *COIN_RESTRICT djs,
     544  double theta, int iBlock)
    550545{
    551   int offset=row.startPartition(iBlock);
    552   double * COIN_RESTRICT work=row.denseVector()+offset;
    553   const int * COIN_RESTRICT which=row.getIndices()+offset;
    554   int number=row.getNumElements(iBlock);
     546  int offset = row.startPartition(iBlock);
     547  double *COIN_RESTRICT work = row.denseVector() + offset;
     548  const int *COIN_RESTRICT which = row.getIndices() + offset;
     549  int number = row.getNumElements(iBlock);
    555550  for (int i = 0; i < number; i++) {
    556551    int iSequence = which[i];
     
    560555    djs[iSequence] = value;
    561556  }
    562   row.setNumElementsPartition(iBlock,0);
     557  row.setNumElementsPartition(iBlock, 0);
    563558}
    564 static void updateDualsInDualBit(CoinPartitionedVector & row,
    565                                  double * djs,
    566                                 double theta, int numberBlocks)
     559static void updateDualsInDualBit(CoinPartitionedVector &row,
     560  double *djs,
     561  double theta, int numberBlocks)
    567562{
    568   for (int iBlock=1;iBlock<numberBlocks;iBlock++) {
    569     cilk_spawn updateDualsInDualBit2(row,djs,theta,iBlock);
    570   }
    571   updateDualsInDualBit2(row,djs,theta,0);
     563  for (int iBlock = 1; iBlock < numberBlocks; iBlock++) {
     564    cilk_spawn updateDualsInDualBit2(row, djs, theta, iBlock);
     565  }
     566  updateDualsInDualBit2(row, djs, theta, 0);
    572567  cilk_sync;
    573568}
    574569/// The duals are updated by the given arrays.
    575    
    576 void
    577 AbcSimplexDual::updateDualsInDual()
     570
     571void AbcSimplexDual::updateDualsInDual()
    578572{
    579573  //dual->usefulArray(3)->compact();
    580   CoinPartitionedVector & array=usefulArray_[arrayForTableauRow_];
     574  CoinPartitionedVector &array = usefulArray_[arrayForTableauRow_];
    581575  //array.compact();
    582   int numberBlocks=array.getNumPartitions();
    583   int number=array.getNumElements();
    584   if(numberBlocks) {
    585     if (number>100) {
    586       updateDualsInDualBit(array,abcDj_,theta_,numberBlocks);
     576  int numberBlocks = array.getNumPartitions();
     577  int number = array.getNumElements();
     578  if (numberBlocks) {
     579    if (number > 100) {
     580      updateDualsInDualBit(array, abcDj_, theta_, numberBlocks);
    587581    } else {
    588       for (int iBlock=0;iBlock<numberBlocks;iBlock++) {
    589         updateDualsInDualBit2(array,abcDj_,theta_,iBlock);
     582      for (int iBlock = 0; iBlock < numberBlocks; iBlock++) {
     583        updateDualsInDualBit2(array, abcDj_, theta_, iBlock);
    590584      }
    591585    }
    592586    array.compact();
    593587  } else {
    594     double * COIN_RESTRICT work=array.denseVector();
    595     const int * COIN_RESTRICT which=array.getIndices();
    596     double * COIN_RESTRICT reducedCost=abcDj_;
    597 #pragma cilk grainsize=128
    598     cilk_for (int i = 0; i < number; i++) {
     588    double *COIN_RESTRICT work = array.denseVector();
     589    const int *COIN_RESTRICT which = array.getIndices();
     590    double *COIN_RESTRICT reducedCost = abcDj_;
     591#pragma cilk grainsize = 128
     592    cilk_for(int i = 0; i < number; i++)
     593    {
    599594      //for (int i = 0; i < number; i++) {
    600595      int iSequence = which[i];
     
    607602  }
    608603}
    609 int
    610 AbcSimplexDual::nextSuperBasic()
     604int AbcSimplexDual::nextSuperBasic()
    611605{
    612606  if (firstFree_ >= 0) {
     
    615609    int iColumn = firstFree_ + 1;
    616610#ifdef PAN
    617     if (fakeSuperBasic(firstFree_)<0) {
     611    if (fakeSuperBasic(firstFree_) < 0) {
    618612      // somehow cleaned up
    619       returnValue=-1;
     613      returnValue = -1;
    620614      for (; iColumn < numberTotal_; iColumn++) {
    621         if (getInternalStatus(iColumn) == isFree||
    622             getInternalStatus(iColumn) == superBasic) {
    623           if (fakeSuperBasic(iColumn)>=0) {
    624             if (fabs(abcDj_[iColumn]) > 1.0e2 * dualTolerance_)
    625               break;
    626           }
    627         }
    628       }
    629       if (iColumn<numberTotal_) {
    630         returnValue=iColumn;
    631         iColumn++;
     615        if (getInternalStatus(iColumn) == isFree || getInternalStatus(iColumn) == superBasic) {
     616          if (fakeSuperBasic(iColumn) >= 0) {
     617            if (fabs(abcDj_[iColumn]) > 1.0e2 * dualTolerance_)
     618              break;
     619          }
     620        }
     621      }
     622      if (iColumn < numberTotal_) {
     623        returnValue = iColumn;
     624        iColumn++;
    632625      }
    633626    }
    634627#endif
    635628    for (; iColumn < numberTotal_; iColumn++) {
    636       if (getInternalStatus(iColumn) == isFree||
    637           getInternalStatus(iColumn) == superBasic) {
     629      if (getInternalStatus(iColumn) == isFree || getInternalStatus(iColumn) == superBasic) {
    638630#ifdef PAN
    639         if (fakeSuperBasic(iColumn)>=0) {
    640 #endif
    641           if (fabs(abcDj_[iColumn]) > dualTolerance_)
    642             break;
     631        if (fakeSuperBasic(iColumn) >= 0) {
     632#endif
     633          if (fabs(abcDj_[iColumn]) > dualTolerance_)
     634            break;
    643635#ifdef PAN
    644         }
     636        }
    645637#endif
    646638      }
     
    658650  For easy problems we can just choose one of the first rows we look at
    659651*/
    660 void
    661 AbcSimplexDual::dualPivotRow()
     652void AbcSimplexDual::dualPivotRow()
    662653{
    663654  //int lastPivotRow=pivotRow_;
    664   pivotRow_=-1;
    665   const double * COIN_RESTRICT lowerBasic = lowerBasic_;
    666   const double * COIN_RESTRICT upperBasic = upperBasic_;
    667   const double * COIN_RESTRICT solutionBasic = solutionBasic_;
    668   const int * COIN_RESTRICT pivotVariable=abcPivotVariable_;
    669   freeSequenceIn_=-1;
    670   double worstValuesPass=0.0;
    671   if ((stateOfProblem_&VALUES_PASS)!=0) {
     655  pivotRow_ = -1;
     656  const double *COIN_RESTRICT lowerBasic = lowerBasic_;
     657  const double *COIN_RESTRICT upperBasic = upperBasic_;
     658  const double *COIN_RESTRICT solutionBasic = solutionBasic_;
     659  const int *COIN_RESTRICT pivotVariable = abcPivotVariable_;
     660  freeSequenceIn_ = -1;
     661  double worstValuesPass = 0.0;
     662  if ((stateOfProblem_ & VALUES_PASS) != 0) {
    672663    for (int iSequence = 0; iSequence < numberTotal_; iSequence++) {
    673       switch(getInternalStatus(iSequence)) {
     664      switch (getInternalStatus(iSequence)) {
    674665      case basic:
    675 #if ABC_NORMAL_DEBUG>0
    676         if (fabs(abcDj_[iSequence])>1.0e-6)
    677           printf("valuespass basic dj %d status %d dj %g\n",iSequence,
    678                  getInternalStatus(iSequence),abcDj_[iSequence]);
    679 #endif
    680         break;
     666#if ABC_NORMAL_DEBUG > 0
     667        if (fabs(abcDj_[iSequence]) > 1.0e-6)
     668          printf("valuespass basic dj %d status %d dj %g\n", iSequence,
     669            getInternalStatus(iSequence), abcDj_[iSequence]);
     670#endif
     671        break;
    681672      case AbcSimplex::isFixed:
    682         break;
     673        break;
    683674      case isFree:
    684675      case superBasic:
    685 #if ABC_NORMAL_DEBUG>0
    686         if (fabs(abcDj_[iSequence])>1.0e-6)
    687           printf("Bad valuespass dj %d status %d dj %g\n",iSequence,
    688                  getInternalStatus(iSequence),abcDj_[iSequence]);
    689 #endif
    690         break;
     676#if ABC_NORMAL_DEBUG > 0
     677        if (fabs(abcDj_[iSequence]) > 1.0e-6)
     678          printf("Bad valuespass dj %d status %d dj %g\n", iSequence,
     679            getInternalStatus(iSequence), abcDj_[iSequence]);
     680#endif
     681        break;
    691682      case atLowerBound:
    692 #if ABC_NORMAL_DEBUG>0
    693         if (abcDj_[iSequence]<-1.0e-6)
    694           printf("Bad valuespass dj %d status %d dj %g\n",iSequence,
    695                  getInternalStatus(iSequence),abcDj_[iSequence]);
    696 #endif
    697         break;
     683#if ABC_NORMAL_DEBUG > 0
     684        if (abcDj_[iSequence] < -1.0e-6)
     685          printf("Bad valuespass dj %d status %d dj %g\n", iSequence,
     686            getInternalStatus(iSequence), abcDj_[iSequence]);
     687#endif
     688        break;
    698689      case atUpperBound:
    699 #if ABC_NORMAL_DEBUG>0
    700         if (abcDj_[iSequence]>1.0e-6)
    701           printf("Bad valuespass dj %d status %d dj %g\n",iSequence,
    702                  getInternalStatus(iSequence),abcDj_[iSequence]);
    703 #endif
    704         break;
     690#if ABC_NORMAL_DEBUG > 0
     691        if (abcDj_[iSequence] > 1.0e-6)
     692          printf("Bad valuespass dj %d status %d dj %g\n", iSequence,
     693            getInternalStatus(iSequence), abcDj_[iSequence]);
     694#endif
     695        break;
    705696      }
    706697    }
    707698    // get worst basic dual - later do faster using steepest infeasibility array
    708699    // does not have to be worst - just bad
    709     int iWorst=-1;
    710     double worst=dualTolerance_;
    711     for (int i=0;i<numberRows_;i++) {
    712       int iSequence=abcPivotVariable_[i];
    713       if (fabs(abcDj_[iSequence])>worst) {
    714         iWorst=i;
    715         worst=fabs(abcDj_[iSequence]);
    716       }
    717     }
    718     if (iWorst>=0) {
    719       pivotRow_=iWorst;
    720       worstValuesPass=abcDj_[abcPivotVariable_[iWorst]];
     700    int iWorst = -1;
     701    double worst = dualTolerance_;
     702    for (int i = 0; i < numberRows_; i++) {
     703      int iSequence = abcPivotVariable_[i];
     704      if (fabs(abcDj_[iSequence]) > worst) {
     705        iWorst = i;
     706        worst = fabs(abcDj_[iSequence]);
     707      }
     708    }
     709    if (iWorst >= 0) {
     710      pivotRow_ = iWorst;
     711      worstValuesPass = abcDj_[abcPivotVariable_[iWorst]];
    721712    } else {
    722713      // factorize and clean up costs
    723       pivotRow_=-100;
     714      pivotRow_ = -100;
    724715      return;
    725716    }
    726717  }
    727   if (false&&numberFreeNonBasic_>abcFactorization_->maximumPivots()) {
    728     lastFirstFree_=-1;
    729     firstFree_=-1;
    730   }
    731   if (firstFree_>=0) {
     718  if (false && numberFreeNonBasic_ > abcFactorization_->maximumPivots()) {
     719    lastFirstFree_ = -1;
     720    firstFree_ = -1;
     721  }
     722  if (firstFree_ >= 0) {
    732723    // free
    733724    int nextFree = nextSuperBasic();
    734     if (nextFree>=0) {
    735       freeSequenceIn_=nextFree;
     725    if (nextFree >= 0) {
     726      freeSequenceIn_ = nextFree;
    736727      // **** should skip price (and maybe weights update)
    737728      // unpack vector and find a good pivot
    738729      unpack(usefulArray_[arrayForBtran_], nextFree);
    739730      abcFactorization_->updateColumn(usefulArray_[arrayForBtran_]);
    740      
    741       double *  COIN_RESTRICT work = usefulArray_[arrayForBtran_].denseVector();
     731
     732      double *COIN_RESTRICT work = usefulArray_[arrayForBtran_].denseVector();
    742733      int number = usefulArray_[arrayForBtran_].getNumElements();
    743       int *  COIN_RESTRICT which = usefulArray_[arrayForBtran_].getIndices();
     734      int *COIN_RESTRICT which = usefulArray_[arrayForBtran_].getIndices();
    744735      double bestFeasibleAlpha = 0.0;
    745736      int bestFeasibleRow = -1;
     
    747738      int bestInfeasibleRow = -1;
    748739      // Go for big infeasibilities unless big changes
    749       double maxInfeas = (fabs(dualOut_)>1.0e3) ? 0.001 : 1.0e6;
     740      double maxInfeas = (fabs(dualOut_) > 1.0e3) ? 0.001 : 1.0e6;
    750741      for (int i = 0; i < number; i++) {
    751         int iRow = which[i];
    752         double alpha = fabs(work[iRow]);
    753         if (alpha > 1.0e-3) {
    754           double value = solutionBasic[iRow];
    755           double lower = lowerBasic[iRow];
    756           double upper = upperBasic[iRow];
    757           double infeasibility = 0.0;
    758           if (value > upper)
    759             infeasibility = value - upper;
    760           else if (value < lower)
    761             infeasibility = lower - value;
    762           infeasibility=CoinMin(maxInfeas,infeasibility);
    763           if (infeasibility * alpha > bestInfeasibleAlpha && alpha > 1.0e-1) {
    764             if (!flagged(pivotVariable[iRow])) {
    765               bestInfeasibleAlpha = infeasibility * alpha;
    766               bestInfeasibleRow = iRow;
    767             }
    768           }
    769           if (alpha > bestFeasibleAlpha && (lower > -1.0e20 || upper < 1.0e20)) {
    770             bestFeasibleAlpha = alpha;
    771             bestFeasibleRow = iRow;
    772           }
    773         }
     742        int iRow = which[i];
     743        double alpha = fabs(work[iRow]);
     744        if (alpha > 1.0e-3) {
     745          double value = solutionBasic[iRow];
     746          double lower = lowerBasic[iRow];
     747          double upper = upperBasic[iRow];
     748          double infeasibility = 0.0;
     749          if (value > upper)
     750            infeasibility = value - upper;
     751          else if (value < lower)
     752            infeasibility = lower - value;
     753          infeasibility = CoinMin(maxInfeas, infeasibility);
     754          if (infeasibility * alpha > bestInfeasibleAlpha && alpha > 1.0e-1) {
     755            if (!flagged(pivotVariable[iRow])) {
     756              bestInfeasibleAlpha = infeasibility * alpha;
     757              bestInfeasibleRow = iRow;
     758            }
     759          }
     760          if (alpha > bestFeasibleAlpha && (lower > -1.0e20 || upper < 1.0e20)) {
     761            bestFeasibleAlpha = alpha;
     762            bestFeasibleRow = iRow;
     763          }
     764        }
    774765      }
    775766      if (bestInfeasibleRow >= 0)
    776         pivotRow_ = bestInfeasibleRow;
     767        pivotRow_ = bestInfeasibleRow;
    777768      else if (bestFeasibleAlpha > 1.0e-2)
    778         pivotRow_ = bestFeasibleRow;
     769        pivotRow_ = bestFeasibleRow;
    779770      usefulArray_[arrayForBtran_].clear();
    780       if (pivotRow_<0) {
    781         // no good
    782         freeSequenceIn_=-1;
    783         if (!abcFactorization_->pivots()) {
    784           lastFirstFree_=-1;
    785           firstFree_=-1;
    786         }
    787       }
    788     }
    789   }
    790   if (pivotRow_<0) {
     771      if (pivotRow_ < 0) {
     772        // no good
     773        freeSequenceIn_ = -1;
     774        if (!abcFactorization_->pivots()) {
     775          lastFirstFree_ = -1;
     776          firstFree_ = -1;
     777        }
     778      }
     779    }
     780  }
     781  if (pivotRow_ < 0) {
    791782    // put back so can test
    792783    //pivotRow_=lastPivotRow;
    793784    // get pivot row using whichever method it is
    794785    pivotRow_ = abcDualRowPivot_->pivotRow();
    795   } 
    796  
     786  }
     787
    797788  if (pivotRow_ >= 0) {
    798789    sequenceOut_ = pivotVariable[pivotRow_];
     
    811802      // odd (could be free) - it's feasible - go to nearest
    812803      if (valueOut_ - lowerOut_ < upperOut_ - valueOut_) {
    813         directionOut_ = 1;
    814         dualOut_ = lowerOut_ - valueOut_;
     804        directionOut_ = 1;
     805        dualOut_ = lowerOut_ - valueOut_;
    815806      } else {
    816         directionOut_ = -1;
    817         dualOut_ = valueOut_ - upperOut_;
     807        directionOut_ = -1;
     808        dualOut_ = valueOut_ - upperOut_;
    818809      }
    819810    }
     
    825816      // could try crashing in variables away from bounds and with near zero djs
    826817      // pivot to take out bad slack and increase objective
    827       double fakeValueOut=solution_[sequenceOut_];
     818      double fakeValueOut = solution_[sequenceOut_];
    828819      dualOut_ = 1.0e-10;
    829       if (upperOut_>lowerOut_||
    830           fabs(fakeValueOut-upperOut_)<100.0*primalTolerance_) {
    831         if (abcDj_[sequenceOut_] > 0.0) {
    832           directionOut_ = 1;
    833         } else {
    834           directionOut_ = -1;
    835         }
     820      if (upperOut_ > lowerOut_ || fabs(fakeValueOut - upperOut_) < 100.0 * primalTolerance_) {
     821        if (abcDj_[sequenceOut_] > 0.0) {
     822          directionOut_ = 1;
     823        } else {
     824          directionOut_ = -1;
     825        }
    836826      } else {
    837         // foolishly trust primal solution
    838         if (fakeValueOut > upperOut_) {
    839           directionOut_ = -1;
    840         } else {
    841           directionOut_ = 1;
    842         }
     827        // foolishly trust primal solution
     828        if (fakeValueOut > upperOut_) {
     829          directionOut_ = -1;
     830        } else {
     831          directionOut_ = 1;
     832        }
    843833      }
    844834#if 1
    845835      // make sure plausible but only when fake primals stored
    846836      if (directionOut_ < 0 && fabs(fakeValueOut - upperOut_) > dualBound_ + primalTolerance_) {
    847         if (fabs(fakeValueOut - upperOut_) > fabs(fakeValueOut - lowerOut_))
    848           directionOut_ = 1;
     837        if (fabs(fakeValueOut - upperOut_) > fabs(fakeValueOut - lowerOut_))
     838          directionOut_ = 1;
    849839      } else if (directionOut_ > 0 && fabs(fakeValueOut - lowerOut_) > dualBound_ + primalTolerance_) {
    850         if (fabs(fakeValueOut - upperOut_) < fabs(fakeValueOut - lowerOut_))
    851           directionOut_ = -1;
    852       }
    853 #endif
    854     }
    855 #if ABC_NORMAL_DEBUG>3
     840        if (fabs(fakeValueOut - upperOut_) < fabs(fakeValueOut - lowerOut_))
     841          directionOut_ = -1;
     842      }
     843#endif
     844    }
     845#if ABC_NORMAL_DEBUG > 3
    856846    assert(dualOut_ >= 0.0);
    857847#endif
    858848  } else {
    859     sequenceOut_=-1;
    860   }
    861   alpha_=0.0;
    862   upperTheta_=COIN_DBL_MAX;
    863   return ;
     849    sequenceOut_ = -1;
     850  }
     851  alpha_ = 0.0;
     852  upperTheta_ = COIN_DBL_MAX;
     853  return;
    864854}
    865855// Checks if any fake bounds active - if so returns number and modifies
     
    871861// initialize is 0 or 3
    872862// and cost of change vector
    873 int
    874 AbcSimplexDual::changeBounds(int initialize,
    875                              double & changeCost)
     863int AbcSimplexDual::changeBounds(int initialize,
     864  double &changeCost)
    876865{
    877   assert (initialize==0||initialize==1||initialize==3||initialize==4);
     866  assert(initialize == 0 || initialize == 1 || initialize == 3 || initialize == 4);
    878867  numberFake_ = 0;
    879   double *  COIN_RESTRICT abcLower = abcLower_;
    880   double *  COIN_RESTRICT abcUpper = abcUpper_;
    881   double *  COIN_RESTRICT abcSolution = abcSolution_;
    882   double *  COIN_RESTRICT abcCost = abcCost_;
     868  double *COIN_RESTRICT abcLower = abcLower_;
     869  double *COIN_RESTRICT abcUpper = abcUpper_;
     870  double *COIN_RESTRICT abcSolution = abcSolution_;
     871  double *COIN_RESTRICT abcCost = abcCost_;
    883872  if (!initialize) {
    884873    int numberInfeasibilities;
     
    888877    changeCost = 0.0;
    889878    // put back original bounds and then check
    890     CoinAbcMemcpy(abcLower,lowerSaved_,numberTotal_);
    891     CoinAbcMemcpy(abcUpper,upperSaved_,numberTotal_);
    892     const double * COIN_RESTRICT dj = abcDj_;
     879    CoinAbcMemcpy(abcLower, lowerSaved_, numberTotal_);
     880    CoinAbcMemcpy(abcUpper, upperSaved_, numberTotal_);
     881    const double *COIN_RESTRICT dj = abcDj_;
    893882    int iSequence;
    894883    // bounds will get bigger - just look at ones at bounds
    895     int numberFlipped=0;
    896     double checkBound=1.000000000001*currentDualBound_;
     884    int numberFlipped = 0;
     885    double checkBound = 1.000000000001 * currentDualBound_;
    897886    for (iSequence = 0; iSequence < numberTotal_; iSequence++) {
    898887      double lowerValue = abcLower[iSequence];
     
    900889      double value = abcSolution[iSequence];
    901890      setFakeBound(iSequence, AbcSimplexDual::noFake);
    902       switch(getInternalStatus(iSequence)) {
    903        
     891      switch (getInternalStatus(iSequence)) {
     892
    904893      case basic:
    905894      case AbcSimplex::isFixed:
    906         break;
     895        break;
    907896      case isFree:
    908897      case superBasic:
    909         break;
     898        break;
    910899      case atUpperBound:
    911         if (fabs(value - upperValue) > primalTolerance_) {
    912           // can we flip
    913           if (value-lowerValue<checkBound&&dj[iSequence]>-currentDualTolerance_) {
    914             abcSolution_[iSequence]=lowerValue;
    915             setInternalStatus(iSequence,atLowerBound);
    916             numberFlipped++;
    917           } else {
    918             numberInfeasibilities++;
    919           }
    920         }
    921         break;
     900        if (fabs(value - upperValue) > primalTolerance_) {
     901          // can we flip
     902          if (value - lowerValue < checkBound && dj[iSequence] > -currentDualTolerance_) {
     903            abcSolution_[iSequence] = lowerValue;
     904            setInternalStatus(iSequence, atLowerBound);
     905            numberFlipped++;
     906          } else {
     907            numberInfeasibilities++;
     908          }
     909        }
     910        break;
    922911      case atLowerBound:
    923         if (fabs(value - lowerValue) > primalTolerance_) {
    924           // can we flip
    925           if (upperValue-value<checkBound&&dj[iSequence]<currentDualTolerance_) {
    926             abcSolution_[iSequence]=upperValue;
    927             setInternalStatus(iSequence,atUpperBound);
    928             numberFlipped++;
    929           } else {
    930             numberInfeasibilities++;
    931           }
    932         }
    933         break;
     912        if (fabs(value - lowerValue) > primalTolerance_) {
     913          // can we flip
     914          if (upperValue - value < checkBound && dj[iSequence] < currentDualTolerance_) {
     915            abcSolution_[iSequence] = upperValue;
     916            setInternalStatus(iSequence, atUpperBound);
     917            numberFlipped++;
     918          } else {
     919            numberInfeasibilities++;
     920          }
     921        }
     922        break;
    934923      }
    935924    }
     
    937926    if (numberInfeasibilities) {
    938927      handler_->message(CLP_DUAL_CHECKB, messages_)
    939         << newBound
    940         << CoinMessageEol;
     928        << newBound
     929        << CoinMessageEol;
    941930      int iSequence;
    942931      for (iSequence = 0; iSequence < numberRows_ + numberColumns_; iSequence++) {
    943         double lowerValue = abcLower[iSequence];
    944         double upperValue = abcUpper[iSequence];
    945         double newLowerValue;
    946         double newUpperValue;
    947         Status status = getInternalStatus(iSequence);
    948         if (status == atUpperBound ||
    949             status == atLowerBound) {
    950           double value = abcSolution[iSequence];
    951           if (value - lowerValue <= upperValue - value) {
    952             newLowerValue = CoinMax(lowerValue, value - 0.666667 * newBound);
    953             newUpperValue = CoinMin(upperValue, newLowerValue + newBound);
    954           } else {
    955             newUpperValue = CoinMin(upperValue, value + 0.666667 * newBound);
    956             newLowerValue = CoinMax(lowerValue, newUpperValue - newBound);
    957           }
    958           abcLower[iSequence] = newLowerValue;
    959           abcUpper[iSequence] = newUpperValue;
    960           if (newLowerValue > lowerValue) {
    961             if (newUpperValue < upperValue) {
    962               setFakeBound(iSequence, AbcSimplexDual::bothFake);
     932        double lowerValue = abcLower[iSequence];
     933        double upperValue = abcUpper[iSequence];
     934        double newLowerValue;
     935        double newUpperValue;
     936        Status status = getInternalStatus(iSequence);
     937        if (status == atUpperBound || status == atLowerBound) {
     938          double value = abcSolution[iSequence];
     939          if (value - lowerValue <= upperValue - value) {
     940            newLowerValue = CoinMax(lowerValue, value - 0.666667 * newBound);
     941            newUpperValue = CoinMin(upperValue, newLowerValue + newBound);
     942          } else {
     943            newUpperValue = CoinMin(upperValue, value + 0.666667 * newBound);
     944            newLowerValue = CoinMax(lowerValue, newUpperValue - newBound);
     945          }
     946          abcLower[iSequence] = newLowerValue;
     947          abcUpper[iSequence] = newUpperValue;
     948          if (newLowerValue > lowerValue) {
     949            if (newUpperValue < upperValue) {
     950              setFakeBound(iSequence, AbcSimplexDual::bothFake);
    963951#ifdef CLP_INVESTIGATE
    964               abort(); // No idea what should happen here - I have never got here
    965 #endif
    966               numberFake_++;
    967             } else {
    968               setFakeBound(iSequence, AbcSimplexDual::lowerFake);
    969               assert (abcLower[iSequence]>lowerSaved_[iSequence]);
    970               assert (abcUpper[iSequence]==upperSaved_[iSequence]);
    971               numberFake_++;
    972             }
    973           } else {
    974             if (newUpperValue < upperValue) {
    975               setFakeBound(iSequence, AbcSimplexDual::upperFake);
    976               assert (abcLower[iSequence]==lowerSaved_[iSequence]);
    977               assert (abcUpper[iSequence]<upperSaved_[iSequence]);
    978               numberFake_++;
    979             }
    980           }
    981           if (status == atUpperBound)
    982             abcSolution[iSequence] = newUpperValue;
    983           else
    984             abcSolution[iSequence] = newLowerValue;
    985           double movement = abcSolution[iSequence] - value;
    986           changeCost += movement * abcCost[iSequence];
    987         }
     952              abort(); // No idea what should happen here - I have never got here
     953#endif
     954              numberFake_++;
     955            } else {
     956              setFakeBound(iSequence, AbcSimplexDual::lowerFake);
     957              assert(abcLower[iSequence] > lowerSaved_[iSequence]);
     958              assert(abcUpper[iSequence] == upperSaved_[iSequence]);
     959              numberFake_++;
     960            }
     961          } else {
     962            if (newUpperValue < upperValue) {
     963              setFakeBound(iSequence, AbcSimplexDual::upperFake);
     964              assert(abcLower[iSequence] == lowerSaved_[iSequence]);
     965              assert(abcUpper[iSequence] < upperSaved_[iSequence]);
     966              numberFake_++;
     967            }
     968          }
     969          if (status == atUpperBound)
     970            abcSolution[iSequence] = newUpperValue;
     971          else
     972            abcSolution[iSequence] = newLowerValue;
     973          double movement = abcSolution[iSequence] - value;
     974          changeCost += movement * abcCost[iSequence];
     975        }
    988976      }
    989977      currentDualBound_ = newBound;
    990 #if ABC_NORMAL_DEBUG>0
    991       printf("new dual bound %g\n",currentDualBound_);
     978#if ABC_NORMAL_DEBUG > 0
     979      printf("new dual bound %g\n", currentDualBound_);
    992980#endif
    993981    } else {
    994       numberInfeasibilities = -1-numberFlipped;
     982      numberInfeasibilities = -1 - numberFlipped;
    995983    }
    996984    return numberInfeasibilities;
     
    999987    if (initialize == 3) {
    1000988      for (iSequence = 0; iSequence < numberTotal_; iSequence++) {
    1001 #if ABC_NORMAL_DEBUG>1
    1002         int bad=-1;
    1003         if (getFakeBound(iSequence)==noFake) {
    1004           if (abcLower_[iSequence]!=lowerSaved_[iSequence]||
    1005               abcUpper_[iSequence]!=upperSaved_[iSequence])
    1006             bad=0;
    1007         } else if (getFakeBound(iSequence)==lowerFake) {
    1008           if (abcLower_[iSequence]==lowerSaved_[iSequence]||
    1009               abcUpper_[iSequence]!=upperSaved_[iSequence])
    1010             bad=1;
    1011         } else if (getFakeBound(iSequence)==upperFake) {
    1012           if (abcLower_[iSequence]!=lowerSaved_[iSequence]||
    1013               abcUpper_[iSequence]==upperSaved_[iSequence])
    1014             bad=2;
    1015         } else {
    1016           if (abcLower_[iSequence]==lowerSaved_[iSequence]||
    1017               abcUpper_[iSequence]==upperSaved_[iSequence])
    1018             bad=3;
    1019         }
    1020         if (bad>=0)
    1021           printf("%d status %d l %g,%g u %g,%g\n",iSequence,internalStatus_[iSequence],
    1022                  abcLower_[iSequence],lowerSaved_[iSequence],
    1023                  abcUpper_[iSequence],upperSaved_[iSequence]);
    1024 #endif
    1025         setFakeBound(iSequence, AbcSimplexDual::noFake);
    1026       }
    1027       CoinAbcMemcpy(abcLower_,lowerSaved_,numberTotal_);
    1028       CoinAbcMemcpy(abcUpper_,upperSaved_,numberTotal_);
     989#if ABC_NORMAL_DEBUG > 1
     990        int bad = -1;
     991        if (getFakeBound(iSequence) == noFake) {
     992          if (abcLower_[iSequence] != lowerSaved_[iSequence] || abcUpper_[iSequence] != upperSaved_[iSequence])
     993            bad = 0;
     994        } else if (getFakeBound(iSequence) == lowerFake) {
     995          if (abcLower_[iSequence] == lowerSaved_[iSequence] || abcUpper_[iSequence] != upperSaved_[iSequence])
     996            bad = 1;
     997        } else if (getFakeBound(iSequence) == upperFake) {
     998          if (abcLower_[iSequence] != lowerSaved_[iSequence] || abcUpper_[iSequence] == upperSaved_[iSequence])
     999            bad = 2;
     1000        } else {
     1001          if (abcLower_[iSequence] == lowerSaved_[iSequence] || abcUpper_[iSequence] == upperSaved_[iSequence])
     1002            bad = 3;
     1003        }
     1004        if (bad >= 0)
     1005          printf("%d status %d l %g,%g u %g,%g\n", iSequence, internalStatus_[iSequence],
     1006            abcLower_[iSequence], lowerSaved_[iSequence],
     1007            abcUpper_[iSequence], upperSaved_[iSequence]);
     1008#endif
     1009        setFakeBound(iSequence, AbcSimplexDual::noFake);
     1010      }
     1011      CoinAbcMemcpy(abcLower_, lowerSaved_, numberTotal_);
     1012      CoinAbcMemcpy(abcUpper_, upperSaved_, numberTotal_);
    10291013    }
    10301014    double testBound = /*0.999999 **/ currentDualBound_;
    10311015    for (iSequence = 0; iSequence < numberTotal_; iSequence++) {
    10321016      Status status = getInternalStatus(iSequence);
    1033       if (status == atUpperBound ||
    1034           status == atLowerBound) {
    1035         double lowerValue = abcLower[iSequence];
    1036         double upperValue = abcUpper[iSequence];
    1037         double value = abcSolution[iSequence];
    1038         if (lowerValue > -largeValue_ || upperValue < largeValue_) {
    1039           if (true || lowerValue - value > -0.5 * currentDualBound_ ||
    1040               upperValue - value < 0.5 * currentDualBound_) {
    1041             if (fabs(lowerValue - value) <= fabs(upperValue - value)) {
    1042               if (upperValue > lowerValue + testBound) {
    1043                 if (getFakeBound(iSequence) == AbcSimplexDual::noFake)
    1044                   numberFake_++;
    1045                 abcUpper[iSequence] = lowerValue + currentDualBound_;
    1046                 double difference = upperSaved_[iSequence]-abcUpper[iSequence];
    1047                 if (difference<1.0e-10*(1.0+fabs(upperSaved_[iSequence])+dualBound_))
    1048                   abcUpper[iSequence] = upperSaved_[iSequence];
    1049                 assert (abcUpper[iSequence]<=upperSaved_[iSequence]+1.0e-3*currentDualBound_);
    1050                 assert (abcLower[iSequence]>=lowerSaved_[iSequence]-1.0e-3*currentDualBound_);
    1051                 if (upperSaved_[iSequence]-abcUpper[iSequence]>
    1052                     abcLower[iSequence]-lowerSaved_[iSequence]) {
    1053                   setFakeBound(iSequence, AbcSimplexDual::upperFake);
    1054                   assert (abcLower[iSequence]==lowerSaved_[iSequence]);
    1055                   assert (abcUpper[iSequence]<upperSaved_[iSequence]);
    1056                 } else {
    1057                   setFakeBound(iSequence, AbcSimplexDual::lowerFake);
    1058                   assert (abcLower[iSequence]>lowerSaved_[iSequence]);
    1059                   assert (abcUpper[iSequence]==upperSaved_[iSequence]);
    1060                 }
    1061               }
    1062             } else {
    1063               if (lowerValue < upperValue - testBound) {
    1064                 if (getFakeBound(iSequence) == AbcSimplexDual::noFake)
    1065                   numberFake_++;
    1066                 abcLower[iSequence] = upperValue - currentDualBound_;
    1067                 double difference = abcLower[iSequence]-lowerSaved_[iSequence];
    1068                 if (difference<1.0e-10*(1.0+fabs(lowerSaved_[iSequence])+dualBound_))
    1069                   abcLower[iSequence] = lowerSaved_[iSequence];
    1070                 assert (abcUpper[iSequence]<=upperSaved_[iSequence]+1.0e-3*currentDualBound_);
    1071                 assert (abcLower[iSequence]>=lowerSaved_[iSequence]-1.0e-3*currentDualBound_);
    1072                 if (upperSaved_[iSequence]-abcUpper[iSequence]>
    1073                     abcLower[iSequence]-lowerSaved_[iSequence]) {
    1074                   setFakeBound(iSequence, AbcSimplexDual::upperFake);
    1075                   //assert (abcLower[iSequence]==lowerSaved_[iSequence]);
    1076                   abcLower[iSequence]=CoinMax(abcLower[iSequence],lowerSaved_[iSequence]);
    1077                   assert (abcUpper[iSequence]<upperSaved_[iSequence]);
    1078                 } else {
    1079                   setFakeBound(iSequence, AbcSimplexDual::lowerFake);
    1080                   assert (abcLower[iSequence]>lowerSaved_[iSequence]);
    1081                   //assert (abcUpper[iSequence]==upperSaved_[iSequence]);
    1082                   abcUpper[iSequence]=CoinMin(abcUpper[iSequence],upperSaved_[iSequence]);
    1083                 }
    1084               }
    1085             }
    1086           } else {
    1087             if (getFakeBound(iSequence) == AbcSimplexDual::noFake)
    1088               numberFake_++;
    1089             abcLower[iSequence] = -0.5 * currentDualBound_;
    1090             abcUpper[iSequence] = 0.5 * currentDualBound_;
    1091             setFakeBound(iSequence, AbcSimplexDual::bothFake);
    1092             abort();
    1093           }
    1094           if (status == atUpperBound)
    1095             abcSolution[iSequence] = abcUpper[iSequence];
    1096           else
    1097             abcSolution[iSequence] = abcLower[iSequence];
    1098         } else {
    1099           // set non basic free variables to fake bounds
    1100           // I don't think we should ever get here
    1101           CoinAssert(!("should not be here"));
    1102           abcLower[iSequence] = -0.5 * currentDualBound_;
    1103           abcUpper[iSequence] = 0.5 * currentDualBound_;
    1104           setFakeBound(iSequence, AbcSimplexDual::bothFake);
    1105           numberFake_++;
    1106           setInternalStatus(iSequence, atUpperBound);
    1107           abcSolution[iSequence] = 0.5 * currentDualBound_;
    1108         }
     1017      if (status == atUpperBound || status == atLowerBound) {
     1018        double lowerValue = abcLower[iSequence];
     1019        double upperValue = abcUpper[iSequence];
     1020        double value = abcSolution[iSequence];
     1021        if (lowerValue > -largeValue_ || upperValue < largeValue_) {
     1022          if (true || lowerValue - value > -0.5 * currentDualBound_ || upperValue - value < 0.5 * currentDualBound_) {
     1023            if (fabs(lowerValue - value) <= fabs(upperValue - value)) {
     1024              if (upperValue > lowerValue + testBound) {
     1025                if (getFakeBound(iSequence) == AbcSimplexDual::noFake)
     1026                  numberFake_++;
     1027                abcUpper[iSequence] = lowerValue + currentDualBound_;
     1028                double difference = upperSaved_[iSequence] - abcUpper[iSequence];
     1029                if (difference < 1.0e-10 * (1.0 + fabs(upperSaved_[iSequence]) + dualBound_))
     1030                  abcUpper[iSequence] = upperSaved_[iSequence];
     1031                assert(abcUpper[iSequence] <= upperSaved_[iSequence] + 1.0e-3 * currentDualBound_);
     1032                assert(abcLower[iSequence] >= lowerSaved_[iSequence] - 1.0e-3 * currentDualBound_);
     1033                if (upperSaved_[iSequence] - abcUpper[iSequence] > abcLower[iSequence] - lowerSaved_[iSequence]) {
     1034                  setFakeBound(iSequence, AbcSimplexDual::upperFake);
     1035                  assert(abcLower[iSequence] == lowerSaved_[iSequence]);
     1036                  assert(abcUpper[iSequence] < upperSaved_[iSequence]);
     1037                } else {
     1038                  setFakeBound(iSequence, AbcSimplexDual::lowerFake);
     1039                  assert(abcLower[iSequence] > lowerSaved_[iSequence]);
     1040                  assert(abcUpper[iSequence] == upperSaved_[iSequence]);
     1041                }
     1042              }
     1043            } else {
     1044              if (lowerValue < upperValue - testBound) {
     1045                if (getFakeBound(iSequence) == AbcSimplexDual::noFake)
     1046                  numberFake_++;
     1047                abcLower[iSequence] = upperValue - currentDualBound_;
     1048                double difference = abcLower[iSequence] - lowerSaved_[iSequence];
     1049                if (difference < 1.0e-10 * (1.0 + fabs(lowerSaved_[iSequence]) + dualBound_))
     1050                  abcLower[iSequence] = lowerSaved_[iSequence];
     1051                assert(abcUpper[iSequence] <= upperSaved_[iSequence] + 1.0e-3 * currentDualBound_);
     1052                assert(abcLower[iSequence] >= lowerSaved_[iSequence] - 1.0e-3 * currentDualBound_);
     1053                if (upperSaved_[iSequence] - abcUpper[iSequence] > abcLower[iSequence] - lowerSaved_[iSequence]) {
     1054                  setFakeBound(iSequence, AbcSimplexDual::upperFake);
     1055                  //assert (abcLower[iSequence]==lowerSaved_[iSequence]);
     1056                  abcLower[iSequence] = CoinMax(abcLower[iSequence], lowerSaved_[iSequence]);
     1057                  assert(abcUpper[iSequence] < upperSaved_[iSequence]);
     1058                } else {
     1059                  setFakeBound(iSequence, AbcSimplexDual::lowerFake);
     1060                  assert(abcLower[iSequence] > lowerSaved_[iSequence]);
     1061                  //assert (abcUpper[iSequence]==upperSaved_[iSequence]);
     1062                  abcUpper[iSequence] = CoinMin(abcUpper[iSequence], upperSaved_[iSequence]);
     1063                }
     1064              }
     1065            }
     1066          } else {
     1067            if (getFakeBound(iSequence) == AbcSimplexDual::noFake)
     1068              numberFake_++;
     1069            abcLower[iSequence] = -0.5 * currentDualBound_;
     1070            abcUpper[iSequence] = 0.5 * currentDualBound_;
     1071            setFakeBound(iSequence, AbcSimplexDual::bothFake);
     1072            abort();
     1073          }
     1074          if (status == atUpperBound)
     1075            abcSolution[iSequence] = abcUpper[iSequence];
     1076          else
     1077            abcSolution[iSequence] = abcLower[iSequence];
     1078        } else {
     1079          // set non basic free variables to fake bounds
     1080          // I don't think we should ever get here
     1081          CoinAssert(!("should not be here"));
     1082          abcLower[iSequence] = -0.5 * currentDualBound_;
     1083          abcUpper[iSequence] = 0.5 * currentDualBound_;
     1084          setFakeBound(iSequence, AbcSimplexDual::bothFake);
     1085          numberFake_++;
     1086          setInternalStatus(iSequence, atUpperBound);
     1087          abcSolution[iSequence] = 0.5 * currentDualBound_;
     1088        }
    11091089      } else if (status == basic) {
    1110         // make sure not at fake bound and bounds correct
    1111         setFakeBound(iSequence, AbcSimplexDual::noFake);
    1112         double gap = abcUpper[iSequence] - abcLower[iSequence];
    1113         if (gap > 0.5 * currentDualBound_ && gap < 2.0 * currentDualBound_) {
    1114           abcLower[iSequence] = lowerSaved_[iSequence];;
    1115           abcUpper[iSequence] = upperSaved_[iSequence];;
    1116         }
     1090        // make sure not at fake bound and bounds correct
     1091        setFakeBound(iSequence, AbcSimplexDual::noFake);
     1092        double gap = abcUpper[iSequence] - abcLower[iSequence];
     1093        if (gap > 0.5 * currentDualBound_ && gap < 2.0 * currentDualBound_) {
     1094          abcLower[iSequence] = lowerSaved_[iSequence];
     1095          ;
     1096          abcUpper[iSequence] = upperSaved_[iSequence];
     1097          ;
     1098        }
    11171099      }
    11181100    }
     
    11381120  Returns upper theta (infinity if no pivot) and may set sequenceIn_ if free
    11391121*/
    1140 void
    1141 AbcSimplexDual::dualColumn1(bool doAll)
     1122void AbcSimplexDual::dualColumn1(bool doAll)
    11421123{
    1143   const CoinIndexedVector & update = usefulArray_[arrayForBtran_];
    1144   CoinPartitionedVector & tableauRow = usefulArray_[arrayForTableauRow_];
    1145   CoinPartitionedVector & candidateList = usefulArray_[arrayForDualColumn_];
    1146   if ((stateOfProblem_&VALUES_PASS)==0)
    1147     upperTheta_=1.0e31;
     1124  const CoinIndexedVector &update = usefulArray_[arrayForBtran_];
     1125  CoinPartitionedVector &tableauRow = usefulArray_[arrayForTableauRow_];
     1126  CoinPartitionedVector &candidateList = usefulArray_[arrayForDualColumn_];
     1127  if ((stateOfProblem_ & VALUES_PASS) == 0)
     1128    upperTheta_ = 1.0e31;
    11481129  else
    1149     upperTheta_=fabs(abcDj_[sequenceOut_])-0.5*dualTolerance_;
    1150   assert (upperTheta_>0.0);
    1151   if (!doAll) 
    1152     upperTheta_ = abcMatrix_->dualColumn1(update,tableauRow,candidateList);
     1130    upperTheta_ = fabs(abcDj_[sequenceOut_]) - 0.5 * dualTolerance_;
     1131  assert(upperTheta_ > 0.0);
     1132  if (!doAll)
     1133    upperTheta_ = abcMatrix_->dualColumn1(update, tableauRow, candidateList);
    11531134  else
    11541135    upperTheta_ = dualColumn1B();
     
    11661147AbcSimplexDual::dualColumn1A()
    11671148{
    1168   const CoinIndexedVector & update = usefulArray_[arrayForBtran_];
    1169   CoinPartitionedVector & tableauRow = usefulArray_[arrayForTableauRow_];
    1170   CoinPartitionedVector & candidateList = usefulArray_[arrayForDualColumn_];
     1149  const CoinIndexedVector &update = usefulArray_[arrayForBtran_];
     1150  CoinPartitionedVector &tableauRow = usefulArray_[arrayForTableauRow_];
     1151  CoinPartitionedVector &candidateList = usefulArray_[arrayForDualColumn_];
    11711152  int numberRemaining = 0;
    11721153  double upperTheta = upperTheta_;
    11731154  // pivot elements
    1174   double *  COIN_RESTRICT arrayCandidate=candidateList.denseVector();
     1155  double *COIN_RESTRICT arrayCandidate = candidateList.denseVector();
    11751156  // indices
    1176   int *  COIN_RESTRICT indexCandidate = candidateList.getIndices();
    1177   const double *  COIN_RESTRICT abcDj = abcDj_;
     1157  int *COIN_RESTRICT indexCandidate = candidateList.getIndices();
     1158  const double *COIN_RESTRICT abcDj = abcDj_;
    11781159  //const double *  COIN_RESTRICT abcPerturbation = abcPerturbation_;
    1179   const unsigned char *  COIN_RESTRICT internalStatus = internalStatus_;
    1180   const double *  COIN_RESTRICT pi=update.denseVector();
    1181   const int *  COIN_RESTRICT piIndex = update.getIndices();
     1160  const unsigned char *COIN_RESTRICT internalStatus = internalStatus_;
     1161  const double *COIN_RESTRICT pi = update.denseVector();
     1162  const int *COIN_RESTRICT piIndex = update.getIndices();
    11821163  int number = update.getNumElements();
    1183   int *  COIN_RESTRICT index = tableauRow.getIndices();
    1184   double *  COIN_RESTRICT array = tableauRow.denseVector();
    1185   assert (!tableauRow.getNumElements());
    1186   int numberNonZero=0;
     1164  int *COIN_RESTRICT index = tableauRow.getIndices();
     1165  double *COIN_RESTRICT array = tableauRow.denseVector();
     1166  assert(!tableauRow.getNumElements());
     1167  int numberNonZero = 0;
    11871168  // do first pass to get possibles
    11881169  double bestPossible = 0.0;
     
    11901171  double tentativeTheta = 1.0e25; // try with this much smaller as guess
    11911172  double acceptablePivot = currentAcceptablePivot_;
    1192   double dualT=-currentDualTolerance_;
    1193   const double multiplier[] = { 1.0, -1.0};
     1173  double dualT = -currentDualTolerance_;
     1174  const double multiplier[] = { 1.0, -1.0 };
    11941175  if (ordinaryVariables_) {
    1195     for (int i=0;i<number;i++) {
    1196       int iRow=piIndex[i];
    1197       unsigned char type=internalStatus[iRow];
    1198       if ((type&4)==0) {
    1199         index[numberNonZero]=iRow;
    1200         double piValue=pi[iRow];
    1201         array[numberNonZero++]=piValue;
    1202         int iStatus = internalStatus[iRow] & 3;
    1203         double mult = multiplier[iStatus];
    1204         double alpha = piValue * mult;
    1205         double oldValue = abcDj[iRow] * mult;
    1206         double value = oldValue - tentativeTheta * alpha;
    1207         if (value < dualT) {
    1208           bestPossible = CoinMax(bestPossible, alpha);
    1209           value = oldValue - upperTheta * alpha;
    1210           if (value < dualT && alpha >= acceptablePivot) {
    1211             upperTheta = (oldValue - dualT) / alpha;
    1212           }
    1213           // add to list
    1214           arrayCandidate[numberRemaining] = alpha;
    1215           indexCandidate[numberRemaining++] = iRow;
    1216         }
     1176    for (int i = 0; i < number; i++) {
     1177      int iRow = piIndex[i];
     1178      unsigned char type = internalStatus[iRow];
     1179      if ((type & 4) == 0) {
     1180        index[numberNonZero] = iRow;
     1181        double piValue = pi[iRow];
     1182        array[numberNonZero++] = piValue;
     1183        int iStatus = internalStatus[iRow] & 3;
     1184        double mult = multiplier[iStatus];
     1185        double alpha = piValue * mult;
     1186        double oldValue = abcDj[iRow] * mult;
     1187        double value = oldValue - tentativeTheta * alpha;
     1188        if (value < dualT) {
     1189          bestPossible = CoinMax(bestPossible, alpha);
     1190          value = oldValue - upperTheta * alpha;
     1191          if (value < dualT && alpha >= acceptablePivot) {
     1192            upperTheta = (oldValue - dualT) / alpha;
     1193          }
     1194          // add to list
     1195          arrayCandidate[numberRemaining] = alpha;
     1196          indexCandidate[numberRemaining++] = iRow;
     1197        }
    12171198      }
    12181199    }
     
    12221203    alpha_ = 0.0;
    12231204    // We can also see if infeasible or pivoting on free
    1224     for (int i=0;i<number;i++) {
    1225       int iRow=piIndex[i];
    1226       unsigned char type=internalStatus[iRow];
    1227       double piValue=pi[iRow];
    1228       if ((type&4)==0) {
    1229         index[numberNonZero]=iRow;
    1230         array[numberNonZero++]=piValue;
    1231         int iStatus = internalStatus[iRow] & 3;
    1232         double mult = multiplier[iStatus];
    1233         double alpha = piValue * mult;
    1234         double oldValue = abcDj[iRow] * mult;
    1235         double value = oldValue - tentativeTheta * alpha;
    1236         if (value < dualT) {
    1237           bestPossible = CoinMax(bestPossible, alpha);
    1238           value = oldValue - upperTheta * alpha;
    1239           if (value < dualT && alpha >= acceptablePivot) {
    1240             upperTheta = (oldValue - dualT) / alpha;
    1241           }
    1242           // add to list
    1243           arrayCandidate[numberRemaining] = alpha;
    1244           indexCandidate[numberRemaining++] = iRow;
    1245         }
    1246       } else if ((type&7)<6) {
    1247         //} else if (getInternalStatus(iRow)==isFree||getInternalStatus(iRow)==superBasic) {
    1248         bool keep;
    1249         index[numberNonZero]=iRow;
    1250         array[numberNonZero++]=piValue;
    1251         bestPossible = CoinMax(bestPossible, fabs(piValue));
    1252         double oldValue = abcDj[iRow];
    1253         // If free has to be very large - should come in via dualRow
    1254         //if (getInternalStatus(iRow+addSequence)==isFree&&fabs(piValue)<1.0e-3)
    1255         //break;
    1256         if (oldValue > currentDualTolerance_) {
    1257           keep = true;
    1258         } else if (oldValue < -currentDualTolerance_) {
    1259           keep = true;
    1260         } else {
    1261           if (fabs(piValue) > CoinMax(10.0 * currentAcceptablePivot_, 1.0e-5)) {
    1262             keep = true;
    1263           } else {
    1264             keep = false;
    1265             badFree = CoinMax(badFree, fabs(piValue));
    1266           }
    1267         }
    1268         if (keep) {
    1269           // free - choose largest
    1270           if (fabs(piValue) > freePivot) {
    1271             freePivot = fabs(piValue);
    1272             sequenceIn_ = iRow;
    1273             theta_ = oldValue / piValue;
    1274             alpha_ = piValue;
    1275           }
    1276         }
     1205    for (int i = 0; i < number; i++) {
     1206      int iRow = piIndex[i];
     1207      unsigned char type = internalStatus[iRow];
     1208      double piValue = pi[iRow];
     1209      if ((type & 4) == 0) {
     1210        index[numberNonZero] = iRow;
     1211        array[numberNonZero++] = piValue;
     1212        int iStatus = internalStatus[iRow] & 3;
     1213        double mult = multiplier[iStatus];
     1214        double alpha = piValue * mult;
     1215        double oldValue = abcDj[iRow] * mult;
     1216        double value = oldValue - tentativeTheta * alpha;
     1217        if (value < dualT) {
     1218          bestPossible = CoinMax(bestPossible, alpha);
     1219          value = oldValue - upperTheta * alpha;
     1220          if (value < dualT && alpha >= acceptablePivot) {
     1221            upperTheta = (oldValue - dualT) / alpha;
     1222          }
     1223          // add to list
     1224          arrayCandidate[numberRemaining] = alpha;
     1225          indexCandidate[numberRemaining++] = iRow;
     1226        }
     1227      } else if ((type & 7) < 6) {
     1228        //} else if (getInternalStatus(iRow)==isFree||getInternalStatus(iRow)==superBasic) {
     1229        bool keep;
     1230        index[numberNonZero] = iRow;
     1231        array[numberNonZero++] = piValue;
     1232        bestPossible = CoinMax(bestPossible, fabs(piValue));
     1233        double oldValue = abcDj[iRow];
     1234        // If free has to be very large - should come in via dualRow
     1235        //if (getInternalStatus(iRow+addSequence)==isFree&&fabs(piValue)<1.0e-3)
     1236        //break;
     1237        if (oldValue > currentDualTolerance_) {
     1238          keep = true;
     1239        } else if (oldValue < -currentDualTolerance_) {
     1240          keep = true;
     1241        } else {
     1242          if (fabs(piValue) > CoinMax(10.0 * currentAcceptablePivot_, 1.0e-5)) {
     1243            keep = true;
     1244          } else {
     1245            keep = false;
     1246            badFree = CoinMax(badFree, fabs(piValue));
     1247          }
     1248        }
     1249        if (keep) {
     1250          // free - choose largest
     1251          if (fabs(piValue) > freePivot) {
     1252            freePivot = fabs(piValue);
     1253            sequenceIn_ = iRow;
     1254            theta_ = oldValue / piValue;
     1255            alpha_ = piValue;
     1256          }
     1257        }
    12771258      }
    12781259    }
     
    12801261  //tableauRow.setNumElements(numberNonZero);
    12811262  //candidateList.setNumElements(numberRemaining);
    1282   tableauRow.setNumElementsPartition(0,numberNonZero);
    1283   candidateList.setNumElementsPartition(0,numberRemaining);
    1284  if (!numberRemaining && sequenceIn_ < 0&&upperTheta_>1.0e29) {
     1263  tableauRow.setNumElementsPartition(0, numberNonZero);
     1264  candidateList.setNumElementsPartition(0, numberRemaining);
     1265  if (!numberRemaining && sequenceIn_ < 0 && upperTheta_ > 1.0e29) {
    12851266    return COIN_DBL_MAX; // Looks infeasible
    12861267  } else {
     
    12961277AbcSimplexDual::dualColumn1B()
    12971278{
    1298   CoinPartitionedVector & tableauRow = usefulArray_[arrayForTableauRow_];
    1299   CoinPartitionedVector & candidateList = usefulArray_[arrayForDualColumn_];
     1279  CoinPartitionedVector &tableauRow = usefulArray_[arrayForTableauRow_];
     1280  CoinPartitionedVector &candidateList = usefulArray_[arrayForDualColumn_];
    13001281  tableauRow.compact();
    13011282  candidateList.clearAndReset();
     
    13051286  double upperTheta = upperTheta_;
    13061287  // pivot elements
    1307   double *  COIN_RESTRICT arrayCandidate=candidateList.denseVector();
     1288  double *COIN_RESTRICT arrayCandidate = candidateList.denseVector();
    13081289  // indices
    1309   int *  COIN_RESTRICT indexCandidate = candidateList.getIndices();
    1310   const double *  COIN_RESTRICT abcDj = abcDj_;
    1311   const unsigned char *  COIN_RESTRICT internalStatus = internalStatus_;
    1312   int *  COIN_RESTRICT index = tableauRow.getIndices();
    1313   double *  COIN_RESTRICT array = tableauRow.denseVector();
    1314   int numberNonZero=tableauRow.getNumElements();
     1290  int *COIN_RESTRICT indexCandidate = candidateList.getIndices();
     1291  const double *COIN_RESTRICT abcDj = abcDj_;
     1292  const unsigned char *COIN_RESTRICT internalStatus = internalStatus_;
     1293  int *COIN_RESTRICT index = tableauRow.getIndices();
     1294  double *COIN_RESTRICT array = tableauRow.denseVector();
     1295  int numberNonZero = tableauRow.getNumElements();
    13151296  // do first pass to get possibles
    13161297  double bestPossible = 0.0;
     
    13181299  double tentativeTheta = 1.0e25; // try with this much smaller as guess
    13191300  double acceptablePivot = currentAcceptablePivot_;
    1320   double dualT=-currentDualTolerance_;
    1321   const double multiplier[] = { 1.0, -1.0};
     1301  double dualT = -currentDualTolerance_;
     1302  const double multiplier[] = { 1.0, -1.0 };
    13221303  if (ordinaryVariables_) {
    1323     for (int i=0;i<numberNonZero;i++) {
    1324       int iSequence=index[i];
    1325       unsigned char iStatus=internalStatus[iSequence]&7;
    1326       if (iStatus<4) {
    1327         double tableauValue=array[i];
    1328         if (fabs(tableauValue)>zeroTolerance_) {
    1329           double mult = multiplier[iStatus];
    1330           double alpha = tableauValue * mult;
    1331           double oldValue = abcDj[iSequence] * mult;
    1332           double value = oldValue - tentativeTheta * alpha;
    1333           if (value < dualT) {
    1334             bestPossible = CoinMax(bestPossible, alpha);
    1335             value = oldValue - upperTheta * alpha;
    1336             if (value < dualT && alpha >= acceptablePivot) {
    1337               upperTheta = (oldValue - dualT) / alpha;
    1338             }
    1339             // add to list
    1340             arrayCandidate[numberRemaining] = alpha;
    1341             indexCandidate[numberRemaining++] = iSequence;
    1342           }
    1343         }
     1304    for (int i = 0; i < numberNonZero; i++) {
     1305      int iSequence = index[i];
     1306      unsigned char iStatus = internalStatus[iSequence] & 7;
     1307      if (iStatus < 4) {
     1308        double tableauValue = array[i];
     1309        if (fabs(tableauValue) > zeroTolerance_) {
     1310          double mult = multiplier[iStatus];
     1311          double alpha = tableauValue * mult;
     1312          double oldValue = abcDj[iSequence] * mult;
     1313          double value = oldValue - tentativeTheta * alpha;
     1314          if (value < dualT) {
     1315            bestPossible = CoinMax(bestPossible, alpha);
     1316            value = oldValue - upperTheta * alpha;
     1317            if (value < dualT && alpha >= acceptablePivot) {
     1318              upperTheta = (oldValue - dualT) / alpha;
     1319            }
     1320            // add to list
     1321            arrayCandidate[numberRemaining] = alpha;
     1322            indexCandidate[numberRemaining++] = iSequence;
     1323          }
     1324        }
    13441325      }
    13451326    }
     
    13481329    double freePivot = currentAcceptablePivot_;
    13491330    double currentDualTolerance = currentDualTolerance_;
    1350     for (int i=0;i<numberNonZero;i++) {
    1351       int iSequence=index[i];
    1352       unsigned char iStatus=internalStatus[iSequence]&7;
    1353       if (iStatus<6) {
    1354         double tableauValue=array[i];
    1355         if (fabs(tableauValue)>zeroTolerance_) {
    1356           if ((iStatus&4)==0) {
    1357             double mult = multiplier[iStatus];
    1358             double alpha = tableauValue * mult;
    1359             double oldValue = abcDj[iSequence] * mult;
    1360             double value = oldValue - tentativeTheta * alpha;
    1361             if (value < dualT) {
    1362               bestPossible = CoinMax(bestPossible, alpha);
    1363               value = oldValue - upperTheta * alpha;
    1364               if (value < dualT && alpha >= acceptablePivot) {
    1365                 upperTheta = (oldValue - dualT) / alpha;
    1366               }
    1367               // add to list
    1368               arrayCandidate[numberRemaining] = alpha;
    1369               indexCandidate[numberRemaining++] = iSequence;
    1370             }
    1371           } else {
    1372             bool keep;
    1373             bestPossible = CoinMax(bestPossible, fabs(tableauValue));
    1374             double oldValue = abcDj[iSequence];
    1375             // If free has to be very large - should come in via dualRow
    1376             //if (getInternalStatus(iSequence+addSequence)==isFree&&fabs(tableauValue)<1.0e-3)
    1377             //break;
    1378             if (oldValue > currentDualTolerance) {
    1379               keep = true;
    1380             } else if (oldValue < -currentDualTolerance) {
    1381               keep = true;
    1382             } else {
    1383               if (fabs(tableauValue) > CoinMax(10.0 * acceptablePivot, 1.0e-5)) {
    1384                 keep = true;
    1385               } else {
    1386                 keep = false;
    1387                 badFree = CoinMax(badFree, fabs(tableauValue));
    1388               }
    1389             }
    1390             if (keep) {
     1331    for (int i = 0; i < numberNonZero; i++) {
     1332      int iSequence = index[i];
     1333      unsigned char iStatus = internalStatus[iSequence] & 7;
     1334      if (iStatus < 6) {
     1335        double tableauValue = array[i];
     1336        if (fabs(tableauValue) > zeroTolerance_) {
     1337          if ((iStatus & 4) == 0) {
     1338            double mult = multiplier[iStatus];
     1339            double alpha = tableauValue * mult;
     1340            double oldValue = abcDj[iSequence] * mult;
     1341            double value = oldValue - tentativeTheta * alpha;
     1342            if (value < dualT) {
     1343              bestPossible = CoinMax(bestPossible, alpha);
     1344              value = oldValue - upperTheta * alpha;
     1345              if (value < dualT && alpha >= acceptablePivot) {
     1346                upperTheta = (oldValue - dualT) / alpha;
     1347              }
     1348              // add to list
     1349              arrayCandidate[numberRemaining] = alpha;
     1350              indexCandidate[numberRemaining++] = iSequence;
     1351            }
     1352          } else {
     1353            bool keep;
     1354            bestPossible = CoinMax(bestPossible, fabs(tableauValue));
     1355            double oldValue = abcDj[iSequence];
     1356            // If free has to be very large - should come in via dualRow
     1357            //if (getInternalStatus(iSequence+addSequence)==isFree&&fabs(tableauValue)<1.0e-3)
     1358            //break;
     1359            if (oldValue > currentDualTolerance) {
     1360              keep = true;
     1361            } else if (oldValue < -currentDualTolerance) {
     1362              keep = true;
     1363            } else {
     1364              if (fabs(tableauValue) > CoinMax(10.0 * acceptablePivot, 1.0e-5)) {
     1365                keep = true;
     1366              } else {
     1367                keep = false;
     1368                badFree = CoinMax(badFree, fabs(tableauValue));
     1369              }
     1370            }
     1371            if (keep) {
    13911372#ifdef PAN
    1392               if (fakeSuperBasic(iSequence)>=0) {
    1393 #endif
    1394                 if (iSequence==freeSequenceIn_)
    1395                   tableauValue=COIN_DBL_MAX;
    1396                 // free - choose largest
    1397                 if (fabs(tableauValue) > fabs(freePivot)) {
    1398                   freePivot = tableauValue;
    1399                   sequenceIn_ = iSequence;
    1400                   theta_ = oldValue / tableauValue;
    1401                   alpha_ = tableauValue;
    1402                 }
     1373              if (fakeSuperBasic(iSequence) >= 0) {
     1374#endif
     1375                if (iSequence == freeSequenceIn_)
     1376                  tableauValue = COIN_DBL_MAX;
     1377                // free - choose largest
     1378                if (fabs(tableauValue) > fabs(freePivot)) {
     1379                  freePivot = tableauValue;
     1380                  sequenceIn_ = iSequence;
     1381                  theta_ = oldValue / tableauValue;
     1382                  alpha_ = tableauValue;
     1383                }
    14031384#ifdef PAN
    1404               }
    1405 #endif
    1406             }
    1407           }
    1408         }
    1409       }
    1410     }
    1411   } 
     1385              }
     1386#endif
     1387            }
     1388          }
     1389        }
     1390      }
     1391    }
     1392  }
    14121393  candidateList.setNumElements(numberRemaining);
    1413   if (!numberRemaining && sequenceIn_ < 0&&upperTheta_>1.0e29) {
     1394  if (!numberRemaining && sequenceIn_ < 0 && upperTheta_ > 1.0e29) {
    14141395    return COIN_DBL_MAX; // Looks infeasible
    14151396  } else {
     
    14221403#define MAXTRY 100
    14231404#define TOL_TYPE -1
    1424 #if TOL_TYPE==-1
    1425 #define useTolerance1() (0.0)     
     1405#if TOL_TYPE == -1
     1406#define useTolerance1() (0.0)
    14261407#define useTolerance2() (0.0)
    14271408#define goToTolerance1() (0.0)
    14281409#define goToTolerance2() (0.0)
    1429 #elif TOL_TYPE==0
    1430 #define useTolerance1() (currentDualTolerance_)     
     1410#elif TOL_TYPE == 0
     1411#define useTolerance1() (currentDualTolerance_)
    14311412#define useTolerance2() (currentDualTolerance_)
    14321413#define goToTolerance1() (0.0)
    14331414#define goToTolerance2() (0.0)
    1434 #elif TOL_TYPE==1
    1435 #define useTolerance1() (perturbedTolerance)     
     1415#elif TOL_TYPE == 1
     1416#define useTolerance1() (perturbedTolerance)
    14361417#define useTolerance2() (0.0)
    14371418#define goToTolerance1() (0.0)
    14381419#define goToTolerance2() (0.0)
    1439 #elif TOL_TYPE==2
    1440 #define useTolerance1() (perturbedTolerance)     
     1420#elif TOL_TYPE == 2
     1421#define useTolerance1() (perturbedTolerance)
    14411422#define useTolerance2() (perturbedTolerance)
    14421423#define goToTolerance1() (0.0)
    14431424#define goToTolerance2() (0.0)
    1444 #elif TOL_TYPE==3
    1445 #define useTolerance1() (perturbedTolerance)     
     1425#elif TOL_TYPE == 3
     1426#define useTolerance1() (perturbedTolerance)
    14461427#define useTolerance2() (perturbedTolerance)
    14471428#define goToTolerance1() (perturbedTolerance)
    14481429#define goToTolerance2() (0.0)
    1449 #elif TOL_TYPE==4
    1450 #define useTolerance1() (perturbedTolerance)     
     1430#elif TOL_TYPE == 4
     1431#define useTolerance1() (perturbedTolerance)
    14511432#define useTolerance2() (perturbedTolerance)
    14521433#define goToTolerance1() (perturbedTolerance)
     
    14541435#else
    14551436XXXX
    1456 #endif     
    1457 #if CLP_CAN_HAVE_ZERO_OBJ<2
     1437#endif
     1438#if CLP_CAN_HAVE_ZERO_OBJ < 2
    14581439#define MODIFYCOST 2
    14591440#endif
    14601441#define DONT_MOVE_OBJECTIVE
    1461 static void dualColumn2Bit(AbcSimplexDual * dual,dualColumnResult * result,
    1462                              int numberBlocks)
     1442static void dualColumn2Bit(AbcSimplexDual *dual, dualColumnResult *result,
     1443  int numberBlocks)
    14631444{
    1464   for (int iBlock=1;iBlock<numberBlocks;iBlock++) {
     1445  for (int iBlock = 1; iBlock < numberBlocks; iBlock++) {
    14651446    cilk_spawn dual->dualColumn2First(result[iBlock]);
    14661447  }
     
    14681449  cilk_sync;
    14691450}
    1470 void
    1471 AbcSimplexDual::dualColumn2First(dualColumnResult & result)
     1451void AbcSimplexDual::dualColumn2First(dualColumnResult &result)
    14721452{
    1473   CoinPartitionedVector & candidateList = usefulArray_[arrayForDualColumn_];
    1474   CoinPartitionedVector & flipList = usefulArray_[arrayForFlipBounds_];
    1475   int iBlock=result.block;
     1453  CoinPartitionedVector &candidateList = usefulArray_[arrayForDualColumn_];
     1454  CoinPartitionedVector &flipList = usefulArray_[arrayForFlipBounds_];
     1455  int iBlock = result.block;
    14761456  int numberSwapped = result.numberSwapped;
    14771457  int numberRemaining = result.numberRemaining;
    1478   double tentativeTheta=result.tentativeTheta;
     1458  double tentativeTheta = result.tentativeTheta;
    14791459  // pivot elements
    1480   double *  COIN_RESTRICT array=candidateList.denseVector();
     1460  double *COIN_RESTRICT array = candidateList.denseVector();
    14811461  // indices
    1482   int *  COIN_RESTRICT indices = candidateList.getIndices();
    1483   const double *  COIN_RESTRICT abcLower = abcLower_;
    1484   const double *  COIN_RESTRICT abcUpper = abcUpper_;
    1485   const double *  COIN_RESTRICT abcDj = abcDj_;
    1486   const unsigned char *  COIN_RESTRICT internalStatus = internalStatus_;
    1487   const double multiplier[] = { 1.0, -1.0};
     1462  int *COIN_RESTRICT indices = candidateList.getIndices();
     1463  const double *COIN_RESTRICT abcLower = abcLower_;
     1464  const double *COIN_RESTRICT abcUpper = abcUpper_;
     1465  const double *COIN_RESTRICT abcDj = abcDj_;
     1466  const unsigned char *COIN_RESTRICT internalStatus = internalStatus_;
     1467  const double multiplier[] = { 1.0, -1.0 };
    14881468
    14891469  // For list of flipped
    1490   int *  COIN_RESTRICT flippedIndex = flipList.getIndices();
    1491   double *  COIN_RESTRICT flippedElement = flipList.denseVector();
     1470  int *COIN_RESTRICT flippedIndex = flipList.getIndices();
     1471  double *COIN_RESTRICT flippedElement = flipList.denseVector();
    14921472  // adjust
    14931473  //if (iBlock>=0) {
    1494     int offset=candidateList.startPartition(iBlock);
    1495     assert(offset==flipList.startPartition(iBlock));
    1496     array += offset;
    1497     indices+=offset;
    1498     flippedIndex+=offset;
    1499     flippedElement+=offset;
    1500     //}
     1474  int offset = candidateList.startPartition(iBlock);
     1475  assert(offset == flipList.startPartition(iBlock));
     1476  array += offset;
     1477  indices += offset;
     1478  flippedIndex += offset;
     1479  flippedElement += offset;
     1480  //}
    15011481  double thruThis = 0.0;
    1502  
     1482
    15031483  double bestPivot = currentAcceptablePivot_;
    15041484  int bestSequence = -1;
    1505   int numberInList=numberRemaining;
     1485  int numberInList = numberRemaining;
    15061486  numberRemaining = 0;
    15071487  double upperTheta = 1.0e50;
     
    15091489  for (int i = 0; i < numberInList; i++) {
    15101490    int iSequence = indices[i];
    1511     assert (getInternalStatus(iSequence) != isFree
    1512             && getInternalStatus(iSequence) != superBasic);
     1491    assert(getInternalStatus(iSequence) != isFree
     1492      && getInternalStatus(iSequence) != superBasic);
    15131493    int iStatus = internalStatus[iSequence] & 3;
    15141494    // treat as if at lower bound
    15151495    double mult = multiplier[iStatus];
    15161496    double alpha = array[i];
    1517     double oldValue = abcDj[iSequence]*mult;
     1497    double oldValue = abcDj[iSequence] * mult;
    15181498    double value = oldValue - tentativeTheta * alpha;
    1519     assert (alpha>0.0);
     1499    assert(alpha > 0.0);
    15201500    //double perturbedTolerance = abcPerturbation[iSequence];
    15211501    if (value < -currentDualTolerance_) {
     
    15281508      flippedIndex[numberSwapped++] = iSequence;
    15291509      if (alpha > bestPivot) {
    1530         bestPivot = alpha;
    1531         bestSequence = iSequence;
     1510        bestPivot = alpha;
     1511        bestSequence = iSequence;
    15321512      }
    15331513    } else {
     
    15351515      value = oldValue - upperTheta * alpha;
    15361516      if (value < -currentDualTolerance_ && alpha >= currentAcceptablePivot_)
    1537         upperTheta = (oldValue + currentDualTolerance_) / alpha;
     1517        upperTheta = (oldValue + currentDualTolerance_) / alpha;
    15381518      array[numberRemaining] = alpha;
    15391519      indices[numberRemaining++] = iSequence;
    15401520    }
    15411521  }
    1542   result.bestEverPivot=bestPivot;
    1543   result.sequence=bestSequence;
    1544   result.numberSwapped=numberSwapped;
    1545   result.numberRemaining=numberRemaining;
    1546   result.thruThis=thruThis;
    1547   result.increaseInThis=increaseInThis;
    1548   result.theta=upperTheta;
     1522  result.bestEverPivot = bestPivot;
     1523  result.sequence = bestSequence;
     1524  result.numberSwapped = numberSwapped;
     1525  result.numberRemaining = numberRemaining;
     1526  result.thruThis = thruThis;
     1527  result.increaseInThis = increaseInThis;
     1528  result.theta = upperTheta;
    15491529}
    1550 void
    1551 AbcSimplexDual::dualColumn2Most(dualColumnResult & result)
     1530void AbcSimplexDual::dualColumn2Most(dualColumnResult &result)
    15521531{
    1553   CoinPartitionedVector & candidateList = usefulArray_[arrayForDualColumn_];
    1554   CoinPartitionedVector & flipList = usefulArray_[arrayForFlipBounds_];
    1555   int numberBlocksReal=candidateList.getNumPartitions();
    1556   flipList.setPartitions(numberBlocksReal,candidateList.startPartitions());
     1532  CoinPartitionedVector &candidateList = usefulArray_[arrayForDualColumn_];
     1533  CoinPartitionedVector &flipList = usefulArray_[arrayForFlipBounds_];
     1534  int numberBlocksReal = candidateList.getNumPartitions();
     1535  flipList.setPartitions(numberBlocksReal, candidateList.startPartitions());
    15571536  int numberBlocks;
    15581537  if (!numberBlocksReal)
    1559     numberBlocks=1;
     1538    numberBlocks = 1;
    15601539  else
    1561     numberBlocks=numberBlocksReal;
     1540    numberBlocks = numberBlocksReal;
    15621541  //usefulArray_[arrayForTableauRow_].compact();
    15631542  //candidateList.compact();
    15641543  int numberSwapped = 0;
    15651544  int numberRemaining = candidateList.getNumElements();
    1566  
     1545
    15671546  double totalThru = 0.0; // for when variables flip
    1568   int sequenceIn=-1;
     1547  int sequenceIn = -1;
    15691548  double bestEverPivot = currentAcceptablePivot_;
    15701549  // If we think we need to modify costs (not if something from broad sweep)
     
    15731552  double increaseInObjective = 0.0;
    15741553  // pivot elements
    1575   double *  COIN_RESTRICT array=candidateList.denseVector();
     1554  double *COIN_RESTRICT array = candidateList.denseVector();
    15761555  // indices
    1577   int *  COIN_RESTRICT indices = candidateList.getIndices();
    1578   const double *  COIN_RESTRICT abcLower = abcLower_;
    1579   const double *  COIN_RESTRICT abcUpper = abcUpper_;
     1556  int *COIN_RESTRICT indices = candidateList.getIndices();
     1557  const double *COIN_RESTRICT abcLower = abcLower_;
     1558  const double *COIN_RESTRICT abcUpper = abcUpper_;
    15801559  //const double *  COIN_RESTRICT abcSolution = abcSolution_;
    1581   const double *  COIN_RESTRICT abcDj = abcDj_;
     1560  const double *COIN_RESTRICT abcDj = abcDj_;
    15821561  //const double *  COIN_RESTRICT abcPerturbation = abcPerturbation_;
    1583   const unsigned char *  COIN_RESTRICT internalStatus = internalStatus_;
     1562  const unsigned char *COIN_RESTRICT internalStatus = internalStatus_;
    15841563  // We can also see if infeasible or pivoting on free
    15851564  double tentativeTheta = 1.0e25; // try with this much smaller as guess
    1586   const double multiplier[] = { 1.0, -1.0};
     1565  const double multiplier[] = { 1.0, -1.0 };
    15871566
    15881567  // For list of flipped
    1589   int numberLastSwapped=0;
    1590   int *  COIN_RESTRICT flippedIndex = flipList.getIndices();
    1591   double *  COIN_RESTRICT flippedElement = flipList.denseVector();
     1568  int numberLastSwapped = 0;
     1569  int *COIN_RESTRICT flippedIndex = flipList.getIndices();
     1570  double *COIN_RESTRICT flippedElement = flipList.denseVector();
    15921571  // If sum of bad small pivots too much
    15931572#ifdef MORE_CAREFUL
     
    15961575  // not free
    15971576  int lastSequence = -1;
    1598   double lastTheta = 0.0; 
     1577  double lastTheta = 0.0;
    15991578  double lastPivotValue = 0.0;
    1600   double thisPivotValue=0.0;
     1579  double thisPivotValue = 0.0;
    16011580  // if free then always choose , otherwise ...
    16021581  double theta = 1.0e50;
    16031582  // now flip flop between spare arrays until reasonable theta
    16041583  tentativeTheta = CoinMax(10.0 * upperTheta_, 1.0e-7);
    1605  
     1584
    16061585  // loops increasing tentative theta until can't go through
    16071586#ifdef PRINT_RATIO_PROGRESS
    1608   int iPass=0;
     1587  int iPass = 0;
    16091588#endif
    16101589  dualColumnResult result2[8];
    1611   for (int iBlock=0;iBlock<numberBlocks;iBlock++) {
    1612     result2[iBlock].block=iBlock;
     1590  for (int iBlock = 0; iBlock < numberBlocks; iBlock++) {
     1591    result2[iBlock].block = iBlock;
    16131592    if (numberBlocksReal)
    1614       result2[iBlock].numberRemaining=candidateList.getNumElements(iBlock);
     1593      result2[iBlock].numberRemaining = candidateList.getNumElements(iBlock);
    16151594    else
    1616       result2[iBlock].numberRemaining=candidateList.getNumElements();
    1617     result2[iBlock].numberSwapped=0;
    1618     result2[iBlock].numberLastSwapped=0;
    1619   }
    1620   double useThru=0.0;
     1595      result2[iBlock].numberRemaining = candidateList.getNumElements();
     1596    result2[iBlock].numberSwapped = 0;
     1597    result2[iBlock].numberLastSwapped = 0;
     1598  }
     1599  double useThru = 0.0;
    16211600  while (tentativeTheta < 1.0e22) {
    16221601    double thruThis = 0.0;
    1623    
     1602
    16241603    double bestPivot = currentAcceptablePivot_;
    16251604    int bestSequence = -1;
    1626     sequenceIn=-1;
    1627     thisPivotValue=0.0;
    1628     int numberInList=numberRemaining;
     1605    sequenceIn = -1;
     1606    thisPivotValue = 0.0;
     1607    int numberInList = numberRemaining;
    16291608    double upperTheta = 1.0e50;
    16301609    double increaseInThis = 0.0; //objective increase in this loop
    1631     for (int iBlock=0;iBlock<numberBlocks;iBlock++) {
    1632       result2[iBlock].tentativeTheta=tentativeTheta;
     1610    for (int iBlock = 0; iBlock < numberBlocks; iBlock++) {
     1611      result2[iBlock].tentativeTheta = tentativeTheta;
    16331612      //result2[iBlock].numberRemaining=numberRemaining;
    16341613      //result2[iBlock].numberSwapped=numberSwapped;
    16351614      //result2[iBlock].numberLastSwapped=numberLastSwapped;
    16361615    }
    1637     for (int iBlock=1;iBlock<numberBlocks;iBlock++) {
     1616    for (int iBlock = 1; iBlock < numberBlocks; iBlock++) {
    16381617      cilk_spawn dualColumn2First(result2[iBlock]);
    16391618    }
     
    16411620    cilk_sync;
    16421621    //dualColumn2Bit(this,result2,numberBlocks);
    1643     numberSwapped=0;
    1644     numberRemaining=0;
    1645     for (int iBlock=0;iBlock<numberBlocks;iBlock++) {
    1646       if (result2[iBlock].bestEverPivot>bestPivot) {
    1647         bestPivot=result2[iBlock].bestEverPivot;
    1648         bestSequence=result2[iBlock].sequence;
    1649       }
    1650       numberSwapped+=result2[iBlock].numberSwapped;
    1651       numberRemaining+=result2[iBlock].numberRemaining;
    1652       thruThis+=result2[iBlock].thruThis;
    1653       increaseInThis+=result2[iBlock].increaseInThis;
    1654       if (upperTheta>result2[iBlock].theta)
    1655         upperTheta=result2[iBlock].theta;
     1622    numberSwapped = 0;
     1623    numberRemaining = 0;
     1624    for (int iBlock = 0; iBlock < numberBlocks; iBlock++) {
     1625      if (result2[iBlock].bestEverPivot > bestPivot) {
     1626        bestPivot = result2[iBlock].bestEverPivot;
     1627        bestSequence = result2[iBlock].sequence;
     1628      }
     1629      numberSwapped += result2[iBlock].numberSwapped;
     1630      numberRemaining += result2[iBlock].numberRemaining;
     1631      thruThis += result2[iBlock].thruThis;
     1632      increaseInThis += result2[iBlock].increaseInThis;
     1633      if (upperTheta > result2[iBlock].theta)
     1634        upperTheta = result2[iBlock].theta;
    16561635    }
    16571636    // end of pass
     
    16591638    iPass++;
    16601639    printf("Iteration %d pass %d dualOut %g thru %g increase %g numberRemain %d\n",
    1661            numberIterations_,iPass,fabs(dualOut_),totalThru+thruThis,increaseInObjective+increaseInThis,
    1662            numberRemaining);
    1663 #endif
    1664     if (totalThru + thruThis > fabs(dualOut_)-fabs(1.0e-9*dualOut_)-1.0e-12 ||
    1665         (increaseInObjective + increaseInThis < 0.0&&bestSequence>=0) || !numberRemaining) {
     1640      numberIterations_, iPass, fabs(dualOut_), totalThru + thruThis, increaseInObjective + increaseInThis,
     1641      numberRemaining);
     1642#endif
     1643    if (totalThru + thruThis > fabs(dualOut_) - fabs(1.0e-9 * dualOut_) - 1.0e-12 || (increaseInObjective + increaseInThis < 0.0 && bestSequence >= 0) || !numberRemaining) {
    16661644      // We should be pivoting in this batch
    16671645      // so compress down to this lot
    1668       numberRemaining=0;
     1646      numberRemaining = 0;
    16691647      candidateList.clearAndReset();
    1670       for (int iBlock=0;iBlock<numberBlocks;iBlock++) {
    1671         int offset=flipList.startPartition(iBlock);
    1672         // set so can compact
    1673         int numberKeep=result2[iBlock].numberLastSwapped;
    1674         flipList.setNumElementsPartition(iBlock,numberKeep);
    1675         for (int i = offset+numberKeep; i <offset+result2[iBlock].numberSwapped; i++) {
    1676           array[numberRemaining] = flippedElement[i];
    1677           flippedElement[i]=0;
    1678           indices[numberRemaining++] = flippedIndex[i];
    1679         }
     1648      for (int iBlock = 0; iBlock < numberBlocks; iBlock++) {
     1649        int offset = flipList.startPartition(iBlock);
     1650        // set so can compact
     1651        int numberKeep = result2[iBlock].numberLastSwapped;
     1652        flipList.setNumElementsPartition(iBlock, numberKeep);
     1653        for (int i = offset + numberKeep; i < offset + result2[iBlock].numberSwapped; i++) {
     1654          array[numberRemaining] = flippedElement[i];
     1655          flippedElement[i] = 0;
     1656          indices[numberRemaining++] = flippedIndex[i];
     1657        }
    16801658      }
    16811659      // make sure candidateList will be cleared correctly
     
    16831661      candidateList.setPackedMode(true);
    16841662      flipList.compact();
    1685       numberSwapped=numberLastSwapped;
    1686       useThru=totalThru;
    1687       assert (totalThru<=fabs(dualOut_));
     1663      numberSwapped = numberLastSwapped;
     1664      useThru = totalThru;
     1665      assert(totalThru <= fabs(dualOut_));
    16881666      int iTry;
    16891667      // first get ratio with tolerance
    16901668      for (iTry = 0; iTry < MAXTRY; iTry++) {
    1691        
    1692         upperTheta = 1.0e50;
    1693         numberInList=numberRemaining;
    1694         numberRemaining = 0;
    1695         increaseInThis = 0.0; //objective increase in this loop
    1696         thruThis = 0.0;
    1697         for (int i = 0; i < numberInList; i++) {
    1698           int iSequence = indices[i];
    1699           assert (getInternalStatus(iSequence) != isFree
    1700                   && getInternalStatus(iSequence) != superBasic);
    1701           int iStatus = internalStatus[iSequence] & 3;
    1702           // treat as if at lower bound
    1703           double mult = multiplier[iStatus];
    1704           double alpha = array[i];
    1705           double oldValue = abcDj[iSequence]*mult;
    1706           double value = oldValue - upperTheta * alpha;
    1707           assert (alpha>0.0);
    1708           //double perturbedTolerance = abcPerturbation[iSequence];
    1709           if (value < -currentDualTolerance_) {
    1710             if (alpha >= currentAcceptablePivot_) {
    1711               upperTheta = (oldValue + currentDualTolerance_) / alpha;
    1712             }
    1713           }
    1714         }
    1715         bestPivot = currentAcceptablePivot_;
    1716         sequenceIn = -1;
    1717         double largestPivot = currentAcceptablePivot_;
    1718         // Sum of bad small pivots
     1669
     1670        upperTheta = 1.0e50;
     1671        numberInList = numberRemaining;
     1672        numberRemaining = 0;
     1673        increaseInThis = 0.0; //objective increase in this loop
     1674        thruThis = 0.0;
     1675        for (int i = 0; i < numberInList; i++) {
     1676          int iSequence = indices[i];
     1677          assert(getInternalStatus(iSequence) != isFree
     1678            && getInternalStatus(iSequence) != superBasic);
     1679          int iStatus = internalStatus[iSequence] & 3;
     1680          // treat as if at lower bound
     1681          double mult = multiplier[iStatus];
     1682          double alpha = array[i];
     1683          double oldValue = abcDj[iSequence] * mult;
     1684          double value = oldValue - upperTheta * alpha;
     1685          assert(alpha > 0.0);
     1686          //double perturbedTolerance = abcPerturbation[iSequence];
     1687          if (value < -currentDualTolerance_) {
     1688            if (alpha >= currentAcceptablePivot_) {
     1689              upperTheta = (oldValue + currentDualTolerance_) / alpha;
     1690            }
     1691          }
     1692        }
     1693        bestPivot = currentAcceptablePivot_;
     1694        sequenceIn = -1;
     1695        double largestPivot = currentAcceptablePivot_;
     1696        // Sum of bad small pivots
    17191697#ifdef MORE_CAREFUL
    1720         double sumBadPivots = 0.0;
    1721         badSumPivots = false;
    1722 #endif
    1723         // Make sure upperTheta will work (-O2 and above gives problems)
    1724         upperTheta *= 1.0000000001;
    1725         for (int i = 0; i < numberInList; i++) {
    1726           int iSequence = indices[i];
    1727           int iStatus = internalStatus[iSequence] & 3;
    1728           // treat as if at lower bound
    1729           double mult = multiplier[iStatus];
    1730           double alpha = array[i];
    1731           double oldValue = abcDj[iSequence]*mult;
    1732           double value = oldValue - upperTheta * alpha;
    1733           assert (alpha>0.0);
    1734           //double perturbedTolerance = abcPerturbation[iSequence];
    1735           double badDj = 0.0;
    1736           if (value <= 0.0) {
    1737             // add to list of swapped
    1738             flippedElement[numberSwapped] = alpha;
    1739             flippedIndex[numberSwapped++] = iSequence;
    1740             badDj = oldValue - useTolerance2();
    1741             // select if largest pivot
    1742             bool take = (alpha > bestPivot);
     1698        double sumBadPivots = 0.0;
     1699        badSumPivots = false;
     1700#endif
     1701        // Make sure upperTheta will work (-O2 and above gives problems)
     1702        upperTheta *= 1.0000000001;
     1703        for (int i = 0; i < numberInList; i++) {
     1704          int iSequence = indices[i];
     1705          int iStatus = internalStatus[iSequence] & 3;
     1706          // treat as if at lower bound
     1707          double mult = multiplier[iStatus];
     1708          double alpha = array[i];
     1709          double oldValue = abcDj[iSequence] * mult;
     1710          double value = oldValue - upperTheta * alpha;
     1711          assert(alpha > 0.0);
     1712          //double perturbedTolerance = abcPerturbation[iSequence];
     1713          double badDj = 0.0;
     1714          if (value <= 0.0) {
     1715            // add to list of swapped
     1716            flippedElement[numberSwapped] = alpha;
     1717            flippedIndex[numberSwapped++] = iSequence;
     1718            badDj = oldValue - useTolerance2();
     1719            // select if largest pivot
     1720            bool take = (alpha > bestPivot);
    17431721#ifdef MORE_CAREFUL
    1744             if (alpha < currentAcceptablePivot_ && upperTheta < 1.0e20) {
    1745               if (value < -currentDualTolerance_) {
    1746                 double gap = abcUpper[iSequence] - abcLower[iSequence];
    1747                 if (gap < 1.0e20)
    1748                   sumBadPivots -= value * gap;
    1749                 else
    1750                   sumBadPivots += 1.0e20;
    1751                 //printf("bad %d alpha %g dj at lower %g\n",
    1752                 //     iSequence,alpha,value);
    1753               }
    1754             }
    1755 #endif
    1756             if (take&&flagged(iSequence)) {
    1757               if (bestPivot>currentAcceptablePivot_)
    1758                 take=false;
    1759             }
    1760             if (take) {
    1761               sequenceIn = iSequence;
    1762               thisPivotValue=alpha;
    1763               bestPivot = alpha;
    1764               if (flagged(iSequence))
    1765                 bestPivot=currentAcceptablePivot_;
    1766               bestSequence = iSequence;
    1767               theta = (oldValue+goToTolerance1()) / alpha;
    1768               //assert (oldValue==abcDj[iSequence]);
    1769               largestPivot = CoinMax(largestPivot, 0.5 * bestPivot);
    1770             }
    1771             double range = abcUpper[iSequence] - abcLower[iSequence];
    1772             thruThis += range * fabs(alpha);
    1773             increaseInThis += badDj * range;
    1774           } else {
    1775             // add to list of remaining
    1776             array[numberRemaining] = alpha;
    1777             indices[numberRemaining++] = iSequence;
    1778           }
    1779         }
     1722            if (alpha < currentAcceptablePivot_ && upperTheta < 1.0e20) {
     1723              if (value < -currentDualTolerance_) {
     1724                double gap = abcUpper[iSequence] - abcLower[iSequence];
     1725                if (gap < 1.0e20)
     1726                  sumBadPivots -= value * gap;
     1727                else
     1728                  sumBadPivots += 1.0e20;
     1729                //printf("bad %d alpha %g dj at lower %g\n",
     1730                //     iSequence,alpha,value);
     1731              }
     1732            }
     1733#endif
     1734            if (take && flagged(iSequence)) {
     1735              if (bestPivot > currentAcceptablePivot_)
     1736                take = false;
     1737            }
     1738            if (take) {
     1739              sequenceIn = iSequence;
     1740              thisPivotValue = alpha;
     1741              bestPivot = alpha;
     1742              if (flagged(iSequence))
     1743                bestPivot = currentAcceptablePivot_;
     1744              bestSequence = iSequence;
     1745              theta = (oldValue + goToTolerance1()) / alpha;
     1746              //assert (oldValue==abcDj[iSequence]);
     1747              largestPivot = CoinMax(largestPivot, 0.5 * bestPivot);
     1748            }
     1749            double range = abcUpper[iSequence] - abcLower[iSequence];
     1750            thruThis += range * fabs(alpha);
     1751            increaseInThis += badDj * range;
     1752          } else {
     1753            // add to list of remaining
     1754            array[numberRemaining] = alpha;
     1755            indices[numberRemaining++] = iSequence;
     1756          }
     1757        }
    17801758#ifdef MORE_CAREFUL
    1781         // If we have done pivots and things look bad set alpha_ 0.0 to force factorization
    1782         if (sumBadPivots > 1.0e4) {
    1783 #if ABC_NORMAL_DEBUG>0
    1784           if (handler_->logLevel() > 1)
    1785             printf("maybe forcing re-factorization - sum %g  %d pivots\n", sumBadPivots,
    1786                    abcFactorization_->pivots());
    1787 #endif
    1788           if(abcFactorization_->pivots() > 3) {
    1789             badSumPivots = true;
     1759        // If we have done pivots and things look bad set alpha_ 0.0 to force factorization
     1760        if (sumBadPivots > 1.0e4) {
     1761#if ABC_NORMAL_DEBUG > 0
     1762          if (handler_->logLevel() > 1)
     1763            printf("maybe forcing re-factorization - sum %g  %d pivots\n", sumBadPivots,
     1764              abcFactorization_->pivots());
     1765#endif
     1766          if (abcFactorization_->pivots() > 3) {
     1767            badSumPivots = true;
    17901768#ifdef PRINT_RATIO_PROGRESS
    1791             printf("maybe forcing re-factorization - sum %g  %d pivots\n", sumBadPivots,
    1792                    abcFactorization_->pivots());
    1793 #endif
    1794             break;
    1795           }
    1796         }
    1797 #endif
    1798         // If we stop now this will be increase in objective (I think)
    1799         double increase = (fabs(dualOut_) - totalThru) * theta;
    1800         increase += increaseInObjective;
    1801         if (theta < 0.0)
    1802           thruThis += fabs(dualOut_); // force using this one
    1803         if (((increaseInObjective < 0.0 && increase < 0.0)||
    1804              (theta>1.0e9 && lastTheta < 1.0e-5))
    1805             && lastSequence >= 0) {
    1806           // back
    1807           // We may need to be more careful - we could do by
    1808           // switch so we always do fine grained?
    1809           bestPivot = 0.0;
    1810           bestSequence=-1;
    1811         } else {
    1812           // add in
    1813           totalThru += thruThis;
    1814           increaseInObjective += increaseInThis;
    1815           lastTheta=theta;
    1816         }
    1817         if (bestPivot < 0.1 * bestEverPivot &&
    1818             bestEverPivot > 1.0e-6 &&
    1819             (bestPivot < 1.0e-3 || totalThru * 2.0 > fabs(dualOut_))) {
    1820           // back to previous one
    1821           sequenceIn = lastSequence;
    1822           thisPivotValue=lastPivotValue;
     1769            printf("maybe forcing re-factorization - sum %g  %d pivots\n", sumBadPivots,
     1770              abcFactorization_->pivots());
     1771#endif
     1772            break;
     1773          }
     1774        }
     1775#endif
     1776        // If we stop now this will be increase in objective (I think)
     1777        double increase = (fabs(dualOut_) - totalThru) * theta;
     1778        increase += increaseInObjective;
     1779        if (theta < 0.0)
     1780          thruThis += fabs(dualOut_); // force using this one
     1781        if (((increaseInObjective < 0.0 && increase < 0.0) || (theta > 1.0e9 && lastTheta < 1.0e-5))
     1782          && lastSequence >= 0) {
     1783          // back
     1784          // We may need to be more careful - we could do by
     1785          // switch so we always do fine grained?
     1786          bestPivot = 0.0;
     1787          bestSequence = -1;
     1788        } else {
     1789          // add in
     1790          totalThru += thruThis;
     1791          increaseInObjective += increaseInThis;
     1792          lastTheta = theta;
     1793        }
     1794        if (bestPivot < 0.1 * bestEverPivot && bestEverPivot > 1.0e-6 && (bestPivot < 1.0e-3 || totalThru * 2.0 > fabs(dualOut_))) {
     1795          // back to previous one
     1796          sequenceIn = lastSequence;
     1797          thisPivotValue = lastPivotValue;
    18231798#ifdef PRINT_RATIO_PROGRESS
    1824           printf("Try %d back to previous bestPivot %g bestEver %g totalThru %g\n",
    1825                  iTry,bestPivot,bestEverPivot,totalThru);
    1826 #endif
    1827           break;
    1828         } else if (sequenceIn == -1 && upperTheta > largeValue_) {
    1829           if (lastPivotValue > currentAcceptablePivot_) {
    1830             // back to previous one
    1831             sequenceIn = lastSequence;
    1832             thisPivotValue=lastPivotValue;
     1799          printf("Try %d back to previous bestPivot %g bestEver %g totalThru %g\n",
     1800            iTry, bestPivot, bestEverPivot, totalThru);
     1801#endif
     1802          break;
     1803        } else if (sequenceIn == -1 && upperTheta > largeValue_) {
     1804          if (lastPivotValue > currentAcceptablePivot_) {
     1805            // back to previous one
     1806            sequenceIn = lastSequence;
     1807            thisPivotValue = lastPivotValue;
    18331808#ifdef PRINT_RATIO_PROGRESS
    1834             printf("Try %d no pivot this time large theta %g lastPivot %g\n",
    1835                    iTry,upperTheta,lastPivotValue);
    1836 #endif
    1837           } else {
    1838             // can only get here if all pivots too small
     1809            printf("Try %d no pivot this time large theta %g lastPivot %g\n",
     1810              iTry, upperTheta, lastPivotValue);
     1811#endif
     1812          } else {
     1813            // can only get here if all pivots too small
    18391814#ifdef PRINT_RATIO_PROGRESS
    1840             printf("XXBAD Try %d no pivot this time large theta %g lastPivot %g\n",
    1841                    iTry,upperTheta,lastPivotValue);
    1842 #endif
    1843           }
    1844           break;
    1845         } else if (totalThru >= fabs(dualOut_)) {
     1815            printf("XXBAD Try %d no pivot this time large theta %g lastPivot %g\n",
     1816              iTry, upperTheta, lastPivotValue);
     1817#endif
     1818          }
     1819          break;
     1820        } else if (totalThru >= fabs(dualOut_)) {
    18461821#ifdef PRINT_RATIO_PROGRESS
    1847           printf("Try %d upperTheta %g totalThru %g - can modify costs\n",
    1848                  iTry,upperTheta,lastPivotValue);
    1849 #endif
    1850           modifyCosts = true; // fine grain - we can modify costs
    1851           break; // no point trying another loop
    1852         } else {
    1853           lastSequence = sequenceIn;
    1854           lastPivotValue=thisPivotValue;
    1855           if (bestPivot > bestEverPivot) {
    1856             bestEverPivot = bestPivot;
    1857             //bestEverSequence=bestSequence;
    1858           }
    1859           modifyCosts = true; // fine grain - we can modify costs
    1860         }
     1822          printf("Try %d upperTheta %g totalThru %g - can modify costs\n",
     1823            iTry, upperTheta, lastPivotValue);
     1824#endif
     1825          modifyCosts = true; // fine grain - we can modify costs
     1826          break; // no point trying another loop
     1827        } else {
     1828          lastSequence = sequenceIn;
     1829          lastPivotValue = thisPivotValue;
     1830          if (bestPivot > bestEverPivot) {
     1831            bestEverPivot = bestPivot;
     1832            //bestEverSequence=bestSequence;
     1833          }
     1834          modifyCosts = true; // fine grain - we can modify costs
     1835        }
    18611836#ifdef PRINT_RATIO_PROGRESS
    1862         printf("Onto next pass totalthru %g bestPivot %g\n",
    1863                totalThru,lastPivotValue);
    1864 #endif
    1865         numberLastSwapped=numberSwapped;
     1837        printf("Onto next pass totalthru %g bestPivot %g\n",
     1838          totalThru, lastPivotValue);
     1839#endif
     1840        numberLastSwapped = numberSwapped;
    18661841      }
    18671842      break;
     
    18701845      if (bestPivot > 1.0e-3 || bestPivot > bestEverPivot) {
    18711846#ifdef PRINT_RATIO_PROGRESS
    1872         printf("Continuing bestPivot %g bestEver %g %d swapped - new tentative %g\n",
    1873                bestPivot,bestEverPivot,numberSwapped,2*upperTheta);
    1874 #endif
    1875         bestEverPivot = bestPivot;
    1876         //bestEverSequence=bestSequence;
    1877         lastPivotValue=bestPivot;
    1878         lastSequence = bestSequence;
    1879         for (int iBlock=0;iBlock<numberBlocks;iBlock++)
    1880           result2[iBlock].numberLastSwapped=result2[iBlock].numberSwapped;
    1881         numberLastSwapped=numberSwapped;
     1847        printf("Continuing bestPivot %g bestEver %g %d swapped - new tentative %g\n",
     1848          bestPivot, bestEverPivot, numberSwapped, 2 * upperTheta);
     1849#endif
     1850        bestEverPivot = bestPivot;
     1851        //bestEverSequence=bestSequence;
     1852        lastPivotValue = bestPivot;
     1853        lastSequence = bestSequence;
     1854        for (int iBlock = 0; iBlock < numberBlocks; iBlock++)
     1855          result2[iBlock].numberLastSwapped = result2[iBlock].numberSwapped;
     1856        numberLastSwapped = numberSwapped;
    18821857      } else {
    18831858#ifdef PRINT_RATIO_PROGRESS
    1884         printf("keep old swapped bestPivot %g bestEver %g %d swapped - new tentative %g\n",
    1885                bestPivot,bestEverPivot,numberSwapped,2*upperTheta);
    1886 #endif
    1887         // keep old swapped
    1888         numberRemaining=0;
    1889         for (int iBlock=0;iBlock<numberBlocks;iBlock++) {
    1890           int offset=flipList.startPartition(iBlock);
    1891           int numberRemaining2=offset+result2[iBlock].numberRemaining;
    1892           int numberLastSwapped=result2[iBlock].numberLastSwapped;
    1893           for (int i = offset+numberLastSwapped;
    1894                i <offset+result2[iBlock].numberSwapped; i++) {
    1895             array[numberRemaining2] = flippedElement[i];
    1896             flippedElement[i]=0;
    1897             indices[numberRemaining2++] = flippedIndex[i];
    1898           }
    1899           result2[iBlock].numberRemaining=numberRemaining2-offset;
    1900           numberRemaining += result2[iBlock].numberRemaining;
    1901           result2[iBlock].numberSwapped=numberLastSwapped;
    1902         }
    1903         numberSwapped=numberLastSwapped;
     1859        printf("keep old swapped bestPivot %g bestEver %g %d swapped - new tentative %g\n",
     1860          bestPivot, bestEverPivot, numberSwapped, 2 * upperTheta);
     1861#endif
     1862        // keep old swapped
     1863        numberRemaining = 0;
     1864        for (int iBlock = 0; iBlock < numberBlocks; iBlock++) {
     1865          int offset = flipList.startPartition(iBlock);
     1866          int numberRemaining2 = offset + result2[iBlock].numberRemaining;
     1867          int numberLastSwapped = result2[iBlock].numberLastSwapped;
     1868          for (int i = offset + numberLastSwapped;
     1869               i < offset + result2[iBlock].numberSwapped; i++) {
     1870            array[numberRemaining2] = flippedElement[i];
     1871            flippedElement[i] = 0;
     1872            indices[numberRemaining2++] = flippedIndex[i];
     1873          }
     1874          result2[iBlock].numberRemaining = numberRemaining2 - offset;
     1875          numberRemaining += result2[iBlock].numberRemaining;
     1876          result2[iBlock].numberSwapped = numberLastSwapped;
     1877        }
     1878        numberSwapped = numberLastSwapped;
    19041879      }
    19051880      increaseInObjective += increaseInThis;
     
    19101885  if (flipList.getNumPartitions()) {
    19111886    // need to compress
    1912     numberRemaining=0;
     1887    numberRemaining = 0;
    19131888    candidateList.clearAndReset();
    1914     for (int iBlock=0;iBlock<numberBlocks;iBlock++) {
    1915       int offset=flipList.startPartition(iBlock);
     1889    for (int iBlock = 0; iBlock < numberBlocks; iBlock++) {
     1890      int offset = flipList.startPartition(iBlock);
    19161891      // set so can compact
    1917       int numberKeep=result2[iBlock].numberLastSwapped;
    1918       flipList.setNumElementsPartition(iBlock,numberKeep);
    1919       for (int i = offset+numberKeep; i <offset+result2[iBlock].numberSwapped; i++) {
    1920         array[numberRemaining] = flippedElement[i];
    1921         flippedElement[i]=0;
    1922         indices[numberRemaining++] = flippedIndex[i];
     1892      int numberKeep = result2[iBlock].numberLastSwapped;
     1893      flipList.setNumElementsPartition(iBlock, numberKeep);
     1894      for (int i = offset + numberKeep; i < offset + result2[iBlock].numberSwapped; i++) {
     1895        array[numberRemaining] = flippedElement[i];
     1896        flippedElement[i] = 0;
     1897        indices[numberRemaining++] = flippedIndex[i];
    19231898      }
    19241899    }
     
    19271902    candidateList.setPackedMode(true);
    19281903    flipList.compact();
    1929     numberSwapped=numberLastSwapped;
    1930   }
    1931   result.theta=theta; //?
    1932   result.totalThru=totalThru;
    1933   result.useThru=useThru;
    1934   result.bestEverPivot=bestEverPivot; //?
    1935   result.increaseInObjective=increaseInObjective; //?
    1936   result.tentativeTheta=tentativeTheta; //?
    1937   result.lastPivotValue=lastPivotValue;
    1938   result.thisPivotValue=thisPivotValue;
    1939   result.lastSequence=lastSequence;
    1940   result.sequence=sequenceIn;
     1904    numberSwapped = numberLastSwapped;
     1905  }
     1906  result.theta = theta; //?
     1907  result.totalThru = totalThru;
     1908  result.useThru = useThru;
     1909  result.bestEverPivot = bestEverPivot; //?
     1910  result.increaseInObjective = increaseInObjective; //?
     1911  result.tentativeTheta = tentativeTheta; //?
     1912  result.lastPivotValue = lastPivotValue;
     1913  result.thisPivotValue = thisPivotValue;
     1914  result.lastSequence = lastSequence;
     1915  result.sequence = sequenceIn;
    19411916  //result.block;
    19421917  //result.pass;
    19431918  //result.phase;
    1944   result.numberSwapped=numberSwapped;
    1945   result.numberLastSwapped=numberLastSwapped;
    1946   result.modifyCosts=modifyCosts;
     1919  result.numberSwapped = numberSwapped;
     1920  result.numberLastSwapped = numberLastSwapped;
     1921  result.modifyCosts = modifyCosts;
    19471922}
    19481923/*
     
    19511926  If necessary will modify costs
    19521927*/
    1953 void
    1954 AbcSimplexDual::dualColumn2()
     1928void AbcSimplexDual::dualColumn2()
    19551929{
    1956   CoinPartitionedVector & candidateList = usefulArray_[arrayForDualColumn_];
    1957   CoinPartitionedVector & flipList = usefulArray_[arrayForFlipBounds_];
     1930  CoinPartitionedVector &candidateList = usefulArray_[arrayForDualColumn_];
     1931  CoinPartitionedVector &flipList = usefulArray_[arrayForFlipBounds_];
    19581932  //usefulArray_[arrayForTableauRow_].compact();
    19591933  usefulArray_[arrayForTableauRow_].computeNumberElements();
    1960   if (candidateList.getNumElements()<100)
     1934  if (candidateList.getNumElements() < 100)
    19611935    candidateList.compact();
    19621936  //usefulArray_[arrayForTableauRow_].compact();
     
    19671941  if (numberIterations_ > 100)
    19681942    currentAcceptablePivot_ = acceptablePivot_;
    1969   if (abcFactorization_->pivots() > 10 ||
    1970       (abcFactorization_->pivots() && sumDualInfeasibilities_))
     1943  if (abcFactorization_->pivots() > 10 || (abcFactorization_->pivots() && sumDualInfeasibilities_))
    19711944    currentAcceptablePivot_ = 1.0e+3 * acceptablePivot_; // if we have iterated be more strict
    19721945  else if (abcFactorization_->pivots() > 5)
     
    19761949  // If very large infeasibility use larger acceptable pivot
    19771950  if (abcFactorization_->pivots()) {
    1978     double value=CoinMax(currentAcceptablePivot_,1.0e-12*fabs(dualOut_));
    1979     currentAcceptablePivot_=CoinMin(1.0e2*currentAcceptablePivot_,value);
     1951    double value = CoinMax(currentAcceptablePivot_, 1.0e-12 * fabs(dualOut_));
     1952    currentAcceptablePivot_ = CoinMin(1.0e2 * currentAcceptablePivot_, value);
    19801953  }
    19811954  // return at once if no free but there were free
    1982   if (lastFirstFree_>=0&&sequenceIn_<0) {
     1955  if (lastFirstFree_ >= 0 && sequenceIn_ < 0) {
    19831956    candidateList.clearAndReset();
    1984     upperTheta_=COIN_DBL_MAX;
    1985   }
    1986   if (upperTheta_==COIN_DBL_MAX) {
     1957    upperTheta_ = COIN_DBL_MAX;
     1958  }
     1959  if (upperTheta_ == COIN_DBL_MAX) {
    19871960    usefulArray_[arrayForTableauRow_].compact();
    1988     assert (!candidateList.getNumElements());
     1961    assert(!candidateList.getNumElements());
    19891962    return;
    19901963  }
    19911964  int numberSwapped = 0;
    19921965  //int numberRemaining = candidateList.getNumElements();
    1993  
     1966
    19941967  double useThru = 0.0; // for when variables flip
    1995  
     1968
    19961969  // If we think we need to modify costs (not if something from broad sweep)
    19971970  bool modifyCosts = false;
     
    19991972  //double *  COIN_RESTRICT array=candidateList.denseVector();
    20001973  // indices
    2001   const double *  COIN_RESTRICT abcLower = abcLower_;
    2002   const double *  COIN_RESTRICT abcUpper = abcUpper_;
    2003   const double *  COIN_RESTRICT abcSolution = abcSolution_;
    2004   const double *  COIN_RESTRICT abcDj = abcDj_;
     1974  const double *COIN_RESTRICT abcLower = abcLower_;
     1975  const double *COIN_RESTRICT abcUpper = abcUpper_;
     1976  const double *COIN_RESTRICT abcSolution = abcSolution_;
     1977  const double *COIN_RESTRICT abcDj = abcDj_;
    20051978  //const double *  COIN_RESTRICT abcPerturbation = abcPerturbation_;
    2006   const unsigned char *  COIN_RESTRICT internalStatus = internalStatus_;
     1979  const unsigned char *COIN_RESTRICT internalStatus = internalStatus_;
    20071980  // We can also see if infeasible or pivoting on free
    2008   const double multiplier[] = { 1.0, -1.0};
     1981  const double multiplier[] = { 1.0, -1.0 };
    20091982
    20101983  // For list of flipped
    2011   int numberLastSwapped=0;
    2012   int *  COIN_RESTRICT flippedIndex = flipList.getIndices();
    2013   double *  COIN_RESTRICT flippedElement = flipList.denseVector();
     1984  int numberLastSwapped = 0;
     1985  int *COIN_RESTRICT flippedIndex = flipList.getIndices();
     1986  double *COIN_RESTRICT flippedElement = flipList.denseVector();
    20141987  // If sum of bad small pivots too much
    20151988#ifdef MORE_CAREFUL
    20161989  bool badSumPivots = false;
    20171990#endif
    2018   if (sequenceIn_<0) {
     1991  if (sequenceIn_ < 0) {
    20191992    int lastSequence = -1;
    20201993    double lastPivotValue = 0.0;
    2021     double thisPivotValue=0.0;
     1994    double thisPivotValue = 0.0;
    20221995    dualColumnResult result;
    20231996    dualColumn2Most(result);
    2024     sequenceIn_=result.sequence;
    2025     lastSequence=result.lastSequence;
    2026     thisPivotValue=result.thisPivotValue;
    2027     lastPivotValue=result.lastPivotValue;
    2028     numberSwapped=result.numberSwapped;
    2029     numberLastSwapped=result.numberLastSwapped;
    2030     modifyCosts=result.modifyCosts;
    2031     useThru=result.useThru;
     1997    sequenceIn_ = result.sequence;
     1998    lastSequence = result.lastSequence;
     1999    thisPivotValue = result.thisPivotValue;
     2000    lastPivotValue = result.lastPivotValue;
     2001    numberSwapped = result.numberSwapped;
     2002    numberLastSwapped = result.numberLastSwapped;
     2003    modifyCosts = result.modifyCosts;
     2004    useThru = result.useThru;
    20322005#ifdef PRINT_RATIO_PROGRESS
    20332006    printf("Iteration %d - out of loop - sequenceIn %d pivotValue %g\n",
    2034            numberIterations_,sequenceIn_,thisPivotValue);
     2007      numberIterations_, sequenceIn_, thisPivotValue);
    20352008#endif
    20362009    // can get here without sequenceIn_ set but with lastSequence
     
    20382011      // back to previous one
    20392012      sequenceIn_ = lastSequence;
    2040       thisPivotValue=lastPivotValue;
     2013      thisPivotValue = lastPivotValue;
    20412014#ifdef PRINT_RATIO_PROGRESS
    20422015      printf("BUT back one - out of loop - sequenceIn %d pivotValue %g\n",
    2043            sequenceIn_,thisPivotValue);
    2044 #endif
    2045     }
    2046    
     2016        sequenceIn_, thisPivotValue);
     2017#endif
     2018    }
     2019
    20472020    // Movement should be minimum for anti-degeneracy - unless
    20482021    // fixed variable out
    20492022    // no need if just one candidate
    2050     assert( numberSwapped-numberLastSwapped>=0);
     2023    assert(numberSwapped - numberLastSwapped >= 0);
    20512024    double minimumTheta;
    2052     if (upperOut_ > lowerOut_&&numberSwapped-numberLastSwapped>1)
     2025    if (upperOut_ > lowerOut_ && numberSwapped - numberLastSwapped > 1)
    20532026#ifndef TRY_ABC_GUS
    20542027      minimumTheta = MINIMUMTHETA;
     
    20602033    if (sequenceIn_ >= 0) {
    20612034      double oldValue;
    2062       alpha_ = thisPivotValue; 
     2035      alpha_ = thisPivotValue;
    20632036      // correct sign
    20642037      int iStatus = internalStatus[sequenceIn_] & 3;
     
    20672040      theta_ = CoinMax(oldValue / alpha_, 0.0);
    20682041      if (theta_ < minimumTheta && fabs(alpha_) < 1.0e5 && 1) {
    2069         // can't pivot to zero
    2070         theta_ = minimumTheta;
     2042        // can't pivot to zero
     2043        theta_ = minimumTheta;
    20712044      }
    20722045      // may need to adjust costs so all dual feasible AND pivoted is exactly 0
    20732046      if (modifyCosts
    20742047#ifdef MORE_CAREFUL
    2075           &&!badSumPivots
    2076 #endif
    2077           ) {
    2078         for (int i = numberLastSwapped; i < numberSwapped; i++) {
    2079           int iSequence = flippedIndex[i];
    2080           int iStatus = internalStatus[iSequence] & 3;
    2081           // treat as if at lower bound
    2082           double mult = multiplier[iStatus];
    2083           double alpha = flippedElement[i];
    2084           flippedElement[i]=0.0;
    2085           if (iSequence==sequenceIn_)
    2086             continue;
    2087           double oldValue = abcDj[iSequence]*mult;
    2088           double value = oldValue - theta_ * alpha;
    2089           //double perturbedTolerance = abcPerturbation[iSequence];
    2090           if (-value > currentDualTolerance_) {
    2091             //thisIncrease = true;
     2048        && !badSumPivots
     2049#endif
     2050      ) {
     2051        for (int i = numberLastSwapped; i < numberSwapped; i++) {
     2052          int iSequence = flippedIndex[i];
     2053          int iStatus = internalStatus[iSequence] & 3;
     2054          // treat as if at lower bound
     2055          double mult = multiplier[iStatus];
     2056          double alpha = flippedElement[i];
     2057          flippedElement[i] = 0.0;
     2058          if (iSequence == sequenceIn_)
     2059            continue;
     2060          double oldValue = abcDj[iSequence] * mult;
     2061          double value = oldValue - theta_ * alpha;
     2062          //double perturbedTolerance = abcPerturbation[iSequence];
     2063          if (-value > currentDualTolerance_) {
     2064            //thisIncrease = true;
    20922065#if MODIFYCOST
    2093             if (numberIterations_>=normalDualColumnIteration_) {
    2094               // modify cost to hit new tolerance
    2095               double modification = alpha * theta_ - oldValue - currentDualTolerance_;
    2096               if ((specialOptions_&(2048 + 4096)) != 0) {
    2097                 if ((specialOptions_ & 2048) != 0) {
    2098                   if (fabs(modification) < 1.0e-10)
    2099                     modification = 0.0;
    2100                 } else {
    2101                   if (fabs(modification) < 1.0e-12)
    2102                     modification = 0.0;
    2103                 }
    2104               }
    2105               abcDj_[iSequence] += mult*modification;
    2106               abcCost_[iSequence] +=  mult*modification;
    2107               if (modification)
    2108                 numberChanged_ ++; // Say changed costs
    2109             }
    2110 #endif
    2111           }
    2112         }
    2113         numberSwapped=numberLastSwapped;
    2114       }
    2115     }
    2116   }
    2117  
     2066            if (numberIterations_ >= normalDualColumnIteration_) {
     2067              // modify cost to hit new tolerance
     2068              double modification = alpha * theta_ - oldValue - currentDualTolerance_;
     2069              if ((specialOptions_ & (2048 + 4096)) != 0) {
     2070                if ((specialOptions_ & 2048) != 0) {
     2071                  if (fabs(modification) < 1.0e-10)
     2072                    modification = 0.0;
     2073                } else {
     2074                  if (fabs(modification) < 1.0e-12)
     2075                    modification = 0.0;
     2076                }
     2077              }
     2078              abcDj_[iSequence] += mult * modification;
     2079              abcCost_[iSequence] += mult * modification;
     2080              if (modification)
     2081                numberChanged_++; // Say changed costs
     2082            }
     2083#endif
     2084          }
     2085        }
     2086        numberSwapped = numberLastSwapped;
     2087      }
     2088    }
     2089  }
     2090
    21182091#ifdef MORE_CAREFUL
    21192092  // If we have done pivots and things look bad set alpha_ 0.0 to force factorization
    2120   if ((badSumPivots ||
    2121        fabs(theta_ * badFree) > 10.0 * currentDualTolerance_) && abcFactorization_->pivots()) {
    2122 #if ABC_NORMAL_DEBUG>0
     2093  if ((badSumPivots || fabs(theta_ * badFree) > 10.0 * currentDualTolerance_) && abcFactorization_->pivots()) {
     2094#if ABC_NORMAL_DEBUG > 0
    21232095    if (handler_->logLevel() > 1)
    21242096      printf("forcing re-factorization\n");
     
    21322104    valueIn_ = abcSolution[sequenceIn_];
    21332105    dualIn_ = abcDj_[sequenceIn_];
    2134    
     2106
    21352107    if (numberTimesOptimal_) {
    21362108      // can we adjust cost back closer to original
    21372109      //*** add coding
    21382110    }
    2139     if (numberIterations_>=normalDualColumnIteration_) {
    2140 #if MODIFYCOST>1
     2111    if (numberIterations_ >= normalDualColumnIteration_) {
     2112#if MODIFYCOST > 1
    21412113      // modify cost to hit zero exactly
    21422114      // so (dualIn_+modification)==theta_*alpha_
    21432115      //double perturbedTolerance = abcPerturbation[sequenceIn_];
    2144       double modification = theta_ * alpha_ - (dualIn_+goToTolerance2());
     2116      double modification = theta_ * alpha_ - (dualIn_ + goToTolerance2());
    21452117      // But should not move objective too much ??
    21462118#ifdef DONT_MOVE_OBJECTIVE
     
    21482120      double smallMove = CoinMax(fabs(rawObjectiveValue_), 1.0e-3);
    21492121      if (moveObjective > smallMove) {
    2150 #if ABC_NORMAL_DEBUG>0
    2151         if (handler_->logLevel() > 1)
    2152           printf("would move objective by %g - original mod %g sol value %g\n", moveObjective,
    2153                 modification, abcSolution[sequenceIn_]);
    2154 #endif
    2155         modification *= smallMove / moveObjective;
     2122#if ABC_NORMAL_DEBUG > 0
     2123        if (handler_->logLevel() > 1)
     2124          printf("would move objective by %g - original mod %g sol value %g\n", moveObjective,
     2125            modification, abcSolution[sequenceIn_]);
     2126#endif
     2127        modification *= smallMove / moveObjective;
    21562128      }
    21572129#endif
    21582130#ifdef MORE_CAREFUL
    21592131      if (badSumPivots)
    2160         modification = 0.0;
    2161 #endif
    2162       if (atFakeBound(sequenceIn_)&&fabs(modification)<currentDualTolerance_)
    2163         modification=0.0;
    2164       if ((specialOptions_&(2048 + 4096)) != 0) {
    2165         if ((specialOptions_ & 16384) != 0) {
    2166           // in fast dual
    2167           if (fabs(modification) < 1.0e-7)
    2168             modification = 0.0;
    2169         } else if ((specialOptions_ & 2048) != 0) {
    2170           if (fabs(modification) < 1.0e-10)
    2171             modification = 0.0;
    2172         } else {
    2173           if (fabs(modification) < 1.0e-12)
    2174             modification = 0.0;
    2175         }
    2176       }
    2177      
     2132        modification = 0.0;
     2133#endif
     2134      if (atFakeBound(sequenceIn_) && fabs(modification) < currentDualTolerance_)
     2135        modification = 0.0;
     2136      if ((specialOptions_ & (2048 + 4096)) != 0) {
     2137        if ((specialOptions_ & 16384) != 0) {
     2138          // in fast dual
     2139          if (fabs(modification) < 1.0e-7)
     2140            modification = 0.0;
     2141        } else if ((specialOptions_ & 2048) != 0) {
     2142          if (fabs(modification) < 1.0e-10)
     2143            modification = 0.0;
     2144        } else {
     2145          if (fabs(modification) < 1.0e-12)
     2146            modification = 0.0;
     2147        }
     2148      }
     2149
    21782150      dualIn_ += modification;
    21792151      abcDj_[sequenceIn_] = dualIn_;
    21802152      abcCost_[sequenceIn_] += modification;
    21812153      if (modification)
    2182         numberChanged_ ++; // Say changed costs
    2183       //int costOffset = numberRows_+numberColumns_;
    2184       //abcCost[sequenceIn_+costOffset] += modification; // save change
    2185       //assert (fabs(modification)<1.0e-6);
    2186 #if ABC_NORMAL_DEBUG>3
     2154        numberChanged_++; // Say changed costs
     2155        //int costOffset = numberRows_+numberColumns_;
     2156        //abcCost[sequenceIn_+costOffset] += modification; // save change
     2157        //assert (fabs(modification)<1.0e-6);
     2158#if ABC_NORMAL_DEBUG > 3
    21872159      if ((handler_->logLevel() & 32) && fabs(modification) > 1.0e-15)
    2188         printf("exact %d new cost %g, change %g\n", sequenceIn_,
    2189                abcCost_[sequenceIn_], modification);
    2190 #endif
    2191 #endif
    2192     }
    2193    
     2160        printf("exact %d new cost %g, change %g\n", sequenceIn_,
     2161          abcCost_[sequenceIn_], modification);
     2162#endif
     2163#endif
     2164    }
     2165
    21942166    if (alpha_ < 0.0) {
    21952167      // as if from upper bound
     
    22092181  //     dualOut_,theta_,alpha_,abcDj_[sequenceIn_],useThru,numberSwapped,
    22102182  //     fabs(dualOut_)*theta_,objectiveValue()+(fabs(dualOut_)-useThru)*theta_,useThru);
    2211   objectiveChange_ = (fabs(dualOut_)-useThru)*theta_;
    2212   rawObjectiveValue_+= objectiveChange_;
     2183  objectiveChange_ = (fabs(dualOut_) - useThru) * theta_;
     2184  rawObjectiveValue_ += objectiveChange_;
    22132185  //CoinZeroN(array, maximumNumberInList);
    22142186  //candidateList.setNumElements(0);
     
    22182190    flipList.setPackedMode(true);
    22192191#ifdef PRINT_RATIO_PROGRESS
    2220   printf("%d flipped\n",numberSwapped);
     2192  printf("%d flipped\n", numberSwapped);
    22212193#endif
    22222194}
    22232195/* Checks if tentative optimal actually means unbounded
    22242196   Returns -3 if not, 2 if is unbounded */
    2225 int
    2226 AbcSimplexDual::checkUnbounded(CoinIndexedVector & ray,
    2227                                double changeCost)
     2197int AbcSimplexDual::checkUnbounded(CoinIndexedVector &ray,
     2198  double changeCost)
    22282199{
    22292200  int status = 2; // say unbounded
     
    22312202  // get reduced cost
    22322203  int number = ray.getNumElements();
    2233   int *  COIN_RESTRICT index = ray.getIndices();
    2234   double *  COIN_RESTRICT array = ray.denseVector();
    2235   const int * COIN_RESTRICT abcPivotVariable = abcPivotVariable_;
     2204  int *COIN_RESTRICT index = ray.getIndices();
     2205  double *COIN_RESTRICT array = ray.denseVector();
     2206  const int *COIN_RESTRICT abcPivotVariable = abcPivotVariable_;
    22362207  for (int i = 0; i < number; i++) {
    22372208    int iRow = index[i];
     
    22472218    way = -1.0;
    22482219  } else {
    2249 #if ABC_NORMAL_DEBUG>3
     2220#if ABC_NORMAL_DEBUG > 3
    22502221    printf("can't decide on up or down\n");
    22512222#endif
     
    22622233      arrayValue = 0.0;
    22632234    double newValue = solution(iPivot) + movement * arrayValue;
    2264     if (newValue > upper(iPivot) + primalTolerance_ ||
    2265         newValue < lower(iPivot) - primalTolerance_)
     2235    if (newValue > upper(iPivot) + primalTolerance_ || newValue < lower(iPivot) - primalTolerance_)
    22662236      status = -3; // not unbounded
    22672237  }
    22682238  if (status == 2) {
    22692239    // create ray
    2270     delete [] ray_;
    2271     ray_ = new double [numberColumns_];
     2240    delete[] ray_;
     2241    ray_ = new double[numberColumns_];
    22722242    CoinZeroN(ray_, numberColumns_);
    22732243    for (int i = 0; i < number; i++) {
     
    22762246      double arrayValue = array[iRow];
    22772247      if (iPivot < numberColumns_ && fabs(arrayValue) >= zeroTolerance)
    2278         ray_[iPivot] = way * array[iRow];
     2248        ray_[iPivot] = way * array[iRow];
    22792249    }
    22802250  }
     
    22822252  return status;
    22832253}
    2284 // Saves good status etc
    2285 void
    2286 AbcSimplex::saveGoodStatus()
     2254// Saves good status etc
     2255void AbcSimplex::saveGoodStatus()
    22872256{
    22882257  // save arrays
    22892258  CoinMemcpyN(internalStatus_, numberTotal_, internalStatusSaved_);
    22902259  // save costs
    2291   CoinMemcpyN(abcCost_,numberTotal_,abcCost_+2*numberTotal_);
    2292   CoinMemcpyN(abcSolution_,numberTotal_,solutionSaved_);
     2260  CoinMemcpyN(abcCost_, numberTotal_, abcCost_ + 2 * numberTotal_);
     2261  CoinMemcpyN(abcSolution_, numberTotal_, solutionSaved_);
    22932262}
    22942263// Restores previous good status and says trouble
    2295 void
    2296 AbcSimplex::restoreGoodStatus(int type)
     2264void AbcSimplex::restoreGoodStatus(int type)
    22972265{
    2298 #if PARTITION_ROW_COPY==1
     2266#if PARTITION_ROW_COPY == 1
    22992267  stateOfProblem_ |= NEED_BASIS_SORT;
    23002268#endif
     
    23042272    // trouble - restore solution
    23052273    CoinMemcpyN(internalStatusSaved_, numberTotal_, internalStatus_);
    2306     CoinMemcpyN(abcCost_+2*numberTotal_,numberTotal_,abcCost_);
    2307     CoinMemcpyN(solutionSaved_,numberTotal_, abcSolution_);
    2308     int *  COIN_RESTRICT abcPivotVariable = abcPivotVariable_;
     2274    CoinMemcpyN(abcCost_ + 2 * numberTotal_, numberTotal_, abcCost_);
     2275    CoinMemcpyN(solutionSaved_, numberTotal_, abcSolution_);
     2276    int *COIN_RESTRICT abcPivotVariable = abcPivotVariable_;
    23092277    // redo pivotVariable
    2310     int numberBasic=0;
    2311     for (int i=0;i<numberTotal_;i++) {
    2312       if (getInternalStatus(i)==basic)
    2313         abcPivotVariable[numberBasic++]=i;
    2314     }
    2315     assert (numberBasic==numberRows_);
     2278    int numberBasic = 0;
     2279    for (int i = 0; i < numberTotal_; i++) {
     2280      if (getInternalStatus(i) == basic)
     2281        abcPivotVariable[numberBasic++] = i;
     2282    }
     2283    assert(numberBasic == numberRows_);
    23162284    forceFactorization_ = 1; // a bit drastic but ..
    23172285    changeMade_++; // say something changed
    23182286  }
    23192287}
    2320 static int computePrimalsAndCheck(AbcSimplexDual * model,const int whichArray[2])
     2288static int computePrimalsAndCheck(AbcSimplexDual *model, const int whichArray[2])
    23212289{
    2322   CoinIndexedVector * array1 = model->usefulArray(whichArray[0]);
    2323   CoinIndexedVector * array2 = model->usefulArray(whichArray[1]);
    2324   int numberRefinements=model->computePrimals(array1,array2);
     2290  CoinIndexedVector *array1 = model->usefulArray(whichArray[0]);
     2291  CoinIndexedVector *array2 = model->usefulArray(whichArray[1]);
     2292  int numberRefinements = model->computePrimals(array1, array2);
    23252293  model->checkPrimalSolution(true);
    23262294  return numberRefinements;
    23272295}
    2328 static int computeDualsAndCheck(AbcSimplexDual * model,const int whichArray[2])
     2296static int computeDualsAndCheck(AbcSimplexDual *model, const int whichArray[2])
    23292297{
    2330   CoinIndexedVector * array1 = model->usefulArray(whichArray[0]);
    2331   CoinIndexedVector * array2 = model->usefulArray(whichArray[1]);
    2332   int numberRefinements=model->computeDuals(NULL,array1,array2);
     2298  CoinIndexedVector *array1 = model->usefulArray(whichArray[0]);
     2299  CoinIndexedVector *array2 = model->usefulArray(whichArray[1]);
     2300  int numberRefinements = model->computeDuals(NULL, array1, array2);
    23332301  model->checkDualSolutionPlusFake();
    23342302  return numberRefinements;
    23352303}
    23362304// Computes solutions - 1 do duals, 2 do primals, 3 both
    2337 int
    2338 AbcSimplex::gutsOfSolution(int type)
     2305int AbcSimplex::gutsOfSolution(int type)
    23392306{
    2340   double oldLargestPrimalError=largestPrimalError_;
    2341   double oldLargestDualError=largestDualError_;
    2342   AbcSimplexDual * dual = reinterpret_cast<AbcSimplexDual *>(this);
     2307  double oldLargestPrimalError = largestPrimalError_;
     2308  double oldLargestDualError = largestDualError_;
     2309  AbcSimplexDual *dual = reinterpret_cast< AbcSimplexDual * >(this);
    23432310  // do work and check
    2344   int numberRefinements=0;
     2311  int numberRefinements = 0;
    23452312#if ABC_PARALLEL
    2346   if (type!=3) {
    2347 #endif
    2348     if ((type&2)!=0) {
     2313  if (type != 3) {
     2314#endif
     2315    if ((type & 2) != 0) {
    23492316      //work space
    23502317      int whichArray[2];
    2351       for (int i=0;i<2;i++)
    2352         whichArray[i]=getAvailableArray();
    2353       numberRefinements=computePrimalsAndCheck(dual,whichArray);
    2354       for (int i=0;i<2;i++)
    2355         setAvailableArray(whichArray[i]);
    2356     }
    2357     if ((type&1)!=0
    2358 #if CAN_HAVE_ZERO_OBJ>1
    2359         &&(specialOptions_&2097152)==0
    2360 #endif
    2361         ) {
     2318      for (int i = 0; i < 2; i++)
     2319        whichArray[i] = getAvailableArray();
     2320      numberRefinements = computePrimalsAndCheck(dual, whichArray);
     2321      for (int i = 0; i < 2; i++)
     2322        setAvailableArray(whichArray[i]);
     2323    }
     2324    if ((type & 1) != 0
     2325#if CAN_HAVE_ZERO_OBJ > 1
     2326      && (specialOptions_ & 2097152) == 0
     2327#endif
     2328    ) {
    23622329      //work space
    23632330      int whichArray[2];
    2364       for (int i=0;i<2;i++)
    2365         whichArray[i]=getAvailableArray();
    2366       numberRefinements+=computeDualsAndCheck(dual,whichArray);
    2367       for (int i=0;i<2;i++)
    2368         setAvailableArray(whichArray[i]);
     2331      for (int i = 0; i < 2; i++)
     2332        whichArray[i] = getAvailableArray();
     2333      numberRefinements += computeDualsAndCheck(dual, whichArray);
     2334      for (int i = 0; i < 2; i++)
     2335        setAvailableArray(whichArray[i]);
    23692336    }
    23702337#if ABC_PARALLEL
     
    23742341#endif
    23752342    // redo to do in parallel
    2376       //work space
    2377       int whichArray[5];
    2378       for (int i=1;i<5;i++)
    2379         whichArray[i]=getAvailableArray();
    2380       if (parallelMode_==0) {
    2381         numberRefinements+=computePrimalsAndCheck(dual,whichArray+3);
    2382         numberRefinements+=computeDualsAndCheck(dual,whichArray+1);
    2383       } else {
    2384 #if ABC_PARALLEL==1
    2385         threadInfo_[0].stuff[0]=whichArray[1];
    2386         threadInfo_[0].stuff[1]=whichArray[2];
    2387         stopStart_=1+32*1;
    2388         startParallelStuff(1);
     2343    //work space
     2344    int whichArray[5];
     2345    for (int i = 1; i < 5; i++)
     2346      whichArray[i] = getAvailableArray();
     2347    if (parallelMode_ == 0) {
     2348      numberRefinements += computePrimalsAndCheck(dual, whichArray + 3);
     2349      numberRefinements += computeDualsAndCheck(dual, whichArray + 1);
     2350    } else {
     2351#if ABC_PARALLEL == 1
     2352      threadInfo_[0].stuff[0] = whichArray[1];
     2353      threadInfo_[0].stuff[1] = whichArray[2];
     2354      stopStart_ = 1 + 32 * 1;
     2355      startParallelStuff(1);
    23892356#else
    2390         whichArray[0]=1;
    2391         CoinThreadInfo info;
    2392         info.status=1;
    2393         info.stuff[0]=whichArray[1];
    2394         info.stuff[1]=whichArray[2];
    2395         int n=cilk_spawn computeDualsAndCheck(dual,whichArray+1);
    2396 #endif
    2397         numberRefinements=computePrimalsAndCheck(dual,whichArray+3);
    2398 #if ABC_PARALLEL==1
    2399         numberRefinements+=stopParallelStuff(1);
     2357      whichArray[0] = 1;
     2358      CoinThreadInfo info;
     2359      info.status = 1;
     2360      info.stuff[0] = whichArray[1];
     2361      info.stuff[1] = whichArray[2];
     2362      int n = cilk_spawn computeDualsAndCheck(dual, whichArray + 1);
     2363#endif
     2364      numberRefinements = computePrimalsAndCheck(dual, whichArray + 3);
     2365#if ABC_PARALLEL == 1
     2366      numberRefinements += stopParallelStuff(1);
    24002367#else
    2401         cilk_sync;
    2402         numberRefinements+=n;
    2403 #endif
    2404       }
    2405       for (int i=1;i<5;i++)
    2406         setAvailableArray(whichArray[i]);
    2407   }
    2408 #endif
    2409   rawObjectiveValue_ +=sumNonBasicCosts_;
     2368      cilk_sync;
     2369      numberRefinements += n;
     2370#endif
     2371    }
     2372    for (int i = 1; i < 5; i++)
     2373      setAvailableArray(whichArray[i]);
     2374  }
     2375#endif
     2376  rawObjectiveValue_ += sumNonBasicCosts_;
    24102377  setClpSimplexObjectiveValue();
    2411   if (handler_->logLevel() > 3 || (largestPrimalError_ > 1.0e-2 ||
    2412                                    largestDualError_ > 1.0e-2))
     2378  if (handler_->logLevel() > 3 || (largestPrimalError_ > 1.0e-2 || largestDualError_ > 1.0e-2))
    24132379    handler_->message(CLP_SIMPLEX_ACCURACY, messages_)
    24142380      << largestPrimalError_
    24152381      << largestDualError_
    24162382      << CoinMessageEol;
    2417   if ((largestPrimalError_ > 1.0e1||largestDualError_>1.0e1)
    2418       && numberRows_ > 100 && numberIterations_) {
    2419 #if ABC_NORMAL_DEBUG>0
     2383  if ((largestPrimalError_ > 1.0e1 || largestDualError_ > 1.0e1)
     2384    && numberRows_ > 100 && numberIterations_) {
     2385#if ABC_NORMAL_DEBUG > 0
    24202386    printf("Large errors - primal %g dual %g\n",
    2421            largestPrimalError_,largestDualError_);
     2387      largestPrimalError_, largestDualError_);
    24222388#endif
    24232389    // Change factorization tolerance
     
    24252391    //abcFactorization_->zeroTolerance(1.0e-18);
    24262392  }
    2427   bool notChanged=true;
    2428   if (numberIterations_ && (forceFactorization_ > 2 || forceFactorization_<0 || abcFactorization_->pivotTolerance()<0.9899999999) &&
    2429       (oldLargestDualError||oldLargestPrimalError)) {
    2430     double useOldDualError=oldLargestDualError;
    2431     double useDualError=largestDualError_;
    2432     if (algorithm_>0&&abcNonLinearCost_&&
    2433         abcNonLinearCost_->sumInfeasibilities()) {
    2434       double factor=CoinMax(1.0,CoinMin(1.0e3,infeasibilityCost_*1.0e-6));
     2393  bool notChanged = true;
     2394  if (numberIterations_ && (forceFactorization_ > 2 || forceFactorization_ < 0 || abcFactorization_->pivotTolerance() < 0.9899999999) && (oldLargestDualError || oldLargestPrimalError)) {
     2395    double useOldDualError = oldLargestDualError;
     2396    double useDualError = largestDualError_;
     2397    if (algorithm_ > 0 && abcNonLinearCost_ && abcNonLinearCost_->sumInfeasibilities()) {
     2398      double factor = CoinMax(1.0, CoinMin(1.0e3, infeasibilityCost_ * 1.0e-6));
    24352399      useOldDualError /= factor;
    24362400      useDualError /= factor;
    24372401    }
    2438     if ((largestPrimalError_>1.0e3&&
    2439          oldLargestPrimalError*1.0e2<largestPrimalError_)||
    2440         (useDualError>1.0e3&&
    2441          useOldDualError*1.0e2<useDualError)) {
     2402    if ((largestPrimalError_ > 1.0e3 && oldLargestPrimalError * 1.0e2 < largestPrimalError_) || (useDualError > 1.0e3 && useOldDualError * 1.0e2 < useDualError)) {
    24422403      double pivotTolerance = abcFactorization_->pivotTolerance();
    2443       double factor=(largestPrimalError_>1.0e10||largestDualError_>1.0e10)
    2444         ? 2.0 : 1.2;
    2445       if (pivotTolerance<0.1)
    2446         abcFactorization_->pivotTolerance(0.1);
    2447       else if (pivotTolerance<0.98999999)
    2448         abcFactorization_->pivotTolerance(CoinMin(0.99,pivotTolerance*factor));
    2449       notChanged=pivotTolerance==abcFactorization_->pivotTolerance();
     2404      double factor = (largestPrimalError_ > 1.0e10 || largestDualError_ > 1.0e10)
     2405        ? 2.0
     2406        : 1.2;
     2407      if (pivotTolerance < 0.1)
     2408        abcFactorization_->pivotTolerance(0.1);
     2409      else if (pivotTolerance < 0.98999999)
     2410        abcFactorization_->pivotTolerance(CoinMin(0.99, pivotTolerance * factor));
     2411      notChanged = pivotTolerance == abcFactorization_->pivotTolerance();
    24502412#if defined(CLP_USEFUL_PRINTOUT) && !defined(GCC_4_9)
    2451       if (pivotTolerance<0.9899999) {
    2452         double newTolerance=abcFactorization_->pivotTolerance();
    2453         printf("Changing pivot tolerance from %g to %g and backtracking\n",
    2454                pivotTolerance,newTolerance);
    2455       } 
     2413      if (pivotTolerance < 0.9899999) {
     2414        double newTolerance = abcFactorization_->pivotTolerance();
     2415        printf("Changing pivot tolerance from %g to %g and backtracking\n",
     2416          pivotTolerance, newTolerance);
     2417      }
    24562418      printf("because old,new primal error %g,%g - dual %g,%g pivot_tol %g\n",
    2457              oldLargestPrimalError,largestPrimalError_,
    2458              oldLargestDualError,largestDualError_,
    2459              pivotTolerance);
    2460 #endif
    2461       if (pivotTolerance<0.9899999) {
    2462         //largestPrimalError_=0.0;
    2463         //largestDualError_=0.0;
    2464         //returnCode=1;
    2465       }
    2466     }
    2467   }
    2468   if (progress_.iterationNumber_[0]>0&&
    2469       progress_.iterationNumber_[CLP_PROGRESS-1]
    2470       -progress_.iterationNumber_[0]<CLP_PROGRESS*3&&
    2471       abcFactorization_->pivotTolerance()<0.25&&notChanged) {
     2419        oldLargestPrimalError, largestPrimalError_,
     2420        oldLargestDualError, largestDualError_,
     2421        pivotTolerance);
     2422#endif
     2423      if (pivotTolerance < 0.9899999) {
     2424        //largestPrimalError_=0.0;
     2425        //largestDualError_=0.0;
     2426        //returnCode=1;
     2427      }
     2428    }
     2429  }
     2430  if (progress_.iterationNumber_[0] > 0 && progress_.iterationNumber_[CLP_PROGRESS - 1] - progress_.iterationNumber_[0] < CLP_PROGRESS * 3 && abcFactorization_->pivotTolerance() < 0.25 && notChanged) {
    24722431    double pivotTolerance = abcFactorization_->pivotTolerance();
    2473     abcFactorization_->pivotTolerance(pivotTolerance*1.5);
     2432    abcFactorization_->pivotTolerance(pivotTolerance * 1.5);
    24742433#if defined(CLP_USEFUL_PRINTOUT) && !defined(GCC_4_9)
    2475     double newTolerance=abcFactorization_->pivotTolerance();
     2434    double newTolerance = abcFactorization_->pivotTolerance();
    24762435    printf("Changing pivot tolerance from %g to %g - inverting too often\n",
    2477            pivotTolerance,newTolerance);
     2436      pivotTolerance, newTolerance);
    24782437#endif
    24792438  }
     
    24812440}
    24822441// Make non free variables dual feasible by moving to a bound
    2483 int
    2484 AbcSimplexDual::makeNonFreeVariablesDualFeasible(bool changeCosts)
     2442int AbcSimplexDual::makeNonFreeVariablesDualFeasible(bool changeCosts)
    24852443{
    2486   const double multiplier[] = { 1.0, -1.0}; // sign?????????????
    2487   double dualT = - 100.0*currentDualTolerance_;
    2488   int numberMoved=0;
    2489   int numberChanged=0;
    2490   double *  COIN_RESTRICT solution = abcSolution_;
    2491   double *  COIN_RESTRICT lower = abcLower_;
    2492   double *  COIN_RESTRICT upper = abcUpper_;
    2493   double saveNonBasicCosts =sumNonBasicCosts_;
    2494   double largestCost=dualTolerance_;
     2444  const double multiplier[] = { 1.0, -1.0 }; // sign?????????????
     2445  double dualT = -100.0 * currentDualTolerance_;
     2446  int numberMoved = 0;
     2447  int numberChanged = 0;
     2448  double *COIN_RESTRICT solution = abcSolution_;
     2449  double *COIN_RESTRICT lower = abcLower_;
     2450  double *COIN_RESTRICT upper = abcUpper_;
     2451  double saveNonBasicCosts = sumNonBasicCosts_;
     2452  double largestCost = dualTolerance_;
    24952453  for (int iSequence = 0; iSequence < numberTotal_; iSequence++) {
    24962454    unsigned char iStatus = internalStatus_[iSequence] & 7;
    2497     if (iStatus<4) {
     2455    if (iStatus < 4) {
    24982456      double mult = multiplier[iStatus];
    24992457      double dj = abcDj_[iSequence] * mult;
    25002458      if (dj < dualT) {
    2501         largestCost=CoinMax(fabs(abcPerturbation_[iSequence]),largestCost);
    2502       }
    2503     } else if (iStatus!=7) {
    2504       largestCost=CoinMax(fabs(abcPerturbation_[iSequence]),largestCost);
     2459        largestCost = CoinMax(fabs(abcPerturbation_[iSequence]), largestCost);
     2460      }
     2461    } else if (iStatus != 7) {
     2462      largestCost = CoinMax(fabs(abcPerturbation_[iSequence]), largestCost);
    25052463    }
    25062464  }
    25072465  for (int iSequence = 0; iSequence < numberTotal_; iSequence++) {
    25082466    unsigned char iStatus = internalStatus_[iSequence] & 7;
    2509     if (iStatus<4) {
     2467    if (iStatus < 4) {
    25102468      double mult = multiplier[iStatus];
    25112469      double dj = abcDj_[iSequence] * mult;
    25122470      // ? should use perturbationArray
    2513       if (dj < dualT&&changeCosts) {
    2514         double gap=upper[iSequence]-lower[iSequence];
    2515         if (gap>1.1*currentDualBound_) {
    2516           assert(getFakeBound(iSequence)==AbcSimplexDual::noFake);
    2517           if (!iStatus) {
    2518             upper[iSequence]=lower[iSequence]+currentDualBound_;
    2519             setFakeBound(iSequence, AbcSimplexDual::upperFake);
    2520           } else {
    2521             lower[iSequence]=upper[iSequence]-currentDualBound_;
    2522             setFakeBound(iSequence, AbcSimplexDual::lowerFake);
    2523           }
    2524         }
    2525         double costDifference=abcPerturbation_[iSequence]-abcCost_[iSequence];
    2526         if (costDifference*mult>0.0) {
    2527 #if ABC_NORMAL_DEBUG>0
    2528           //printf("can improve situation on %d by %g\n",iSequence,costDifference*mult);
    2529 #endif
    2530           dj+=costDifference*mult;
    2531           abcDj_[iSequence]+=costDifference;
    2532           abcCost_[iSequence]=abcPerturbation_[iSequence];
    2533           costDifference=0.0;
    2534         }
    2535         double changeInObjective=-gap*dj;
    2536         // probably need to be more intelligent
    2537         if ((changeInObjective>1.0e3||gap>CoinMax(0.5*dualBound_,1.0e3))&&dj>-1.0e-1) {
    2538           // change cost
    2539           costDifference=(-dj-0.5*dualTolerance_)*mult;
    2540           if (fabs(costDifference)<100000.0*dualTolerance_) {
    2541             dj+=costDifference*mult;
    2542             abcDj_[iSequence]+=costDifference;
    2543             abcCost_[iSequence]+=costDifference;
    2544             numberChanged++;
    2545           }
    2546         }
    2547       }
    2548       if (dj < dualT&&!changeCosts) {
    2549         numberMoved++;
    2550         if (iStatus==0) {
    2551           // at lower bound
    2552           // to upper bound
    2553           setInternalStatus(iSequence, atUpperBound);
    2554           solution[iSequence] = upper[iSequence];
    2555           sumNonBasicCosts_ += abcCost_[iSequence]*(upper[iSequence]-lower[iSequence]);
    2556         } else {
    2557           // at upper bound
    2558           // to lower bound
    2559           setInternalStatus(iSequence, atLowerBound);
    2560           solution[iSequence] = lower[iSequence];
    2561           sumNonBasicCosts_ -= abcCost_[iSequence]*(upper[iSequence]-lower[iSequence]);
    2562         }
    2563       }
    2564     }
    2565   }
    2566 #if ABC_NORMAL_DEBUG>0
    2567   if (numberMoved+numberChanged)
    2568   printf("makeDualfeasible %d moved, %d had costs changed - sum dual %g\n",
    2569          numberMoved,numberChanged,sumDualInfeasibilities_);
    2570 #endif
    2571   rawObjectiveValue_ +=(sumNonBasicCosts_-saveNonBasicCosts);
     2471      if (dj < dualT && changeCosts) {
     2472        double gap = upper[iSequence] - lower[iSequence];
     2473        if (gap > 1.1 * currentDualBound_) {
     2474          assert(getFakeBound(iSequence) == AbcSimplexDual::noFake);
     2475          if (!iStatus) {
     2476            upper[iSequence] = lower[iSequence] + currentDualBound_;
     2477            setFakeBound(iSequence, AbcSimplexDual::upperFake);
     2478          } else {
     2479            lower[iSequence] = upper[iSequence] - currentDualBound_;
     2480            setFakeBound(iSequence, AbcSimplexDual::lowerFake);
     2481          }
     2482        }
     2483        double costDifference = abcPerturbation_[iSequence] - abcCost_[iSequence];
     2484        if (costDifference * mult > 0.0) {
     2485#if ABC_NORMAL_DEBUG > 0
     2486          //printf("can improve situation on %d by %g\n",iSequence,costDifference*mult);
     2487#endif
     2488          dj += costDifference * mult;
     2489          abcDj_[iSequence] += costDifference;
     2490          abcCost_[iSequence] = abcPerturbation_[iSequence];
     2491          costDifference = 0.0;
     2492        }
     2493        double changeInObjective = -gap * dj;
     2494        // probably need to be more intelligent
     2495        if ((changeInObjective > 1.0e3 || gap > CoinMax(0.5 * dualBound_, 1.0e3)) && dj > -1.0e-1) {
     2496          // change cost
     2497          costDifference = (-dj - 0.5 * dualTolerance_) * mult;
     2498          if (fabs(costDifference) < 100000.0 * dualTolerance_) {
     2499            dj += costDifference * mult;
     2500            abcDj_[iSequence] += costDifference;
     2501            abcCost_[iSequence] += costDifference;
     2502            numberChanged++;
     2503          }
     2504        }
     2505      }
     2506      if (dj < dualT && !changeCosts) {
     2507        numberMoved++;
     2508        if (iStatus == 0) {
     2509          // at lower bound
     2510          // to upper bound
     2511          setInternalStatus(iSequence, atUpperBound);
     2512          solution[iSequence] = upper[iSequence];
     2513          sumNonBasicCosts_ += abcCost_[iSequence] * (upper[iSequence] - lower[iSequence]);
     2514        } else {
     2515          // at upper bound
     2516          // to lower bound
     2517          setInternalStatus(iSequence, atLowerBound);
     2518          solution[iSequence] = lower[iSequence];
     2519          sumNonBasicCosts_ -= abcCost_[iSequence] * (upper[iSequence] - lower[iSequence]);
     2520        }
     2521      }
     2522    }
     2523  }
     2524#if ABC_NORMAL_DEBUG > 0
     2525  if (numberMoved + numberChanged)
     2526    printf("makeDualfeasible %d moved, %d had costs changed - sum dual %g\n",
     2527      numberMoved, numberChanged, sumDualInfeasibilities_);
     2528#endif
     2529  rawObjectiveValue_ += (sumNonBasicCosts_ - saveNonBasicCosts);
    25722530  setClpSimplexObjectiveValue();
    25732531  return numberMoved;
    25742532}
    2575 int
    2576 AbcSimplexDual::whatNext()
     2533int AbcSimplexDual::whatNext()
    25772534{
    2578   int returnCode=0;
    2579   assert (!stateOfIteration_);
     2535  int returnCode = 0;
     2536  assert(!stateOfIteration_);
    25802537  // see if update stable
    2581 #if ABC_NORMAL_DEBUG>3
     2538#if ABC_NORMAL_DEBUG > 3
    25822539  if ((handler_->logLevel() & 32))
    25832540    printf("btran alpha %g, ftran alpha %g\n", btranAlpha_, alpha_);
    25842541#endif
    2585   int numberPivots=abcFactorization_->pivots();
     2542  int numberPivots = abcFactorization_->pivots();
    25862543  //double checkValue = 1.0e-7; // numberPivots<5 ? 1.0e-7 : 1.0e-6;
    25872544  double checkValue = numberPivots ? 1.0e-7 : 1.0e-5;
    25882545  // relax if free variable in
    2589   if ((internalStatus_[sequenceIn_]&7)>1)
    2590     checkValue=1.0e-5;
     2546  if ((internalStatus_[sequenceIn_] & 7) > 1)
     2547    checkValue = 1.0e-5;
    25912548  // if can't trust much and long way from optimal then relax
    25922549  if (largestPrimalError_ > 10.0)
    25932550    checkValue = CoinMin(1.0e-4, 1.0e-8 * largestPrimalError_);
    2594   if (fabs(btranAlpha_) < 1.0e-12 || fabs(alpha_) < 1.0e-12 ||
    2595       fabs(btranAlpha_ - alpha_) > checkValue*(1.0 + fabs(alpha_))) {
     2551  if (fabs(btranAlpha_) < 1.0e-12 || fabs(alpha_) < 1.0e-12 || fabs(btranAlpha_ - alpha_) > checkValue * (1.0 + fabs(alpha_))) {
    25962552    handler_->message(CLP_DUAL_CHECK, messages_)
    25972553      << btranAlpha_
     
    26032559      test = 1.0e-1 * fabs(alpha_);
    26042560    else
    2605       test = 10.0*checkValue;//1.0e-4 * (1.0 + fabs(alpha_));
    2606     bool needFlag = (fabs(btranAlpha_) < 1.0e-12 || fabs(alpha_) < 1.0e-12 ||
    2607                      fabs(btranAlpha_ - alpha_) > test);
    2608 #if ABC_NORMAL_DEBUG>0
    2609     if (fabs(btranAlpha_ + alpha_) < 1.0e-5*(1.0 + fabs(alpha_))) {
    2610       printf("alpha diff (%g,%g) %g check %g\n",btranAlpha_,alpha_,fabs(btranAlpha_-alpha_),checkValue*(1.0+fabs(alpha_)));
     2561      test = 10.0 * checkValue; //1.0e-4 * (1.0 + fabs(alpha_));
     2562    bool needFlag = (fabs(btranAlpha_) < 1.0e-12 || fabs(alpha_) < 1.0e-12 || fabs(btranAlpha_ - alpha_) > test);
     2563#if ABC_NORMAL_DEBUG > 0
     2564    if (fabs(btranAlpha_ + alpha_) < 1.0e-5 * (1.0 + fabs(alpha_))) {
     2565      printf("alpha diff (%g,%g) %g check %g\n", btranAlpha_, alpha_, fabs(btranAlpha_ - alpha_), checkValue * (1.0 + fabs(alpha_)));
    26112566    }
    26122567#endif
    26132568    if (numberPivots) {
    2614       if (needFlag&&numberPivots<10) {
    2615         // need to reject something
    2616         assert (sequenceOut_>=0);
    2617         char x = isColumn(sequenceOut_) ? 'C' : 'R';
    2618         handler_->message(CLP_SIMPLEX_FLAG, messages_)
    2619           << x << sequenceWithin(sequenceOut_)
    2620           << CoinMessageEol;
    2621 #if ABC_NORMAL_DEBUG>0
    2622         printf("flag %d as alpha  %g %g - after %d pivots\n", sequenceOut_,
    2623                btranAlpha_, alpha_,numberPivots);
    2624 #endif
    2625         // Make safer?
    2626         abcFactorization_->saferTolerances (1.0, -1.03);
    2627         setFlagged(sequenceOut_);
    2628         // so can't happen immediately again
    2629         sequenceOut_=-1;
    2630         lastBadIteration_ = numberIterations_; // say be more cautious
     2569      if (needFlag && numberPivots < 10) {
     2570        // need to reject something
     2571        assert(sequenceOut_ >= 0);
     2572        char x = isColumn(sequenceOut_) ? 'C' : 'R';
     2573        handler_->message(CLP_SIMPLEX_FLAG, messages_)
     2574          << x << sequenceWithin(sequenceOut_)
     2575          << CoinMessageEol;
     2576#if ABC_NORMAL_DEBUG > 0
     2577        printf("flag %d as alpha  %g %g - after %d pivots\n", sequenceOut_,
     2578          btranAlpha_, alpha_, numberPivots);
     2579#endif
     2580        // Make safer?
     2581        abcFactorization_->saferTolerances(1.0, -1.03);
     2582        setFlagged(sequenceOut_);
     2583        // so can't happen immediately again
     2584        sequenceOut_ = -1;
     2585        lastBadIteration_ = numberIterations_; // say be more cautious
    26312586      }
    26322587      // Make safer?
     
    26352590      problemStatus_ = -2; // factorize now
    26362591      returnCode = -2;
    2637       stateOfIteration_=2;
     2592      stateOfIteration_ = 2;
    26382593    } else {
    26392594      if (needFlag) {
    2640         // need to reject something
    2641         assert (sequenceOut_>=0);
    2642         char x = isColumn(sequenceOut_) ? 'C' : 'R';
    2643         handler_->message(CLP_SIMPLEX_FLAG, messages_)
    2644           << x << sequenceWithin(sequenceOut_)
    2645           << CoinMessageEol;
    2646 #if ABC_NORMAL_DEBUG>3
    2647         printf("flag a %g %g\n", btranAlpha_, alpha_);
    2648 #endif
    2649         // Make safer?
    2650         double tolerance=abcFactorization_->pivotTolerance();
    2651         abcFactorization_->saferTolerances (1.0, -1.03);
    2652         setFlagged(sequenceOut_);
    2653         // so can't happen immediately again
    2654         sequenceOut_=-1;
    2655         //abcProgress_.clearBadTimes();
    2656         lastBadIteration_ = numberIterations_; // say be more cautious
    2657         if (fabs(alpha_) < 1.0e-10 && fabs(btranAlpha_) < 1.0e-8 && numberIterations_ > 100) {
    2658           //printf("I think should declare infeasible\n");
    2659           problemStatus_ = 1;
    2660           returnCode = 1;
    2661           stateOfIteration_=2;
    2662         } else {
    2663           stateOfIteration_=1;
    2664           if (tolerance<abcFactorization_->pivotTolerance()) {
    2665             stateOfIteration_=2;
    2666             returnCode=-2;
    2667           }
    2668         }
     2595        // need to reject something
     2596        assert(sequenceOut_ >= 0);
     2597        char x = isColumn(sequenceOut_) ? 'C' : 'R';
     2598        handler_->message(CLP_SIMPLEX_FLAG, messages_)
     2599          << x << sequenceWithin(sequenceOut_)
     2600          << CoinMessageEol;
     2601#if ABC_NORMAL_DEBUG > 3
     2602        printf("flag a %g %g\n", btranAlpha_, alpha_);
     2603#endif
     2604        // Make safer?
     2605        double tolerance = abcFactorization_->pivotTolerance();
     2606        abcFactorization_->saferTolerances(1.0, -1.03);
     2607        setFlagged(sequenceOut_);
     2608        // so can't happen immediately again
     2609        sequenceOut_ = -1;
     2610        //abcProgress_.clearBadTimes();
     2611        lastBadIteration_ = numberIterations_; // say be more cautious
     2612        if (fabs(alpha_) < 1.0e-10 && fabs(btranAlpha_) < 1.0e-8 && numberIterations_ > 100) {
     2613          //printf("I think should declare infeasible\n");
     2614          problemStatus_ = 1;
     2615          returnCode = 1;
     2616          stateOfIteration_ = 2;
     2617        } else {
     2618          stateOfIteration_ = 1;
     2619          if (tolerance < abcFactorization_->pivotTolerance()) {
     2620            stateOfIteration_ = 2;
     2621            returnCode = -2;
     2622          }
     2623        }
    26692624      }
    26702625    }
     
    26722627  if (!stateOfIteration_) {
    26732628    // check update
    2674     returnCode=abcFactorization_->checkReplacePart2(pivotRow_,btranAlpha_,alpha_,ftAlpha_);
     2629    returnCode = abcFactorization_->checkReplacePart2(pivotRow_, btranAlpha_, alpha_, ftAlpha_);
    26752630  }
    26762631  return returnCode;
     
    26822637   3 can skip factorization
    26832638   Updates status */
    2684 void
    2685 AbcSimplexDual::statusOfProblemInDual(int type)
     2639void AbcSimplexDual::statusOfProblemInDual(int type)
    26862640{
    26872641  // If lots of iterations then adjust costs if large ones
     
    26912645         numberPivots,type,problemStatus_,forceFactorization_,dontFactorizePivots_);
    26922646#endif
    2693   int saveType=type;
    2694   double lastSumDualInfeasibilities=sumDualInfeasibilities_;
    2695   double lastSumPrimalInfeasibilities=sumPrimalInfeasibilities_;
    2696   if (type>=4) {
     2647  int saveType = type;
     2648  double lastSumDualInfeasibilities = sumDualInfeasibilities_;
     2649  double lastSumPrimalInfeasibilities = sumPrimalInfeasibilities_;
     2650  if (type >= 4) {
    26972651    // force factorization
    26982652    type &= 3;
    2699     numberPivots=9999999;
     2653    numberPivots = 9999999;
    27002654  }
    27012655  //double realDualInfeasibilities = 0.0;
    27022656  double changeCost;
    2703   bool unflagVariables = numberFlagged_>0;
     2657  bool unflagVariables = numberFlagged_ > 0;
    27042658  int weightsSaved = 0;
    2705   int numberBlackMarks=0;
     2659  int numberBlackMarks = 0;
    27062660  if (!type) {
    27072661    // be optimistic
     
    27112665    abcFactorization_->pivotTolerance(newTolerance);
    27122666  }
    2713   if (type != 3&&(numberPivots>dontFactorizePivots_||numberIterations_==baseIteration_)) {
     2667  if (type != 3 && (numberPivots > dontFactorizePivots_ || numberIterations_ == baseIteration_)) {
    27142668    // factorize
    27152669    // save dual weights
     
    27172671    weightsSaved = 2;
    27182672    // is factorization okay?
    2719     int factorizationStatus=0;
    2720   if ((largestPrimalError_ > 1.0e1||largestDualError_>1.0e1)
    2721       && numberRows_ > 100 && numberIterations_>baseIteration_) {
    2722     double newTolerance = CoinMin(1.1* abcFactorization_->pivotTolerance(), 0.99);
    2723     abcFactorization_->pivotTolerance(newTolerance);
    2724   }
     2673    int factorizationStatus = 0;
     2674    if ((largestPrimalError_ > 1.0e1 || largestDualError_ > 1.0e1)
     2675      && numberRows_ > 100 && numberIterations_ > baseIteration_) {
     2676      double newTolerance = CoinMin(1.1 * abcFactorization_->pivotTolerance(), 0.99);
     2677      abcFactorization_->pivotTolerance(newTolerance);
     2678    }
    27252679#ifdef EARLY_FACTORIZE
    2726     if ((numberEarly_&0xffff)<=5||!usefulArray_[ABC_NUMBER_USEFUL-1].getNumElements()) {
    2727         //#define KEEP_TRYING_EARLY
     2680    if ((numberEarly_ & 0xffff) <= 5 || !usefulArray_[ABC_NUMBER_USEFUL - 1].getNumElements()) {
     2681      //#define KEEP_TRYING_EARLY
    27282682#ifdef KEEP_TRYING_EARLY
    2729       int savedEarly=numberEarly_>>16;
    2730       int newEarly=(numberEarly_&0xffff);
    2731       newEarly=CoinMin(savedEarly,1+2*newEarly);
    2732       numberEarly_=(savedEarly<<16)|newEarly;
     2683      int savedEarly = numberEarly_ >> 16;
     2684      int newEarly = (numberEarly_ & 0xffff);
     2685      newEarly = CoinMin(savedEarly, 1 + 2 * newEarly);
     2686      numberEarly_ = (savedEarly << 16) | newEarly;
    27332687#endif
    27342688      factorizationStatus = internalFactorize(type ? 1 : 2);
    27352689    } else {
    2736       CoinIndexedVector & vector = usefulArray_[ABC_NUMBER_USEFUL-1];
    2737       bool bad = vector.getNumElements()<0;
    2738       const int * indices = vector.getIndices();
    2739       double * array = vector.denseVector();
     2690      CoinIndexedVector &vector = usefulArray_[ABC_NUMBER_USEFUL - 1];
     2691      bool bad = vector.getNumElements() < 0;
     2692      const int *indices = vector.getIndices();
     2693      double *array = vector.denseVector();
    27402694      int capacity = vector.capacity();
    27412695      capacity--;
    27422696      int numberPivotsStored = indices[capacity];
    2743 #if ABC_NORMAL_DEBUG>0
    2744       printf("early status %s nPivots %d\n",bad ? "bad" : "good",numberPivotsStored);
     2697#if ABC_NORMAL_DEBUG > 0
     2698      printf("early status %s nPivots %d\n", bad ? "bad" : "good", numberPivotsStored);
    27452699#endif
    27462700      if (!bad) {
    2747         // do remaining pivots
    2748         int iterationsDone=abcEarlyFactorization_->pivots();
    2749         factorizationStatus =
    2750           abcEarlyFactorization_->replaceColumns(this,vector,
    2751                                                  iterationsDone,numberPivotsStored,true);
    2752         if (!factorizationStatus) {
    2753           // should be able to compare e.g. basics 1.0
     2701        // do remaining pivots
     2702        int iterationsDone = abcEarlyFactorization_->pivots();
     2703        factorizationStatus = abcEarlyFactorization_->replaceColumns(this, vector,
     2704          iterationsDone, numberPivotsStored, true);
     2705        if (!factorizationStatus) {
     2706          // should be able to compare e.g. basics 1.0
    27542707#define GOOD_EARLY
    27552708#ifdef GOOD_EARLY
    2756           AbcSimplexFactorization * temp = abcFactorization_;
    2757           abcFactorization_=abcEarlyFactorization_;
    2758           abcEarlyFactorization_=temp;
    2759 #endif
    2760           moveToBasic();
     2709          AbcSimplexFactorization *temp = abcFactorization_;
     2710          abcFactorization_ = abcEarlyFactorization_;
     2711          abcEarlyFactorization_ = temp;
     2712#endif
     2713          moveToBasic();
    27612714#ifndef GOOD_EARLY
    2762           int * pivotSave = CoinCopyOfArray(abcPivotVariable_,numberRows_);
    2763           factorizationStatus = internalFactorize(type ? 1 : 2);
    2764           {
    2765             double * array = usefulArray_[3].denseVector();
    2766             double * array2 = usefulArray_[4].denseVector();
    2767             for (int iPivot = 0; iPivot < numberRows_; iPivot++) {
    2768               int iSequence = abcPivotVariable_[iPivot];
    2769               unpack(usefulArray_[3], iSequence);
    2770               unpack(usefulArray_[4], iSequence);
    2771               abcFactorization_->updateColumn(usefulArray_[3]);
    2772               abcEarlyFactorization_->updateColumn(usefulArray_[4]);
    2773               assert (fabs(array[iPivot] - 1.0) < 1.0e-4);
    2774               array[iPivot] = 0.0;
    2775               int iPivot2;
    2776               for (iPivot2=0;iPivot2<numberRows_;iPivot2++) {
    2777                 if (pivotSave[iPivot2]==iSequence)
    2778                   break;
    2779               }
    2780               assert (iPivot2<numberRows_);
    2781               assert (fabs(array2[iPivot2] - 1.0) < 1.0e-4);
    2782               array2[iPivot2] = 0.0;
    2783               for (int i = 0; i < numberRows_; i++)
    2784                 assert (fabs(array[i]) < 1.0e-4);
    2785               for (int i = 0; i < numberRows_; i++)
    2786                 assert (fabs(array2[i]) < 1.0e-4);
    2787               usefulArray_[3].clear();
    2788               usefulArray_[4].clear();
    2789             }
    2790             delete [] pivotSave;
    2791           }
    2792 #endif
    2793         } else {
    2794           bad=true;
    2795         }
     2715          int *pivotSave = CoinCopyOfArray(abcPivotVariable_, numberRows_);
     2716          factorizationStatus = internalFactorize(type ? 1 : 2);
     2717          {
     2718            double *array = usefulArray_[3].denseVector();
     2719            double *array2 = usefulArray_[4].denseVector();
     2720            for (int iPivot = 0; iPivot < numberRows_; iPivot++) {
     2721              int iSequence = abcPivotVariable_[iPivot];
     2722              unpack(usefulArray_[3], iSequence);
     2723              unpack(usefulArray_[4], iSequence);
     2724              abcFactorization_->updateColumn(usefulArray_[3]);
     2725              abcEarlyFactorization_->updateColumn(usefulArray_[4]);
     2726              assert(fabs(array[iPivot] - 1.0) < 1.0e-4);
     2727              array[iPivot] = 0.0;
     2728              int iPivot2;
     2729              for (iPivot2 = 0; iPivot2 < numberRows_; iPivot2++) {
     2730                if (pivotSave[iPivot2] == iSequence)
     2731                  break;
     2732              }
     2733              assert(iPivot2 < numberRows_);
     2734              assert(fabs(array2[iPivot2] - 1.0) < 1.0e-4);
     2735              array2[iPivot2] = 0.0;
     2736              for (int i = 0; i < numberRows_; i++)
     2737                assert(fabs(array[i]) < 1.0e-4);
     2738              for (int i = 0; i < numberRows_; i++)
     2739                assert(fabs(array2[i]) < 1.0e-4);
     2740              usefulArray_[3].clear();
     2741              usefulArray_[4].clear();
     2742            }
     2743            delete[] pivotSave;
     2744          }
     2745#endif
     2746        } else {
     2747          bad = true;
     2748        }
    27962749      }
    27972750      // clean up
    27982751      vector.setNumElements(0);
    2799       for (int i=0;i<2*numberPivotsStored;i++) {
    2800         array[--capacity]=0.0;
     2752      for (int i = 0; i < 2 * numberPivotsStored; i++) {
     2753        array[--capacity] = 0.0;
    28012754      }
    28022755      if (bad) {
    2803         // switch off
    2804 #if ABC_NORMAL_DEBUG>0
    2805         printf("switching off early factorization(in statusOf)\n");
     2756        // switch off
     2757#if ABC_NORMAL_DEBUG > 0
     2758        printf("switching off early factorization(in statusOf)\n");
    28062759#endif
    28072760#ifndef KEEP_TRYING_EARLY
    2808         numberEarly_=0;
    2809         delete abcEarlyFactorization_;
    2810         abcEarlyFactorization_=NULL;
     2761        numberEarly_ = 0;
     2762        delete abcEarlyFactorization_;
     2763        abcEarlyFactorization_ = NULL;
    28112764#else
    2812         numberEarly_&=0xffff0000;
    2813 #endif
    2814         factorizationStatus = internalFactorize(1);
     2765        numberEarly_ &= 0xffff0000;
     2766#endif
     2767        factorizationStatus = internalFactorize(1);
    28152768      }
    28162769    }
     
    28192772#endif
    28202773    if (factorizationStatus) {
    2821       if (type == 1&&lastFlaggedIteration_!=1) {
    2822         // use for real disaster
    2823         lastFlaggedIteration_ = 1;
    2824         // no - restore previous basis
    2825         unflagVariables = false;
    2826         // restore weights
    2827         weightsSaved = 4;
    2828         changeMade_++; // say something changed
    2829         // Keep any flagged variables
    2830         for (int i = 0; i < numberTotal_; i++) {
    2831           if (flagged(i))
    2832             internalStatusSaved_[i] |= 64; //say flagged
    2833         }
    2834         restoreGoodStatus(type);
    2835         // get correct bounds on all variables
    2836         resetFakeBounds(1);
    2837         numberBlackMarks=10;
    2838         if (sequenceOut_>=0) {
    2839           // need to reject something
    2840           char x = isColumn(sequenceOut_) ? 'C' : 'R';
    2841           handler_->message(CLP_SIMPLEX_FLAG, messages_)
    2842             << x << sequenceWithin(sequenceOut_)
    2843             << CoinMessageEol;
    2844 #if ABC_NORMAL_DEBUG>3
    2845           printf("flag d\n");
    2846 #endif
    2847           setFlagged(sequenceOut_);
    2848           lastBadIteration_ = numberIterations_; // say be more cautious
    2849           // so can't happen immediately again
    2850           sequenceOut_=-1;
    2851         }
    2852         //abcProgress_.clearBadTimes();
    2853        
    2854         // Go to safe
    2855         abcFactorization_->pivotTolerance(0.99);
     2774      if (type == 1 && lastFlaggedIteration_ != 1) {
     2775        // use for real disaster
     2776        lastFlaggedIteration_ = 1;
     2777        // no - restore previous basis
     2778        unflagVariables = false;
     2779        // restore weights
     2780        weightsSaved = 4;
     2781        changeMade_++; // say something changed
     2782        // Keep any flagged variables
     2783        for (int i = 0; i < numberTotal_; i++) {
     2784          if (flagged(i))
     2785            internalStatusSaved_[i] |= 64; //say flagged
     2786        }
     2787        restoreGoodStatus(type);
     2788        // get correct bounds on all variables
     2789        resetFakeBounds(1);
     2790        numberBlackMarks = 10;
     2791        if (sequenceOut_ >= 0) {
     2792          // need to reject something
     2793          char x = isColumn(sequenceOut_) ? 'C' : 'R';
     2794          handler_->message(CLP_SIMPLEX_FLAG, messages_)
     2795            << x << sequenceWithin(sequenceOut_)
     2796            << CoinMessageEol;
     2797#if ABC_NORMAL_DEBUG > 3
     2798          printf("flag d\n");
     2799#endif
     2800          setFlagged(sequenceOut_);
     2801          lastBadIteration_ = numberIterations_; // say be more cautious
     2802          // so can't happen immediately again
     2803          sequenceOut_ = -1;
     2804        }
     2805        //abcProgress_.clearBadTimes();
     2806
     2807        // Go to safe
     2808        abcFactorization_->pivotTolerance(0.99);
    28562809      } else {
    2857 #if ABC_NORMAL_DEBUG>0
    2858         printf("Bad initial basis\n");
     2810#if ABC_NORMAL_DEBUG > 0
     2811        printf("Bad initial basis\n");
    28592812#endif
    28602813      }
    28612814      if (internalFactorize(1)) {
    2862         // try once more
    2863       if (internalFactorize(0))
    2864         abort();
    2865       }
    2866 #if PARTITION_ROW_COPY==1
    2867       int iVector=getAvailableArray();
     2815        // try once more
     2816        if (internalFactorize(0))
     2817          abort();
     2818      }
     2819#if PARTITION_ROW_COPY == 1
     2820      int iVector = getAvailableArray();
    28682821      abcMatrix_->sortUseful(usefulArray_[iVector]);
    28692822      setAvailableArray(iVector);
     
    28742827  }
    28752828  // get primal and dual solutions
    2876   numberBlackMarks+=gutsOfSolution(3)/2;
    2877   assert (type!=0||numberIterations_==baseIteration_); // may be wrong
     2829  numberBlackMarks += gutsOfSolution(3) / 2;
     2830  assert(type != 0 || numberIterations_ == baseIteration_); // may be wrong
    28782831  if (!type) {
    2879     initialSumInfeasibilities_=sumPrimalInfeasibilities_;
    2880     initialNumberInfeasibilities_=numberPrimalInfeasibilities_;
    2881     CoinAbcMemcpy(solutionSaved_+numberTotal_,abcSolution_,numberTotal_);
    2882     CoinAbcMemcpy(internalStatusSaved_+numberTotal_,internalStatus_,numberTotal_);
    2883   }
    2884   double savePrimalInfeasibilities=sumPrimalInfeasibilities_;
    2885   if ((moreSpecialOptions_&16384)!=0&&(moreSpecialOptions_&8192)==0) {
    2886     if (numberIterations_==baseIteration_) {
     2832    initialSumInfeasibilities_ = sumPrimalInfeasibilities_;
     2833    initialNumberInfeasibilities_ = numberPrimalInfeasibilities_;
     2834    CoinAbcMemcpy(solutionSaved_ + numberTotal_, abcSolution_, numberTotal_);
     2835    CoinAbcMemcpy(internalStatusSaved_ + numberTotal_, internalStatus_, numberTotal_);
     2836  }
     2837  double savePrimalInfeasibilities = sumPrimalInfeasibilities_;
     2838  if ((moreSpecialOptions_ & 16384) != 0 && (moreSpecialOptions_ & 8192) == 0) {
     2839    if (numberIterations_ == baseIteration_) {
    28872840      // If primal feasible and looks suited to primal go to primal
    2888       if (!sumPrimalInfeasibilities_&&sumDualInfeasibilities_>1.0&&
    2889           numberRows_*4>numberColumns_) {
    2890         // do primal
    2891         // mark so can perturb
    2892         initialSumInfeasibilities_=-1.0;
    2893         problemStatus_=10;
    2894         return;
    2895       }
    2896     } else if ((numberIterations_>1000&&
    2897                numberIterations_*10>numberRows_&&numberIterations_*4<numberRows_)||(sumPrimalInfeasibilities_+sumDualInfeasibilities_>
    2898                                                                                     1.0e10*(initialSumInfeasibilities_+1000.0)&&numberIterations_>10000&&sumDualInfeasibilities_>1.0))
    2899  {
    2900       if (sumPrimalInfeasibilities_+1.0e2*sumDualInfeasibilities_>
    2901           2000.0*(initialSumInfeasibilities_+100.0)) {
    2902 #if ABC_NORMAL_DEBUG>0
    2903         printf ("sump %g sumd %g initial %g\n",sumPrimalInfeasibilities_,sumDualInfeasibilities_,
    2904                 initialSumInfeasibilities_);
    2905 #endif
    2906         // but only if average gone up as well
    2907         if (sumPrimalInfeasibilities_*initialNumberInfeasibilities_>
    2908             100.0*(initialSumInfeasibilities_+10.0)*numberPrimalInfeasibilities_) {
    2909 #if ABC_NORMAL_DEBUG>0
    2910           printf("returning to do primal\n");
    2911 #endif
    2912           // do primal
    2913           problemStatus_=10;
    2914           CoinAbcMemcpy(abcSolution_,solutionSaved_+numberTotal_,numberTotal_);
    2915           CoinAbcMemcpy(internalStatus_,internalStatusSaved_+numberTotal_,numberTotal_);
    2916           // mark so can perturb
    2917           initialSumInfeasibilities_=-1.0;
    2918           return;
    2919         }
    2920       }
    2921     }
    2922   } else if ((sumPrimalInfeasibilities_+sumDualInfeasibilities_>
    2923              1.0e6*(initialSumInfeasibilities_+1000.0)&&(moreSpecialOptions_&8192)==0&&
    2924              numberIterations_>1000&&
    2925               numberIterations_*10>numberRows_&&numberIterations_*4<numberRows_)||
    2926              (sumPrimalInfeasibilities_+sumDualInfeasibilities_>
    2927               1.0e10*(initialSumInfeasibilities_+1000.0)&&(moreSpecialOptions_&8192)==0&&
    2928               numberIterations_>10000&&sumDualInfeasibilities_>1.0)) {
     2841      if (!sumPrimalInfeasibilities_ && sumDualInfeasibilities_ > 1.0 && numberRows_ * 4 > numberColumns_) {
     2842        // do primal
     2843        // mark so can perturb
     2844        initialSumInfeasibilities_ = -1.0;
     2845        problemStatus_ = 10;
     2846        return;
     2847      }
     2848    } else if ((numberIterations_ > 1000 && numberIterations_ * 10 > numberRows_ && numberIterations_ * 4 < numberRows_) || (sumPrimalInfeasibilities_ + sumDualInfeasibilities_ > 1.0e10 * (initialSumInfeasibilities_ + 1000.0) && numberIterations_ > 10000 && sumDualInfeasibilities_ > 1.0)) {
     2849      if (sumPrimalInfeasibilities_ + 1.0e2 * sumDualInfeasibilities_ > 2000.0 * (initialSumInfeasibilities_ + 100.0)) {
     2850#if ABC_NORMAL_DEBUG > 0
     2851        printf("sump %g sumd %g initial %g\n", sumPrimalInfeasibilities_, sumDualInfeasibilities_,
     2852          initialSumInfeasibilities_);
     2853#endif
     2854        // but only if average gone up as well
     2855        if (sumPrimalInfeasibilities_ * initialNumberInfeasibilities_ > 100.0 * (initialSumInfeasibilities_ + 10.0) * numberPrimalInfeasibilities_) {
     2856#if ABC_NORMAL_DEBUG > 0
     2857          printf("returning to do primal\n");
     2858#endif
     2859          // do primal
     2860          problemStatus_ = 10;
     2861          CoinAbcMemcpy(abcSolution_, solutionSaved_ + numberTotal_, numberTotal_);
     2862          CoinAbcMemcpy(internalStatus_, internalStatusSaved_ + numberTotal_, numberTotal_);
     2863          // mark so can perturb
     2864          initialSumInfeasibilities_ = -1.0;
     2865          return;
     2866        }
     2867      }
     2868    }
     2869  } else if ((sumPrimalInfeasibilities_ + sumDualInfeasibilities_ > 1.0e6 * (initialSumInfeasibilities_ + 1000.0) && (moreSpecialOptions_ & 8192) == 0 && numberIterations_ > 1000 && numberIterations_ * 10 > numberRows_ && numberIterations_ * 4 < numberRows_) || (sumPrimalInfeasibilities_ + sumDualInfeasibilities_ > 1.0e10 * (initialSumInfeasibilities_ + 1000.0) && (moreSpecialOptions_ & 8192) == 0 && numberIterations_ > 10000 && sumDualInfeasibilities_ > 1.0)) {
    29292870    // do primal
    2930     problemStatus_=10;
    2931     CoinAbcMemcpy(abcSolution_,solutionSaved_+numberTotal_,numberTotal_);
    2932     CoinAbcMemcpy(internalStatus_,internalStatusSaved_+numberTotal_,numberTotal_);
     2871    problemStatus_ = 10;
     2872    CoinAbcMemcpy(abcSolution_, solutionSaved_ + numberTotal_, numberTotal_);
     2873    CoinAbcMemcpy(internalStatus_, internalStatusSaved_ + numberTotal_, numberTotal_);
    29332874    // mark so can perturb
    2934     initialSumInfeasibilities_=-1.0;
     2875    initialSumInfeasibilities_ = -1.0;
    29352876    return;
    29362877  }
    29372878  //double saveDualInfeasibilities=sumDualInfeasibilities_;
    29382879  // 0 don't ignore, 1 ignore errors, 2 values pass
    2939   int ignoreStuff=(firstFree_<0&&lastFirstFree_<0) ? 0 : 1;
    2940   if ((stateOfProblem_&VALUES_PASS)!=0)
    2941     ignoreStuff=2;
     2880  int ignoreStuff = (firstFree_ < 0 && lastFirstFree_ < 0) ? 0 : 1;
     2881  if ((stateOfProblem_ & VALUES_PASS) != 0)
     2882    ignoreStuff = 2;
    29422883  {
    29432884    double thisObj = rawObjectiveValue();
    29442885    double lastObj = abcProgress_.lastObjective(0);
    2945     if ((lastObj > thisObj + 1.0e-3 * CoinMax(fabs(thisObj), fabs(lastObj)) + 1.0e-4||
    2946          (sumPrimalInfeasibilities_>10.0*lastSumPrimalInfeasibilities+1.0e3&&
    2947           sumDualInfeasibilities_>10.0*CoinMax(lastSumDualInfeasibilities,1.0)))
    2948         &&!ignoreStuff) {
    2949 #if ABC_NORMAL_DEBUG>0
    2950       printf("bad - objective backwards %g %g errors %g %g suminf %g %g\n",lastObj,thisObj,largestDualError_,largestPrimalError_,sumDualInfeasibilities_,sumPrimalInfeasibilities_);
     2886    if ((lastObj > thisObj + 1.0e-3 * CoinMax(fabs(thisObj), fabs(lastObj)) + 1.0e-4 || (sumPrimalInfeasibilities_ > 10.0 * lastSumPrimalInfeasibilities + 1.0e3 && sumDualInfeasibilities_ > 10.0 * CoinMax(lastSumDualInfeasibilities, 1.0)))
     2887      && !ignoreStuff) {
     2888#if ABC_NORMAL_DEBUG > 0
     2889      printf("bad - objective backwards %g %g errors %g %g suminf %g %g\n", lastObj, thisObj, largestDualError_, largestPrimalError_, sumDualInfeasibilities_, sumPrimalInfeasibilities_);
    29512890#endif
    29522891      numberBlackMarks++;
    2953       if (largestDualError_>1.0e-3||largestPrimalError_>1.0e-3||
    2954           (sumDualInfeasibilities_>10.0*CoinMax(lastSumDualInfeasibilities,1.0)
    2955            &&firstFree_<0)) {
    2956 #if ABC_NORMAL_DEBUG>0
    2957         printf("backtracking %d iterations - dual error %g primal error %g - sumDualInf %g\n",
    2958                numberPivots,
    2959                largestDualError_,largestPrimalError_,sumDualInfeasibilities_);
    2960 #endif
    2961         // restore previous basis
    2962         unflagVariables = false;
    2963         // restore weights
    2964         weightsSaved = 4;
    2965         changeMade_++; // say something changed
    2966         // Keep any flagged variables
    2967         for (int i = 0; i < numberTotal_; i++) {
    2968           if (flagged(i))
    2969             internalStatusSaved_[i] |= 64; //say flagged
    2970         }
    2971         restoreGoodStatus(type);
    2972         // get correct bounds on all variables
    2973         resetFakeBounds(1);
    2974         numberBlackMarks+=10;
    2975         if (sequenceOut_>=0) {
    2976           // need to reject something
    2977 #if ABC_NORMAL_DEBUG>0
    2978           if (flagged(sequenceOut_))
    2979             printf("BAD %x already flagged\n",sequenceOut_);
    2980 #endif
    2981           char x = isColumn(sequenceOut_) ? 'C' : 'R';
    2982           handler_->message(CLP_SIMPLEX_FLAG, messages_)
    2983             << x << sequenceWithin(sequenceOut_)
    2984             << CoinMessageEol;
    2985 #if ABC_NORMAL_DEBUG>3
    2986           printf("flag d\n");
    2987 #endif
    2988           setFlagged(sequenceOut_);
    2989           lastBadIteration_ = numberIterations_; // say be more cautious
    2990 #if ABC_NORMAL_DEBUG>0
    2991         } else {
    2992           printf("backtracking - no valid sequence out\n");
    2993 #endif
    2994         }
    2995         // so can't happen immediately again
    2996         sequenceOut_=-1;
    2997         //abcProgress_.clearBadTimes();
    2998         // Go to safe
    2999         //abcFactorization_->pivotTolerance(0.99);
    3000         if (internalFactorize(1)) {
    3001           abort();
    3002         }
    3003         moveToBasic();
    3004 #if PARTITION_ROW_COPY==1
    3005         int iVector=getAvailableArray();
    3006         abcMatrix_->sortUseful(usefulArray_[iVector]);
    3007         setAvailableArray(iVector);
    3008 #endif
    3009         // get primal and dual solutions
    3010         numberBlackMarks+=gutsOfSolution(3);
    3011         //gutsOfSolution(1);
    3012         makeNonFreeVariablesDualFeasible();
     2892      if (largestDualError_ > 1.0e-3 || largestPrimalError_ > 1.0e-3 || (sumDualInfeasibilities_ > 10.0 * CoinMax(lastSumDualInfeasibilities, 1.0) && firstFree_ < 0)) {
     2893#if ABC_NORMAL_DEBUG > 0
     2894        printf("backtracking %d iterations - dual error %g primal error %g - sumDualInf %g\n",
     2895          numberPivots,
     2896          largestDualError_, largestPrimalError_, sumDualInfeasibilities_);
     2897#endif
     2898        // restore previous basis
     2899        unflagVariables = false;
     2900        // restore weights
     2901        weightsSaved = 4;
     2902        changeMade_++; // say something changed
     2903        // Keep any flagged variables
     2904        for (int i = 0; i < numberTotal_; i++) {
     2905          if (flagged(i))
     2906            internalStatusSaved_[i] |= 64; //say flagged
     2907        }
     2908        restoreGoodStatus(type);
     2909        // get correct bounds on all variables
     2910        resetFakeBounds(1);
     2911        numberBlackMarks += 10;
     2912        if (sequenceOut_ >= 0) {
     2913          // need to reject something
     2914#if ABC_NORMAL_DEBUG > 0
     2915          if (flagged(sequenceOut_))
     2916            printf("BAD %x already flagged\n", sequenceOut_);
     2917#endif
     2918          char x = isColumn(sequenceOut_) ? 'C' : 'R';
     2919          handler_->message(CLP_SIMPLEX_FLAG, messages_)
     2920            << x << sequenceWithin(sequenceOut_)
     2921            << CoinMessageEol;
     2922#if ABC_NORMAL_DEBUG > 3
     2923          printf("flag d\n");
     2924#endif
     2925          setFlagged(sequenceOut_);
     2926          lastBadIteration_ = numberIterations_; // say be more cautious
     2927#if ABC_NORMAL_DEBUG > 0
     2928        } else {
     2929          printf("backtracking - no valid sequence out\n");
     2930#endif
     2931        }
     2932        // so can't happen immediately again
     2933        sequenceOut_ = -1;
     2934        //abcProgress_.clearBadTimes();
     2935        // Go to safe
     2936        //abcFactorization_->pivotTolerance(0.99);
     2937        if (internalFactorize(1)) {
     2938          abort();
     2939        }
     2940        moveToBasic();
     2941#if PARTITION_ROW_COPY == 1
     2942        int iVector = getAvailableArray();
     2943        abcMatrix_->sortUseful(usefulArray_[iVector]);
     2944        setAvailableArray(iVector);
     2945#endif
     2946        // get primal and dual solutions
     2947        numberBlackMarks += gutsOfSolution(3);
     2948        //gutsOfSolution(1);
     2949        makeNonFreeVariablesDualFeasible();
    30132950      }
    30142951    }
     
    30162953  //#define PAN
    30172954#ifdef PAN
    3018     if (!type&&(specialOptions_&COIN_CBC_USING_CLP)==0&&firstFree_<0) {
     2955  if (!type && (specialOptions_ & COIN_CBC_USING_CLP) == 0 && firstFree_ < 0) {
    30192956    // first time - set large bad ones superbasic
    3020     int whichArray=getAvailableArray();
    3021     double * COIN_RESTRICT work=usefulArray_[whichArray].denseVector();
    3022     int number=0;
    3023     int * COIN_RESTRICT which=usefulArray_[whichArray].getIndices();
    3024     const double * COIN_RESTRICT reducedCost=abcDj_;
    3025     const double * COIN_RESTRICT lower=abcLower_;
    3026     const double * COIN_RESTRICT upper=abcUpper_;
     2957    int whichArray = getAvailableArray();
     2958    double *COIN_RESTRICT work = usefulArray_[whichArray].denseVector();
     2959    int number = 0;
     2960    int *COIN_RESTRICT which = usefulArray_[whichArray].getIndices();
     2961    const double *COIN_RESTRICT reducedCost = abcDj_;
     2962    const double *COIN_RESTRICT lower = abcLower_;
     2963    const double *COIN_RESTRICT upper = abcUpper_;
    30272964#if PRINT_PAN
    3028     int nAtUb=0;
    3029 #endif
    3030     for (int i=0;i<numberTotal_;i++) {
     2965    int nAtUb = 0;
     2966#endif
     2967    for (int i = 0; i < numberTotal_; i++) {
    30312968      Status status = getInternalStatus(i);
    3032       double djValue=reducedCost[i];
    3033       double badValue=0.0;
    3034       if (status==atLowerBound&&djValue<-currentDualTolerance_) {
    3035         double gap=upper[i]-lower[i];
    3036         if (gap>100000000.0)
    3037           badValue = -djValue*CoinMin(gap,1.0e10);
    3038       } else if (status==atUpperBound&&djValue>currentDualTolerance_) {
    3039         double gap=upper[i]-lower[i];
    3040         if (gap>100000000.0) {
    3041           badValue = djValue*CoinMin(gap,1.0e10);
     2969      double djValue = reducedCost[i];
     2970      double badValue = 0.0;
     2971      if (status == atLowerBound && djValue < -currentDualTolerance_) {
     2972        double gap = upper[i] - lower[i];
     2973        if (gap > 100000000.0)
     2974          badValue = -djValue * CoinMin(gap, 1.0e10);
     2975      } else if (status == atUpperBound && djValue > currentDualTolerance_) {
     2976        double gap = upper[i] - lower[i];
     2977        if (gap > 100000000.0) {
     2978          badValue = djValue * CoinMin(gap, 1.0e10);
    30422979#if PRINT_PAN
    3043           nAtUb++;
    3044 #endif
    3045         }
     2980          nAtUb++;
     2981#endif
     2982        }
    30462983      }
    30472984      if (badValue) {
    3048         work[number]=badValue;
    3049         which[number++]=i;
     2985        work[number] = badValue;
     2986        which[number++] = i;
    30502987      }
    30512988    }
    30522989    // for now don't do if primal feasible (probably should go to primal)
    30532990    if (!numberPrimalInfeasibilities_) {
    3054       number=0;
    3055 #if ABC_NORMAL_DEBUG>1
     2991      number = 0;
     2992#if ABC_NORMAL_DEBUG > 1
    30562993      printf("XXXX doesn't work if primal feasible - also fix switch to Clp primal\n");
    30572994#endif
    30582995    }
    3059     if (number&&ignoreStuff!=2) {
    3060       CoinSort_2(work,work+number,which);
    3061       int numberToDo=CoinMin(number,numberRows_/10); // ??
    3062 #if PRINT_PAN>1
    3063       CoinSort_2(which,which+numberToDo,work);
    3064       int n=0;
     2996    if (number && ignoreStuff != 2) {
     2997      CoinSort_2(work, work + number, which);
     2998      int numberToDo = CoinMin(number, numberRows_ / 10); // ??
     2999#if PRINT_PAN > 1
     3000      CoinSort_2(which, which + numberToDo, work);
     3001      int n = 0;
    30653002#endif
    30663003#if PRINT_PAN
    3067       printf("Panning %d variables (out of %d at lb and %d at ub)\n",numberToDo,number-nAtUb,nAtUb);
    3068 #endif
    3069       firstFree_=numberTotal_;
    3070       for (int i=0;i<numberToDo;i++) {
    3071         int iSequence=which[i];
    3072 #if PRINT_PAN>1
    3073         if (!n)
    3074           printf("Pan ");
    3075         printf("%d ",iSequence);
    3076         n++;
    3077         if (n==10) {
    3078           n=0;
    3079           printf("\n");
    3080         }
    3081 #endif
    3082         setInternalStatus(iSequence,superBasic);
    3083         firstFree_=CoinMin(firstFree_,iSequence);
    3084       }
    3085 #if PRINT_PAN>1
     3004      printf("Panning %d variables (out of %d at lb and %d at ub)\n", numberToDo, number - nAtUb, nAtUb);
     3005#endif
     3006      firstFree_ = numberTotal_;
     3007      for (int i = 0; i < numberToDo; i++) {
     3008        int iSequence = which[i];
     3009#if PRINT_PAN > 1
     3010        if (!n)
     3011          printf("Pan ");
     3012        printf("%d ", iSequence);
     3013        n++;
     3014        if (n == 10) {
     3015          n = 0;
     3016          printf("\n");
     3017        }
     3018#endif
     3019        setInternalStatus(iSequence, superBasic);
     3020        firstFree_ = CoinMin(firstFree_, iSequence);
     3021      }
     3022#if PRINT_PAN > 1
    30863023      if (n)
    3087         printf("\n");
    3088 #endif
    3089       ordinaryVariables_=0;
    3090       CoinAbcMemset0(work,number);
     3024        printf("\n");
     3025#endif
     3026      ordinaryVariables_ = 0;
     3027      CoinAbcMemset0(work, number);
    30913028      stateOfProblem_ |= FAKE_SUPERBASIC;
    30923029    }
     
    30943031  }
    30953032#endif
    3096   if (!sumOfRelaxedPrimalInfeasibilities_&&sumDualInfeasibilities_&&type&&saveType<9
    3097       &&ignoreStuff!=2) {
     3033  if (!sumOfRelaxedPrimalInfeasibilities_ && sumDualInfeasibilities_ && type && saveType < 9
     3034    && ignoreStuff != 2) {
    30983035    // say been feasible
    30993036    abcState_ |= CLP_ABC_BEEN_FEASIBLE;
    3100     int numberFake=numberAtFakeBound();
     3037    int numberFake = numberAtFakeBound();
    31013038    if (!numberFake) {
    31023039      makeNonFreeVariablesDualFeasible();
    3103       numberDualInfeasibilities_=0;
    3104       sumDualInfeasibilities_=0.0;
     3040      numberDualInfeasibilities_ = 0;
     3041      sumDualInfeasibilities_ = 0.0;
    31053042      // just primal
    31063043      gutsOfSolution(2);
    31073044    }
    31083045  }
    3109   bool computeNewSumInfeasibilities=numberIterations_==baseIteration_;
    3110   if ((!type||(firstFree_<0&&lastFirstFree_>=0))&&ignoreStuff!=2) {
     3046  bool computeNewSumInfeasibilities = numberIterations_ == baseIteration_;
     3047  if ((!type || (firstFree_ < 0 && lastFirstFree_ >= 0)) && ignoreStuff != 2) {
    31113048#ifdef PAN
    3112     if ((stateOfProblem_&FAKE_SUPERBASIC)!=0&&firstFree_<0&&lastFirstFree_>=0&&type) {
     3049    if ((stateOfProblem_ & FAKE_SUPERBASIC) != 0 && firstFree_ < 0 && lastFirstFree_ >= 0 && type) {
    31133050      // clean up
    31143051#if PRINT_PAN
    3115       printf("Pan switch off after %d iterations\n",numberIterations_);
    3116 #endif
    3117       computeNewSumInfeasibilities=true;
    3118       ordinaryVariables_=1;
    3119       const double * COIN_RESTRICT reducedCost=abcDj_;
    3120       const double * COIN_RESTRICT lower=abcLower_;
    3121       const double * COIN_RESTRICT upper=abcUpper_;
    3122       for (int i=0;i<numberTotal_;i++) {
    3123         Status status = getInternalStatus(i);
    3124         if (status==superBasic) {
    3125           double djValue=reducedCost[i];
    3126           double value=abcSolution_[i];
    3127           if (value<lower[i]+primalTolerance_) {
    3128             setInternalStatus(i,atLowerBound);
    3129 #if ABC_NORMAL_DEBUG>0
    3130             if(djValue<-dualTolerance_)
    3131               printf("Odd at lb %d dj %g\n",i,djValue);
    3132 #endif
    3133           } else if (value>upper[i]-primalTolerance_) {
    3134             setInternalStatus(i,atUpperBound);
    3135 #if ABC_NORMAL_DEBUG>0
    3136             if(djValue>dualTolerance_)
    3137               printf("Odd at ub %d dj %g\n",i,djValue);
    3138 #endif
    3139           } else {
    3140             assert (status!=superBasic);
    3141           }
    3142         }
    3143         if (status==isFree)
    3144           ordinaryVariables_=0;
     3052      printf("Pan switch off after %d iterations\n", numberIterations_);
     3053#endif
     3054      computeNewSumInfeasibilities = true;
     3055      ordinaryVariables_ = 1;
     3056      const double *COIN_RESTRICT reducedCost = abcDj_;
     3057      const double *COIN_RESTRICT lower = abcLower_;
     3058      const double *COIN_RESTRICT upper = abcUpper_;
     3059      for (int i = 0; i < numberTotal_; i++) {
     3060        Status status = getInternalStatus(i);
     3061        if (status == superBasic) {
     3062          double djValue = reducedCost[i];
     3063          double value = abcSolution_[i];
     3064          if (value < lower[i] + primalTolerance_) {
     3065            setInternalStatus(i, atLowerBound);
     3066#if ABC_NORMAL_DEBUG > 0
     3067            if (djValue < -dualTolerance_)
     3068              printf("Odd at lb %d dj %g\n", i, djValue);
     3069#endif
     3070          } else if (value > upper[i] - primalTolerance_) {
     3071            setInternalStatus(i, atUpperBound);
     3072#if ABC_NORMAL_DEBUG > 0
     3073            if (djValue > dualTolerance_)
     3074              printf("Odd at ub %d dj %g\n", i, djValue);
     3075#endif
     3076          } else {
     3077            assert(status != superBasic);
     3078          }
     3079        }
     3080        if (status == isFree)
     3081          ordinaryVariables_ = 0;
    31453082      }
    31463083      stateOfProblem_ &= ~FAKE_SUPERBASIC;
     
    31493086    // set up perturbation and dualBound_
    31503087    // make dual feasible
    3151     if (firstFree_<0) {
     3088    if (firstFree_ < 0) {
    31523089      if (numberFlagged_) {
    3153         numberFlagged_=0;
    3154         for (int iRow = 0; iRow < numberRows_; iRow++) {
    3155           int iPivot = abcPivotVariable_[iRow];
    3156           if (flagged(iPivot)) {
    3157             clearFlagged(iPivot);
    3158           }
    3159         }
    3160       }
    3161       int numberChanged=resetFakeBounds(0);
    3162 #if ABC_NORMAL_DEBUG>0
    3163       if (numberChanged>0)
    3164         printf("Re-setting %d fake bounds %d gone dual infeasible - can expect backward objective\n",
    3165                numberChanged,numberDualInfeasibilities_);
    3166 #endif
    3167       if (numberDualInfeasibilities_||numberChanged!=-1) {
    3168         makeNonFreeVariablesDualFeasible();
    3169         numberDualInfeasibilities_=0;
    3170         sumDualInfeasibilities_=0.0;
    3171         sumOfRelaxedDualInfeasibilities_=0.0;
    3172         // just primal
    3173         gutsOfSolution(2);
    3174         if (!numberIterations_ && sumPrimalInfeasibilities_ >
    3175             1.0e5*(savePrimalInfeasibilities+1.0e3) &&
    3176             (moreSpecialOptions_ & (256|8192)) == 0) {
    3177           // Use primal
    3178           problemStatus_=10;
    3179           // mark so can perturb
    3180           initialSumInfeasibilities_=-1.0;
    3181           CoinAbcMemcpy(abcSolution_,solutionSaved_,numberTotal_);
    3182           CoinAbcMemcpy(internalStatus_,internalStatusSaved_,numberTotal_);
    3183           return;
    3184         }
    3185         // redo
    3186         if(computeNewSumInfeasibilities)
    3187           initialSumInfeasibilities_=sumPrimalInfeasibilities_;
    3188         //computeObjective();
    3189       }
     3090        numberFlagged_ = 0;
     3091        for (int iRow = 0; iRow < numberRows_; iRow++) {
     3092          int iPivot = abcPivotVariable_[iRow];
     3093          if (flagged(iPivot)) {
     3094            clearFlagged(iPivot);
     3095          }
     3096        }
     3097      }
     3098      int numberChanged = resetFakeBounds(0);
     3099#if ABC_NORMAL_DEBUG > 0
     3100      if (numberChanged > 0)
     3101        printf("Re-setting %d fake bounds %d gone dual infeasible - can expect backward objective\n",
     3102          numberChanged, numberDualInfeasibilities_);
     3103#endif
     3104      if (numberDualInfeasibilities_ || numberChanged != -1) {
     3105        makeNonFreeVariablesDualFeasible();
     3106        numberDualInfeasibilities_ = 0;
     3107        sumDualInfeasibilities_ = 0.0;
     3108        sumOfRelaxedDualInfeasibilities_ = 0.0;
     3109        // just primal
     3110        gutsOfSolution(2);
     3111        if (!numberIterations_ && sumPrimalInfeasibilities_ > 1.0e5 * (savePrimalInfeasibilities + 1.0e3) && (moreSpecialOptions_ & (256 | 8192)) == 0) {
     3112          // Use primal
     3113          problemStatus_ = 10;
     3114          // mark so can perturb
     3115          initialSumInfeasibilities_ = -1.0;
     3116          CoinAbcMemcpy(abcSolution_, solutionSaved_, numberTotal_);
     3117          CoinAbcMemcpy(internalStatus_, internalStatusSaved_, numberTotal_);
     3118          return;
     3119        }
     3120        // redo
     3121        if (computeNewSumInfeasibilities)
     3122          initialSumInfeasibilities_ = sumPrimalInfeasibilities_;
     3123        //computeObjective();
     3124      }
    31903125    }
    31913126    //bounceTolerances(type);
    3192   } else if (numberIterations_>numberRows_&&stateDualColumn_==-2) {
     3127  } else if (numberIterations_ > numberRows_ && stateDualColumn_ == -2) {
    31933128    bounceTolerances(4);
    31943129  }
    31953130  // If bad accuracy treat as singular
    3196   if ((largestPrimalError_ > 1.0e15 || largestDualError_ > 1.0e15) && numberIterations_>1000) {
    3197     problemStatus_=10; //abort();
    3198 #if ABC_NORMAL_DEBUG>0
    3199     printf("Big problems - errors %g %g try primal\n",largestPrimalError_,largestDualError_);
    3200 #endif
    3201   } else if (goodAccuracy()&&numberIterations_>lastBadIteration_+200) {
     3131  if ((largestPrimalError_ > 1.0e15 || largestDualError_ > 1.0e15) && numberIterations_ > 1000) {
     3132    problemStatus_ = 10; //abort();
     3133#if ABC_NORMAL_DEBUG > 0
     3134    printf("Big problems - errors %g %g try primal\n", largestPrimalError_, largestDualError_);
     3135#endif
     3136  } else if (goodAccuracy() && numberIterations_ > lastBadIteration_ + 200) {
    32023137    // Can reduce tolerance
    32033138    double newTolerance = CoinMax(0.995 * abcFactorization_->pivotTolerance(), saveData_.pivotTolerance_);
    32043139    if (!type)
    32053140      newTolerance = saveData_.pivotTolerance_;
    3206     if (newTolerance>abcFactorization_->minimumPivotTolerance())
     3141    if (newTolerance > abcFactorization_->minimumPivotTolerance())
    32073142      abcFactorization_->pivotTolerance(newTolerance);
    32083143  }
    32093144  bestObjectiveValue_ = CoinMax(bestObjectiveValue_,
    3210                                 rawObjectiveValue_ - bestPossibleImprovement_);
     3145    rawObjectiveValue_ - bestPossibleImprovement_);
    32113146  // Double check infeasibility if no action
    32123147  if (abcProgress_.lastIterationNumber(0) == numberIterations_) {
     
    32203155    double thisObj = rawObjectiveValue_ - bestPossibleImprovement_;
    32213156#ifdef CLP_INVESTIGATE
    3222     assert (bestPossibleImprovement_ > -1000.0 && rawObjectiveValue_ > -1.0e100);
     3157    assert(bestPossibleImprovement_ > -1000.0 && rawObjectiveValue_ > -1.0e100);
    32233158    if (bestPossibleImprovement_)
    32243159      printf("obj %g add in %g -> %g\n", rawObjectiveValue_, bestPossibleImprovement_,
    3225              thisObj);
     3160        thisObj);
    32263161#endif
    32273162    double lastObj = abcProgress_.lastObjective(0);
    32283163#ifndef NDEBUG
    3229 #if ABC_NORMAL_DEBUG>3
     3164#if ABC_NORMAL_DEBUG > 3
    32303165    resetFakeBounds(-1);
    32313166#endif
    32323167#endif
    3233     if (lastObj < thisObj - 1.0e-5 * CoinMax(fabs(thisObj), fabs(lastObj)) - 1.0e-3 && saveType<9) {
     3168    if (lastObj < thisObj - 1.0e-5 * CoinMax(fabs(thisObj), fabs(lastObj)) - 1.0e-3 && saveType < 9) {
    32343169      numberTimesOptimal_ = 0;
    32353170    }
     
    32403175      int backIteration = abcProgress_.lastIterationNumber(CLP_PROGRESS - 1);
    32413176      if (backIteration > 0 && numberIterations_ - backIteration < 9 * CLP_PROGRESS) {
    3242         if (abcFactorization_->pivotTolerance() < 0.9) {
    3243           // up tolerance
    3244           abcFactorization_->pivotTolerance(CoinMin(abcFactorization_->pivotTolerance() * 1.05 + 0.02, 0.91));
    3245           //printf("tol now %g\n",abcFactorization_->pivotTolerance());
    3246           abcProgress_.clearIterationNumbers();
    3247         }
     3177        if (abcFactorization_->pivotTolerance() < 0.9) {
     3178          // up tolerance
     3179          abcFactorization_->pivotTolerance(CoinMin(abcFactorization_->pivotTolerance() * 1.05 + 0.02, 0.91));
     3180          //printf("tol now %g\n",abcFactorization_->pivotTolerance());
     3181          abcProgress_.clearIterationNumbers();
     3182        }
    32483183      }
    32493184    }
     
    32573192  if (abcProgress_.reallyBadTimes() > 10) {
    32583193    problemStatus_ = 10; // instead - try other algorithm
    3259 #if ABC_NORMAL_DEBUG>3
     3194#if ABC_NORMAL_DEBUG > 3
    32603195    printf("returning at %d\n", __LINE__);
    32613196#endif
     
    32713206    } else {
    32723207      problemStatus_ = 10; // instead - try other algorithm
    3273 #if ABC_NORMAL_DEBUG>3
     3208#if ABC_NORMAL_DEBUG > 3
    32743209      printf("returning at %d\n", __LINE__);
    32753210#endif
     
    32783213  }
    32793214  // really for free variables in
    3280   if((progressFlag_ & 2) != 0) {
     3215  if ((progressFlag_ & 2) != 0) {
    32813216    //situationChanged = 2;
    32823217  }
    32833218  progressFlag_ &= (~3); //reset progress flag
    32843219  // mark as having gone optimal if looks like it
    3285   if (!numberPrimalInfeasibilities_&&
    3286       !numberDualInfeasibilities_)
     3220  if (!numberPrimalInfeasibilities_ && !numberDualInfeasibilities_)
    32873221    progressFlag_ |= 8;
    32883222  if (handler_->detail(CLP_SIMPLEX_STATUS, messages_) < 100) {
     
    32943228      << sumDualInfeasibilities_ << numberDualInfeasibilities_;
    32953229    handler_->printing(numberDualInfeasibilitiesWithoutFree_
    3296                        < numberDualInfeasibilities_)
     3230      < numberDualInfeasibilities_)
    32973231      << numberDualInfeasibilitiesWithoutFree_;
    32983232    handler_->message() << CoinMessageEol;
     
    33053239      int iPivot = abcPivotVariable_[iRow];
    33063240      if (!flagged(iPivot) && pivoted(iPivot)) {
    3307         // carry on
    3308         numberPrimalInfeasibilities_ = -1;
    3309         sumOfRelaxedPrimalInfeasibilities_ = 1.0;
    3310         sumPrimalInfeasibilities_ = 1.0;
    3311         break;
     3241        // carry on
     3242        numberPrimalInfeasibilities_ = -1;
     3243        sumOfRelaxedPrimalInfeasibilities_ = 1.0;
     3244        sumPrimalInfeasibilities_ = 1.0;
     3245        break;
    33123246      }
    33133247    }
     
    33153249  /* If we are primal feasible and any dual infeasibilities are on
    33163250     free variables then it is better to go to primal */
    3317   if (!numberPrimalInfeasibilities_ && !numberDualInfeasibilitiesWithoutFree_ &&
    3318       numberDualInfeasibilities_) {
     3251  if (!numberPrimalInfeasibilities_ && !numberDualInfeasibilitiesWithoutFree_ && numberDualInfeasibilities_) {
    33193252    // say been feasible
    33203253    abcState_ |= CLP_ABC_BEEN_FEASIBLE;
    3321     if (type&&ignoreStuff!=2)
     3254    if (type && ignoreStuff != 2)
    33223255      problemStatus_ = 10;
    33233256    else
    3324       numberPrimalInfeasibilities_=1;
     3257      numberPrimalInfeasibilities_ = 1;
    33253258  }
    33263259  // check optimal
    33273260  // give code benefit of doubt
    3328   if (sumOfRelaxedDualInfeasibilities_ == 0.0 &&
    3329       sumOfRelaxedPrimalInfeasibilities_ == 0.0&&ignoreStuff!=2) {
     3261  if (sumOfRelaxedDualInfeasibilities_ == 0.0 && sumOfRelaxedPrimalInfeasibilities_ == 0.0 && ignoreStuff != 2) {
    33303262    // say been feasible
    33313263    abcState_ |= CLP_ABC_BEEN_FEASIBLE;
     
    33353267    numberPrimalInfeasibilities_ = 0;
    33363268    sumPrimalInfeasibilities_ = 0.0;
    3337   } else if (sumOfRelaxedDualInfeasibilities_>1.0e-3&&firstFree_<0&&ignoreStuff!=2
    3338              &&numberIterations_>lastCleaned_+10) {
    3339 #if ABC_NORMAL_DEBUG>0
     3269  } else if (sumOfRelaxedDualInfeasibilities_ > 1.0e-3 && firstFree_ < 0 && ignoreStuff != 2
     3270    && numberIterations_ > lastCleaned_ + 10) {
     3271#if ABC_NORMAL_DEBUG > 0
    33403272    printf("Making dual feasible\n");
    33413273#endif
    33423274    makeNonFreeVariablesDualFeasible(true);
    3343     lastCleaned_=numberIterations_;
    3344     numberDualInfeasibilities_=0;
    3345     sumDualInfeasibilities_=0.0;
     3275    lastCleaned_ = numberIterations_;
     3276    numberDualInfeasibilities_ = 0;
     3277    sumDualInfeasibilities_ = 0.0;
    33463278    // just primal
    33473279    gutsOfSolution(2);
     
    33503282  double limit = 0.0;
    33513283  getDblParam(ClpDualObjectiveLimit, limit);
    3352   int numberChangedBounds=0;
    3353   if (primalFeasible()&&ignoreStuff!=2) {
     3284  int numberChangedBounds = 0;
     3285  if (primalFeasible() && ignoreStuff != 2) {
    33543286    // may be optimal - or may be bounds are wrong
    33553287    numberChangedBounds = changeBounds(0, changeCost);
     
    33573289      gutsOfSolution(2);
    33583290  }
    3359   if (primalFeasible()&&ignoreStuff!=2) {
     3291  if (primalFeasible() && ignoreStuff != 2) {
    33603292    if (numberChangedBounds <= 0 && !numberDualInfeasibilities_) {
    33613293      //looks optimal - do we need to reset tolerance
    3362       if (lastCleaned_ < numberIterations_ && /*numberTimesOptimal_*/ stateDualColumn_ < 4 &&
    3363           (numberChanged_ || (specialOptions_ & 4096) == 0)) {
     3294      if (lastCleaned_ < numberIterations_ && /*numberTimesOptimal_*/ stateDualColumn_ < 4 && (numberChanged_ || (specialOptions_ & 4096) == 0)) {
    33643295#if CLP_CAN_HAVE_ZERO_OBJ
    3365         if ((specialOptions_&2097152)==0) {
    3366 #endif
    3367           numberTimesOptimal_++;
    3368           if (stateDualColumn_==-2) {
    3369 #if ABC_NORMAL_DEBUG>0
    3370             printf("Going straight from state -2 to 0\n");
    3371 #endif
    3372             stateDualColumn_=-1;
    3373           }
    3374           changeMade_++; // say something changed
    3375           if (numberTimesOptimal_ == 1) {
    3376             if (fabs(currentDualTolerance_-dualTolerance_)>1.0e-12) {
    3377 #if ABC_NORMAL_DEBUG>0
    3378               printf("changing dual tolerance from %g to %g (numberTimesOptimal_==%d)\n",
    3379                      currentDualTolerance_,dualTolerance_,numberTimesOptimal_);
    3380 #endif
    3381               currentDualTolerance_ = dualTolerance_;
    3382             }
    3383           } else {
    3384             if (numberTimesOptimal_ == 2) {
    3385               // better to have small tolerance even if slower
    3386               abcFactorization_->zeroTolerance(CoinMin(abcFactorization_->zeroTolerance(), 1.0e-15));
    3387             }
    3388 #if ABC_NORMAL_DEBUG>0
    3389             printf("changing dual tolerance from %g to %g (numberTimesOptimal_==%d)\n",
    3390                    currentDualTolerance_,dualTolerance_*pow(2.0,numberTimesOptimal_-1),numberTimesOptimal_);
    3391 #endif
    3392             currentDualTolerance_ = dualTolerance_ * pow(2.0, numberTimesOptimal_ - 1);
    3393           }
    3394           if (numberChanged_>0) {
    3395             handler_->message(CLP_DUAL_ORIGINAL, messages_)
    3396               << CoinMessageEol;
    3397             //realDualInfeasibilities = sumDualInfeasibilities_;
    3398           } else if (numberChangedBounds<-1) {
    3399             // bounds were flipped
    3400             //gutsOfSolution(2);
    3401           }
    3402           if (stateDualColumn_>=0)
    3403             stateDualColumn_++;
     3296        if ((specialOptions_ & 2097152) == 0) {
     3297#endif
     3298          numberTimesOptimal_++;
     3299          if (stateDualColumn_ == -2) {
     3300#if ABC_NORMAL_DEBUG > 0
     3301            printf("Going straight from state -2 to 0\n");
     3302#endif
     3303            stateDualColumn_ = -1;
     3304          }
     3305          changeMade_++; // say something changed
     3306          if (numberTimesOptimal_ == 1) {
     3307            if (fabs(currentDualTolerance_ - dualTolerance_) > 1.0e-12) {
     3308#if ABC_NORMAL_DEBUG > 0
     3309              printf("changing dual tolerance from %g to %g (numberTimesOptimal_==%d)\n",
     3310                currentDualTolerance_, dualTolerance_, numberTimesOptimal_);
     3311#endif
     3312              currentDualTolerance_ = dualTolerance_;
     3313            }
     3314          } else {
     3315            if (numberTimesOptimal_ == 2) {
     3316              // better to have small tolerance even if slower
     3317              abcFactorization_->zeroTolerance(CoinMin(abcFactorization_->zeroTolerance(), 1.0e-15));
     3318            }
     3319#if ABC_NORMAL_DEBUG > 0
     3320            printf("changing dual tolerance from %g to %g (numberTimesOptimal_==%d)\n",
     3321              currentDualTolerance_, dualTolerance_ * pow(2.0, numberTimesOptimal_ - 1), numberTimesOptimal_);
     3322#endif
     3323            currentDualTolerance_ = dualTolerance_ * pow(2.0, numberTimesOptimal_ - 1);
     3324          }
     3325          if (numberChanged_ > 0) {
     3326            handler_->message(CLP_DUAL_ORIGINAL, messages_)
     3327              << CoinMessageEol;
     3328            //realDualInfeasibilities = sumDualInfeasibilities_;
     3329          } else if (numberChangedBounds < -1) {
     3330            // bounds were flipped
     3331            //gutsOfSolution(2);
     3332          }
     3333          if (stateDualColumn_ >= 0)
     3334            stateDualColumn_++;
    34043335#ifndef TRY_ABC_GUS
    3405           int returnCode=bounceTolerances(1);
    3406           if (returnCode)
     3336          int returnCode = bounceTolerances(1);
     3337          if (returnCode)
    34073338#endif // always go to primal
    3408             problemStatus_=10;
    3409           lastCleaned_ = numberIterations_;
     3339            problemStatus_ = 10;
     3340          lastCleaned_ = numberIterations_;
    34103341#if CLP_CAN_HAVE_ZERO_OBJ
    3411         } else {
    3412           // no cost - skip checks
    3413           problemStatus_=0;
    3414         }
     3342        } else {
     3343          // no cost - skip checks
     3344          problemStatus_ = 0;
     3345        }
    34153346#endif
    34163347      } else {
    3417         problemStatus_ = 0; // optimal
    3418         if (lastCleaned_ < numberIterations_ && numberChanged_) {
    3419           handler_->message(CLP_SIMPLEX_GIVINGUP, messages_)
    3420             << CoinMessageEol;
    3421         }
    3422       }
    3423     } else if (numberChangedBounds<-1) {
     3348        problemStatus_ = 0; // optimal
     3349        if (lastCleaned_ < numberIterations_ && numberChanged_) {
     3350          handler_->message(CLP_SIMPLEX_GIVINGUP, messages_)
     3351            << CoinMessageEol;
     3352        }
     3353      }
     3354    } else if (numberChangedBounds < -1) {
    34243355      // some flipped
    34253356      bounceTolerances(2);
    3426 #if ABC_NORMAL_DEBUG>0
     3357#if ABC_NORMAL_DEBUG > 0
    34273358      printf("numberChangedBounds %d numberAtFakeBound %d at line %d in file %s\n",
    3428              numberChangedBounds,numberAtFakeBound(),__LINE__,__FILE__);
    3429 #endif
    3430     } else if (numberChangedBounds>0||numberAtFakeBound()) {
     3359        numberChangedBounds, numberAtFakeBound(), __LINE__, __FILE__);
     3360#endif
     3361    } else if (numberChangedBounds > 0 || numberAtFakeBound()) {
    34313362      handler_->message(CLP_DUAL_BOUNDS, messages_)
    3432         << currentDualBound_
    3433         << CoinMessageEol;
    3434 #if ABC_NORMAL_DEBUG>0
     3363        << currentDualBound_
     3364        << CoinMessageEol;
     3365#if ABC_NORMAL_DEBUG > 0
    34353366      printf("changing bounds\n");
    34363367      printf("numberChangedBounds %d numberAtFakeBound %d at line %d in file %s\n",
    3437              numberChangedBounds,numberAtFakeBound(),__LINE__,__FILE__);
    3438 #endif
    3439       if (!numberDualInfeasibilities_&&!numberPrimalInfeasibilities_) {
    3440         // check unbounded
    3441         // find a variable with bad dj
    3442         int iChosen = -1;
    3443         if ((specialOptions_ & 0x03000000) == 0) {
    3444           double largest = 100.0 * primalTolerance_;
    3445           for (int iSequence = 0; iSequence < numberTotal_; iSequence++) {
    3446             double djValue = abcDj_[iSequence];
    3447             double originalLo = lowerSaved_[iSequence];
    3448             double originalUp = upperSaved_[iSequence];
    3449             if (fabs(djValue) > fabs(largest)) {
    3450               if (getInternalStatus(iSequence) != basic) {
    3451                 if (djValue > 0 && originalLo < -1.0e20) {
    3452                   if (djValue > fabs(largest)) {
    3453                     largest = djValue;
    3454                     iChosen = iSequence;
    3455                   }
    3456                 } else if (djValue < 0 && originalUp > 1.0e20) {
    3457                   if (-djValue > fabs(largest)) {
    3458                     largest = djValue;
    3459                     iChosen = iSequence;
    3460                   }
    3461                 }
    3462               }
    3463             }
    3464           }
    3465         }
    3466         if (iChosen >= 0) {
    3467           int iVector=getAvailableArray();
    3468           unpack(usefulArray_[iVector],iChosen);
    3469           //double changeCost;
    3470           problemStatus_ = checkUnbounded(usefulArray_[iVector], 0.0/*changeCost*/);
    3471           usefulArray_[iVector].clear();
    3472           setAvailableArray(iVector);
    3473         }
     3368        numberChangedBounds, numberAtFakeBound(), __LINE__, __FILE__);
     3369#endif
     3370      if (!numberDualInfeasibilities_ && !numberPrimalInfeasibilities_) {
     3371        // check unbounded
     3372        // find a variable with bad dj
     3373        int iChosen = -1;
     3374        if ((specialOptions_ & 0x03000000) == 0) {
     3375          double largest = 100.0 * primalTolerance_;
     3376          for (int iSequence = 0; iSequence < numberTotal_; iSequence++) {
     3377            double djValue = abcDj_[iSequence];
     3378            double originalLo = lowerSaved_[iSequence];
     3379            double originalUp = upperSaved_[iSequence];
     3380            if (fabs(djValue) > fabs(largest)) {
     3381              if (getInternalStatus(iSequence) != basic) {
     3382                if (djValue > 0 && originalLo < -1.0e20) {
     3383                  if (djValue > fabs(largest)) {
     3384                    largest = djValue;
     3385                    iChosen = iSequence;
     3386                  }
     3387                } else if (djValue < 0 && originalUp > 1.0e20) {
     3388                  if (-djValue > fabs(largest)) {
     3389                    largest = djValue;
     3390                    iChosen = iSequence;
     3391                  }
     3392                }
     3393              }
     3394            }
     3395          }
     3396        }
     3397        if (iChosen >= 0) {
     3398          int iVector = getAvailableArray();
     3399          unpack(usefulArray_[iVector], iChosen);
     3400          //double changeCost;
     3401          problemStatus_ = checkUnbounded(usefulArray_[iVector], 0.0 /*changeCost*/);
     3402          usefulArray_[iVector].clear();
     3403          setAvailableArray(iVector);
     3404        }
    34743405      }
    34753406      gutsOfSolution(3);
    34763407      //bounceTolerances(2);
    3477       //realDualInfeasibilities = sumDualInfeasibilities_; 
     3408      //realDualInfeasibilities = sumDualInfeasibilities_;
    34783409    }
    34793410    // unflag all variables (we may want to wait a bit?)
    34803411    if (unflagVariables) {
    34813412      int numberFlagged = numberFlagged_;
    3482       numberFlagged_=0;
     3413      numberFlagged_ = 0;
    34833414      for (int iRow = 0; iRow < numberRows_; iRow++) {
    3484         int iPivot = abcPivotVariable_[iRow];
    3485         if (flagged(iPivot)) {
    3486           clearFlagged(iPivot);
    3487         }
    3488       }
    3489 #if ABC_NORMAL_DEBUG>3
     3415        int iPivot = abcPivotVariable_[iRow];
     3416        if (flagged(iPivot)) {
     3417          clearFlagged(iPivot);
     3418        }
     3419      }
     3420#if ABC_NORMAL_DEBUG > 3
    34903421      if (numberFlagged) {
    3491         printf("unflagging %d variables - tentativeStatus %d probStat %d ninf %d nopt %d\n", numberFlagged, tentativeStatus,
    3492                problemStatus_, numberPrimalInfeasibilities_,
    3493                numberTimesOptimal_);
     3422        printf("unflagging %d variables - tentativeStatus %d probStat %d ninf %d nopt %d\n", numberFlagged, tentativeStatus,
     3423          problemStatus_, numberPrimalInfeasibilities_,
     3424          numberTimesOptimal_);
    34943425      }
    34953426#endif
    34963427      unflagVariables = numberFlagged > 0;
    34973428      if (numberFlagged && !numberPivots) {
    3498         /* looks like trouble as we have not done any iterations.
     3429        /* looks like trouble as we have not done any iterations.
    34993430           Try changing pivot tolerance then give it a few goes and give up */
    3500         if (abcFactorization_->pivotTolerance() < 0.9) {
    3501           abcFactorization_->pivotTolerance(0.99);
    3502           problemStatus_ = -1;
    3503         } else if (numberTimesOptimal_ < 3) {
    3504           numberTimesOptimal_++;
    3505           problemStatus_ = -1;
    3506         } else {
    3507           unflagVariables = false;
    3508           //secondaryStatus_ = 1; // and say probably infeasible
    3509           if ((moreSpecialOptions_ & 256) == 0||(abcState_&CLP_ABC_BEEN_FEASIBLE)!=0) {
    3510             // try primal
    3511             problemStatus_ = 10;
    3512           } else {
    3513             // almost certainly infeasible
    3514             problemStatus_ = 1;
    3515           }
    3516 #if ABC_NORMAL_DEBUG>3
    3517           printf("returning at %d\n", __LINE__);
    3518 #endif
    3519         }
     3431        if (abcFactorization_->pivotTolerance() < 0.9) {
     3432          abcFactorization_->pivotTolerance(0.99);
     3433          problemStatus_ = -1;
     3434        } else if (numberTimesOptimal_ < 3) {
     3435          numberTimesOptimal_++;
     3436          problemStatus_ = -1;
     3437        } else {
     3438          unflagVariables = false;
     3439          //secondaryStatus_ = 1; // and say probably infeasible
     3440          if ((moreSpecialOptions_ & 256) == 0 || (abcState_ & CLP_ABC_BEEN_FEASIBLE) != 0) {
     3441            // try primal
     3442            problemStatus_ = 10;
     3443          } else {
     3444            // almost certainly infeasible
     3445            problemStatus_ = 1;
     3446          }
     3447#if ABC_NORMAL_DEBUG > 3
     3448          printf("returning at %d\n", __LINE__);
     3449#endif
     3450        }
    35203451      }
    35213452    }
     
    35383469      looksBad = 1;
    35393470    } else if (largestPrimalError_ > 1.0e-2
    3540                && rawObjectiveValue_ > CoinMin(1.0e15, 1.0e3 * limit)) {
     3471      && rawObjectiveValue_ > CoinMin(1.0e15, 1.0e3 * limit)) {
    35413472      looksBad = 2;
    35423473    }
    35433474    if (looksBad) {
    35443475      if (abcFactorization_->pivotTolerance() < 0.9) {
    3545         // up tolerance
    3546         abcFactorization_->pivotTolerance(CoinMin(abcFactorization_->pivotTolerance() * 1.05 + 0.02, 0.91));
     3476        // up tolerance
     3477        abcFactorization_->pivotTolerance(CoinMin(abcFactorization_->pivotTolerance() * 1.05 + 0.02, 0.91));
    35473478      } else if (numberIterations_ > 10000) {
    3548 #if ABC_NORMAL_DEBUG>0
    3549         if (handler_->logLevel() > 2)
    3550           printf("bad dual - saying infeasible %d\n", looksBad);
    3551 #endif
    3552         problemStatus_ = 1;
    3553         secondaryStatus_ = 1; // and say was on cutoff
     3479#if ABC_NORMAL_DEBUG > 0
     3480        if (handler_->logLevel() > 2)
     3481          printf("bad dual - saying infeasible %d\n", looksBad);
     3482#endif
     3483        problemStatus_ = 1;
     3484        secondaryStatus_ = 1; // and say was on cutoff
    35543485      } else if (largestPrimalError_ > 1.0e5) {
    3555 #if ABC_NORMAL_DEBUG>0
    3556         if (handler_->logLevel() > 2)
    3557           printf("bad dual - going to primal %d %g\n", looksBad, largestPrimalError_);
    3558 #endif
    3559         allSlackBasis();
    3560         problemStatus_ = 10;
     3486#if ABC_NORMAL_DEBUG > 0
     3487        if (handler_->logLevel() > 2)
     3488          printf("bad dual - going to primal %d %g\n", looksBad, largestPrimalError_);
     3489#endif
     3490        allSlackBasis();
     3491        problemStatus_ = 10;
    35613492      }
    35623493    }
     
    35693500    moreSpecialOptions_ &= ~16; // clear check accuracy flag
    35703501    if (numberFlagged_) {
    3571       numberFlagged_=0;
     3502      numberFlagged_ = 0;
    35723503      for (int iRow = 0; iRow < numberRows_; iRow++) {
    3573         int iPivot = abcPivotVariable_[iRow];
    3574         if (flagged(iPivot)) {
    3575           clearFlagged(iPivot);
    3576         }
    3577       }
    3578     }
    3579   }
    3580   if (problemStatus_ < 0&&ignoreStuff!=2) {
     3504        int iPivot = abcPivotVariable_[iRow];
     3505        if (flagged(iPivot)) {
     3506          clearFlagged(iPivot);
     3507        }
     3508      }
     3509    }
     3510  }
     3511  if (problemStatus_ < 0 && ignoreStuff != 2) {
    35813512    //sumDualInfeasibilities_ = realDualInfeasibilities; // back to say be careful
    35823513    if (sumDualInfeasibilities_) {
     
    35843515    } else if (!numberPrimalInfeasibilities_) {
    35853516      // Looks good
    3586       problemStatus_=0;
     3517      problemStatus_ = 0;
    35873518    }
    35883519  }
    35893520  double thisObj = abcProgress_.lastObjective(0);
    35903521  double lastObj = abcProgress_.lastObjective(1);
    3591   if (lastObj > thisObj + 1.0e-4 * CoinMax(fabs(thisObj), fabs(lastObj)) + 1.0e-4&&
    3592       lastFirstFree_<0) {
     3522  if (lastObj > thisObj + 1.0e-4 * CoinMax(fabs(thisObj), fabs(lastObj)) + 1.0e-4 && lastFirstFree_ < 0) {
    35933523    //printf("BAD - objective backwards\n");
    35943524    //bounceTolerances(3);
    3595     numberBlackMarks+=3;
    3596   }
    3597   if (numberBlackMarks>0&&numberIterations_>baseIteration_) {
     3525    numberBlackMarks += 3;
     3526  }
     3527  if (numberBlackMarks > 0 && numberIterations_ > baseIteration_) {
    35983528    // be very careful
    35993529    int maxFactor = abcFactorization_->maximumPivots();
    36003530    if (maxFactor > 10) {
    3601       if ((stateOfProblem_&PESSIMISTIC)==0||true) {
    3602         if (largestDualError_>10.0*CoinMax(lastDualError_,1.0e-6)
    3603             ||largestPrimalError_>10.0*CoinMax(lastPrimalError_,1.0e-6))
    3604           maxFactor = CoinMin(maxFactor,20);
    3605         forceFactorization_ = CoinMax(1, (maxFactor >> 1));
    3606       } else if (numberBlackMarks>2) {
    3607         forceFactorization_ = CoinMax(1, (forceFactorization_ >> 1));
     3531      if ((stateOfProblem_ & PESSIMISTIC) == 0 || true) {
     3532        if (largestDualError_ > 10.0 * CoinMax(lastDualError_, 1.0e-6)
     3533          || largestPrimalError_ > 10.0 * CoinMax(lastPrimalError_, 1.0e-6))
     3534          maxFactor = CoinMin(maxFactor, 20);
     3535        forceFactorization_ = CoinMax(1, (maxFactor >> 1));
     3536      } else if (numberBlackMarks > 2) {
     3537        forceFactorization_ = CoinMax(1, (forceFactorization_ >> 1));
    36083538      }
    36093539    }
    36103540    stateOfProblem_ |= PESSIMISTIC;
    3611     if (numberBlackMarks>=10)
     3541    if (numberBlackMarks >= 10)
    36123542      forceFactorization_ = 1;
    36133543  }
    3614   lastPrimalError_=largestPrimalError_;
    3615   lastDualError_=largestDualError_;
    3616   lastFirstFree_=firstFree_;
    3617   if (ignoreStuff==2) {
     3544  lastPrimalError_ = largestPrimalError_;
     3545  lastDualError_ = largestDualError_;
     3546  lastFirstFree_ = firstFree_;
     3547  if (ignoreStuff == 2) {
    36183548    // in values pass
    3619     lastFirstFree_=-1;
     3549    lastFirstFree_ = -1;
    36203550    // firstFree_=-1;
    36213551  }
     
    36263556  if (problemStatus_ > 2)
    36273557    rawObjectiveValue_ = approximateObjective;
    3628   if (problemStatus_ == 1 && (progressFlag_&8) != 0 &&
    3629       fabs(rawObjectiveValue_) > 1.0e10 )
     3558  if (problemStatus_ == 1 && (progressFlag_ & 8) != 0 && fabs(rawObjectiveValue_) > 1.0e10)
    36303559    problemStatus_ = 10; // infeasible - but has looked feasible
    36313560  checkMoveBack(true);
     
    37703699}
    37713700// see if cutoff reached
    3772 bool
    3773 AbcSimplexDual::checkCutoff(bool computeObjective)
     3701bool AbcSimplexDual::checkCutoff(bool computeObjective)
    37743702{
    3775   double objValue=COIN_DBL_MAX;
     3703  double objValue = COIN_DBL_MAX;
    37763704  if (computeObjective)
    37773705    objValue = computeInternalObjectiveValue();
     
    37813709  getDblParam(ClpDualObjectiveLimit, limit);
    37823710  // Looks as if numberAtFakeBound() being computed too often
    3783   if(fabs(limit) < 1.0e30 && objValue >
    3784      limit && !numberAtFakeBound()) {
     3711  if (fabs(limit) < 1.0e30 && objValue > limit && !numberAtFakeBound()) {
    37853712    bool looksInfeasible = !numberDualInfeasibilities_;
    3786     if (objValue > limit + fabs(0.1 * limit) + 1.0e2 * sumDualInfeasibilities_ + 1.0e4 &&
    3787         sumDualInfeasibilities_ < largestDualError_ && numberIterations_ > 0.5 * numberRows_ + 1000)
     3713    if (objValue > limit + fabs(0.1 * limit) + 1.0e2 * sumDualInfeasibilities_ + 1.0e4 && sumDualInfeasibilities_ < largestDualError_ && numberIterations_ > 0.5 * numberRows_ + 1000)
    37883714      looksInfeasible = true;
    3789     if (looksInfeasible&&!computeObjective)
     3715    if (looksInfeasible && !computeObjective)
    37903716      objValue = computeInternalObjectiveValue();
    37913717    if (looksInfeasible) {
    37923718      // Even if not perturbed internal costs may have changed
    37933719      // be careful
    3794       if(objValue > limit) {
    3795         problemStatus_ = 1;
    3796         secondaryStatus_ = 1; // and say was on cutoff
    3797         return true;
     3720      if (objValue > limit) {
     3721        problemStatus_ = 1;
     3722        secondaryStatus_ = 1; // and say was on cutoff
     3723        return true;
    37983724      }
    37993725    }
     
    38073733   returns 3 if skip this iteration and re-factorize
    38083734*/
    3809 int
    3810 AbcSimplexDual::flipBounds()
     3735int AbcSimplexDual::flipBounds()
    38113736{
    3812   CoinIndexedVector & array = usefulArray_[arrayForFlipBounds_];
    3813   CoinIndexedVector & output = usefulArray_[arrayForFlipRhs_];
     3737  CoinIndexedVector &array = usefulArray_[arrayForFlipBounds_];
     3738  CoinIndexedVector &output = usefulArray_[arrayForFlipRhs_];
    38143739  output.clear();
    3815   int numberFlipped=array.getNumElements();
     3740  int numberFlipped = array.getNumElements();
    38163741  if (numberFlipped) {
    3817 #if CLP_CAN_HAVE_ZERO_OBJ>1
    3818     if ((specialOptions_&2097152)==0) {
     3742#if CLP_CAN_HAVE_ZERO_OBJ > 1
     3743    if ((specialOptions_ & 2097152) == 0) {
    38193744#endif
    38203745      // do actual flips
    38213746      // do in parallel once got spare space in factorization
    3822 #if ABC_PARALLEL==2
    3823 #endif
    3824       int number=array.getNumElements();
    3825       const int *  COIN_RESTRICT which=array.getIndices();
    3826       double *  COIN_RESTRICT work = array.denseVector();
    3827      
    3828       double *  COIN_RESTRICT solution = abcSolution_;
    3829       const double *  COIN_RESTRICT lower = abcLower_;
    3830       const double *  COIN_RESTRICT upper = abcUpper_;
     3747#if ABC_PARALLEL == 2
     3748#endif
     3749      int number = array.getNumElements();
     3750      const int *COIN_RESTRICT which = array.getIndices();
     3751      double *COIN_RESTRICT work = array.denseVector();
     3752
     3753      double *COIN_RESTRICT solution = abcSolution_;
     3754      const double *COIN_RESTRICT lower = abcLower_;
     3755      const double *COIN_RESTRICT upper = abcUpper_;
    38313756#if CLEANUP_DJS
    3832       double *  COIN_RESTRICT cost = abcCost_;
    3833       double *  COIN_RESTRICT dj = abcDj_;
     3757      double *COIN_RESTRICT cost = abcCost_;
     3758      double *COIN_RESTRICT dj = abcDj_;
    38343759      // see if we can clean up djs
    38353760      // may have perturbation
    3836       const double * COIN_RESTRICT originalCost = abcPerturbation_;
     3761      const double *COIN_RESTRICT originalCost = abcPerturbation_;
    38373762#else
    3838       const double *  COIN_RESTRICT cost = abcCost_;
    3839       const double *  COIN_RESTRICT dj = abcDj_;
    3840 #endif
    3841       const double multiplier[] = { 1.0, -1.0};
     3763    const double *COIN_RESTRICT cost = abcCost_;
     3764    const double *COIN_RESTRICT dj = abcDj_;
     3765#endif
     3766      const double multiplier[] = { 1.0, -1.0 };
    38423767      for (int i = 0; i < number; i++) {
    3843         double value=work[i]*theta_;
    3844         work[i]=0.0;
    3845         int iSequence = which[i];
    3846         unsigned char iStatus = internalStatus_[iSequence]&3;
    3847         assert ((internalStatus_[iSequence]&7)==0||
    3848                 (internalStatus_[iSequence]&7)==1);
    3849         double mult = multiplier[iStatus];
    3850         double djValue = dj[iSequence] * mult-value;
    3851         //double perturbedTolerance = abcPerturbation_[iSequence];
    3852         if (djValue<-currentDualTolerance_) {
    3853           // might just happen - if so just skip
    3854           assert (iSequence!=sequenceIn_);
    3855           double movement=(upper[iSequence]-lower[iSequence])*mult;
    3856           if (iStatus==0) {
    3857             // at lower bound
    3858             // to upper bound
    3859             setInternalStatus(iSequence, atUpperBound);
    3860             solution[iSequence] = upper[iSequence];
     3768        double value = work[i] * theta_;
     3769        work[i] = 0.0;
     3770        int iSequence = which[i];
     3771        unsigned char iStatus = internalStatus_[iSequence] & 3;
     3772        assert((internalStatus_[iSequence] & 7) == 0 || (internalStatus_[iSequence] & 7) == 1);
     3773        double mult = multiplier[iStatus];
     3774        double djValue = dj[iSequence] * mult - value;
     3775        //double perturbedTolerance = abcPerturbation_[iSequence];
     3776        if (djValue < -currentDualTolerance_) {
     3777          // might just happen - if so just skip
     3778          assert(iSequence != sequenceIn_);
     3779          double movement = (upper[iSequence] - lower[iSequence]) * mult;
     3780          if (iStatus == 0) {
     3781            // at lower bound
     3782            // to upper bound
     3783            setInternalStatus(iSequence, atUpperBound);
     3784            solution[iSequence] = upper[iSequence];
    38613785#if CLEANUP_DJS
    3862             if (cost[iSequence]<originalCost[iSequence]) {
    3863               double difference = CoinMax(cost[iSequence]-originalCost[iSequence],djValue);
    3864               dj[iSequence]-=difference;
    3865               cost[iSequence]-=difference;
    3866             }
    3867 #endif
    3868           } else {
    3869             // at upper bound
    3870 &nbs