Bonmin  1.7
BonRandomChoice.hpp
Go to the documentation of this file.
00001 // (C) Copyright CNRS 2008
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // Authors :
00006 // Pierre Bonami, LIF, CNRS-Marseille Universites.
00007 //
00008 // Date : 03/17/2008
00009 #ifndef BonRandomChoice_H
00010 #define BonRandomChoice_H
00011 
00012 #include "OsiChooseVariable.hpp"
00013 #include "OsiSolverInterface.hpp"
00014 #include <list>
00015 #include <cmath>
00016 
00017 class BonRandomChoice : public OsiChooseVariable {
00018   public:
00020   BonRandomChoice(): OsiChooseVariable(){
00021   }
00022 
00023   //Constructor from solver
00024   BonRandomChoice(const OsiSolverInterface * solver):
00025     OsiChooseVariable(solver){
00026   }
00027 
00028   // Copy constructor
00029   BonRandomChoice(const BonRandomChoice &other):
00030     OsiChooseVariable(other){
00031   }
00032 
00033   // Assignment operator
00034   BonRandomChoice & operator=(const BonRandomChoice &rhs){
00035     OsiChooseVariable::operator=(rhs);
00036     return (*this);
00037   }
00038 
00039   // Virtual copy
00040   virtual OsiChooseVariable * clone() const{
00041      return new BonRandomChoice(*this);
00042   }
00043 
00045   virtual ~BonRandomChoice(){
00046   }
00047 
00050   virtual int setupList(OsiBranchingInformation * info, bool initialize);
00051 
00052   virtual int chooseVariable( OsiSolverInterface * solver,
00053                               OsiBranchingInformation * info,
00054                               bool fixVariables){
00055     if(numberUnsatisfied_){
00056       int chosen = (int) (floor(CoinDrand48() * (numberUnsatisfied_)));
00057       bestObjectIndex_ = list_[chosen];
00058       bestWhichWay_ = solver->object(bestObjectIndex_)->whichWay();
00059       firstForcedObjectIndex_ = -1;
00060       firstForcedWhichWay_ =-1;
00061       return 0;
00062     }
00063     else {
00064       return 1;
00065     }
00066   }
00067 };
00068 #endif