Changeset 1093


Ignore:
Timestamp:
Oct 29, 2008 8:06:51 AM (11 years ago)
Author:
rlh
Message:

Runs only when general integer variables exist. Fixed memory leakes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cbc/src/CbcHeuristicRandRound.cpp

    r1092 r1093  
    9595  // rlh: Todo: Memory Cleanup
    9696
     97  //  std::cout << "Entering the Randomized Rounding Heuristic" << std::endl;
     98
    9799  setWhen(1);  // setWhen(1) didn't have the effect I expected (e.g., run once).
    98100             
     
    103105  int passNumber = model_->getCurrentPassNumber();
    104106  //    Just do once
    105   if (!atRoot||passNumber!=1)
     107  if (!atRoot||passNumber!=1){
     108    // std::cout << "Leaving the Randomized Rounding Heuristic" << std::endl;
    106109    return 0;
    107 
     110  }
     111   
    108112  std::cout << "Entering the Randomized Rounding Heuristic" << std::endl;
    109  
    110113  typedef struct {
    111114    int numberSolutions;
     
    143146  simplex->allSlackBasis();
    144147 
    145   // Calling primal invalidates pointers to some rim vectors,
     148  // Calling primal() invalidates pointers to some rim vectors,
    146149  // like...row sense (!)
    147150  simplex->primal();
     
    163166  // Find the integer variables (use columnType(?))
    164167  // One if not continuous, that is binary or general integer)
     168  // columnType() = 0 continuous
     169  //              = 1 binary
     170  //              = 2 general integer
    165171  bool * varClassInt = new bool[numCols];
     172  const char* columnType = clpSolver->columnType();
     173  int numGenInt = 0;   
    166174  for(int i=0; i<numCols; i++)
    167175    {
     
    170178      else
    171179        varClassInt[i] = 1;
    172     }
     180      if (columnType[i]==2) numGenInt++;
     181    }
     182
     183  // Heuristic is for problems with general integer variables.
     184  // If there are none, quit.
     185  if (numGenInt++<1){
     186    delete [] varClassInt ;
     187    std::cout << "Leaving the Randomized Rounding Heuristic" << std::endl;
     188    return 0;
     189 }
     190
    173191
    174192  // -Get the rows sense
     
    469487          if(feasibility)
    470488            {
    471               printf("Feasible Found!!\n");
     489              printf("Feasible Found.\n");
    472490              printf("%.2f\n", CoinCpuTime()-start);
    473491              numFeasibles++;
     
    480498            }
    481499        }
     500      delete [] roundRp;
    482501    }
    483502  printf("Number of Feasible Corners: %d\n", numFeasibleCorners);
     
    487506  printf("time: %.2f\n",CoinCpuTime()-start);
    488507 
    489   if (numFeasibles == 0) return 0;
     508  if (numFeasibles == 0) {
     509    // cleanup
     510    delete [] varClassInt;
     511    for (int i=0; i<numRows; i++)
     512      delete matrix[i];
     513    delete [] matrix;
     514    delete [] newObj;
     515    delete [] index;
     516    for (int i=0; i<numberSolutions; i++)
     517      delete cornerPoints[i];
     518    delete [] cornerPoints;
     519    delete [] rp;
     520    return 0;
     521  }
    490522 
    491523  // We found something better
     
    494526    betterSolution[k] =  feasibles[numFeasibles-1][k];
    495527  } 
     528  delete [] varClassInt;
     529  for (int i=0; i<numRows; i++)
     530    delete matrix[i];
     531  delete [] matrix;
     532  delete [] newObj;
     533  delete [] index;
     534  for (int i=0; i<numberSolutions; i++)
     535      delete cornerPoints[i];
     536    delete [] cornerPoints;
     537  delete [] rp;
    496538  std::cout << "Leaving the Randomized Rounding Heuristic" << std::endl;
    497539  return 1;
Note: See TracChangeset for help on using the changeset viewer.