/home/coin/SVN-release/OS-1.1.1/Bonmin/src/CbcBonmin/BonGuessHeuristic.cpp

Go to the documentation of this file.
00001 // (C) Copyright International Business Machines  2007
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // Authors :
00006 // Andreas Waechter          IBM       2007-09-01
00007 
00008 #include "BonGuessHeuristic.hpp"
00009 #include "CoinHelperFunctions.hpp"
00010 #include "CbcModel.hpp"
00011 #include "BonChooseVariable.hpp"
00012 
00013 //#include "OsiAuxInfo.hpp"
00014 namespace Bonmin
00015 {
00017   GuessHeuristic::GuessHeuristic(CbcModel &model)
00018       :
00019       CbcHeuristic(model)
00020   {}
00021 
00023   int
00024   GuessHeuristic::solution(double &solutionValue, double *betterSolution)
00025   {
00026     // Get pointer to pseudo costs object
00027     const BonChooseVariable* chooseMethod = dynamic_cast<BonChooseVariable*>(model_->branchingMethod()->chooseMethod());
00028 
00029     if (!chooseMethod) {
00030       (*model_->messageHandler()) << "Can't get pseudo costs!!!\n";
00031       solutionValue = model_->getCurrentMinimizationObjValue();
00032       return -1;
00033     }
00034     const OsiPseudoCosts& pseudoCosts = chooseMethod->pseudoCosts();
00035     int numberObjects = pseudoCosts.numberObjects();
00036     assert(numberObjects == model_->numberObjects());
00037     const double* upTotalChange = pseudoCosts.upTotalChange();
00038     const double* downTotalChange = pseudoCosts.downTotalChange();
00039     const int* upNumber = pseudoCosts.upNumber();
00040     const int* downNumber = pseudoCosts.downNumber();
00041 
00042     double sumUpTot = 0.;
00043     int numberUpTot = 0;
00044     double sumDownTot = 0.;
00045     int numberDownTot = 0;
00046     for (int i=0;i<numberObjects;i++) {
00047       sumUpTot += upTotalChange[i];
00048       numberUpTot += upNumber[i];
00049       sumDownTot += downTotalChange[i];
00050       numberDownTot += downNumber[i];
00051     }
00052     if (!numberUpTot || !numberDownTot) {
00053       // don't have ANY pseudo-costs information yet
00054       solutionValue = COIN_DBL_MAX;
00055       return -1;
00056     }
00057     double upAvrg=sumUpTot/numberUpTot;
00058     double downAvrg=sumDownTot/numberDownTot;
00059 
00060     OsiObject** object =  model_->objects();
00061 
00062     solutionValue = model_->getCurrentMinimizationObjValue();
00063     for (int iObj = 0; iObj < numberObjects; iObj++) {
00064       //printf("%3d upest=%e uptot=%e upnum=%d downest=%e downtot=%e downnum=%d  ", iObj, object[iObj]->upEstimate(), upTotalChange[iObj], upNumber[iObj], object[iObj]->downEstimate(), downTotalChange[iObj], downNumber[iObj]);
00065 
00066       double upEstimate = upNumber[iObj] ? object[iObj]->upEstimate()*upTotalChange[iObj]/upNumber[iObj] : object[iObj]->upEstimate()*upAvrg;
00067       double downEstimate = downNumber[iObj] ? object[iObj]->downEstimate()*downTotalChange[iObj]/downNumber[iObj] : object[iObj]->downEstimate()*downAvrg;
00068       //printf("up=%e down=%e\n", upEstimate, downEstimate);
00069       solutionValue += CoinMin(upEstimate,downEstimate);
00070     }
00071     //printf("solutionValue = %e\n", solutionValue);
00072     return -1;
00073   }
00074 
00075 }

Generated on Tue Sep 30 03:01:23 2008 by  doxygen 1.4.7