11 #include "CoinFinite.hpp"
12 #include "CbcModel.hpp"
13 #include "CbcConfig.h"
27 stop_diving_on_cutoff_(false)
32 treeCleaning_(rhs.treeCleaning_),
33 nextOnBranch_(rhs.nextOnBranch_),
34 stop_diving_on_cutoff_(rhs.stop_diving_on_cutoff_)
42 CbcTree::operator=(rhs);
67 std::cout<<
"CbcDiver::top"<<std::endl;
72 else return CbcTree::top();
80 std::cout<<
"CbcDiver::push"<<std::endl;
84 if (x->branchingObject()->numberBranchesLeft() == x->branchingObject()->numberBranches()) {
97 std::cout<<
"CbcDiver::pop"<<std::endl;
110 std::cout<<
"CbcDiver::bestNode"<<std::endl;
118 return CbcTree::bestNode(cutoff);
125 assert(
true &&
"We did not think we get here.");
129 return CbcTree::bestNode(cutoff);
149 CbcTree::cleanTree(model,cutoff, bestPossibleObjective);
158 for (
unsigned int i = 0 ; i < nodes_.size() ; i++) {
159 if (nodes_[i] == NULL)
continue;
160 const double & obj = nodes_[i]->objectiveValue();
161 if (obj < bestPossibleObjective) {
162 bestPossibleObjective = obj;
165 return bestPossibleObjective;
172 roptions->AddStringOption2(
173 "stop_diving_on_cutoff",
174 "Flag indicating whether we stop diving based on guessed feasible objective and the current cutoff",
178 roptions->setOptionExtraInfo(
"stop_diving_on_cutoff", 63);
197 treeCleaning_(false),
199 candidateChild_(NULL),
200 stop_diving_on_cutoff_(false)
205 treeCleaning_(rhs.treeCleaning_),
206 nextOnBranch_(rhs.nextOnBranch_),
207 candidateChild_(rhs.candidateChild_),
208 stop_diving_on_cutoff_(rhs.stop_diving_on_cutoff_)
216 CbcTree::operator=(rhs);
242 std::cout<<
"CbcProbedDiver::top"<<std::endl;
250 else return CbcTree::top();
258 std::cout<<
"CbcProbedDiver::push"<<std::endl;
262 if (x->branchingObject()->numberBranchesLeft() == x->branchingObject()->numberBranches()) {
266 printf(
"Putting parent %i. objective value %g\n", x, x->objectiveValue());
273 printf(
"Putting first kid %i. objective value %g\n", x, x->objectiveValue());
278 printf(
"Putting second kid %i. objective value %g\n", x, x->objectiveValue());
283 printf(
"first child %i is found better.\n", x);
292 printf(
"second child %i is found better\n", x);
302 printf(
"Putting back parent %i.\n",x);
306 printf(
"Putting nextOnBranch_ in candidateChild_.\n");
321 std::cout<<
"CbcProbedDiver::pop"<<std::endl;
337 std::cout<<
"CbcProbedDiver::bestNode"<<std::endl;
350 return CbcTree::bestNode(cutoff);
361 assert(
true &&
"Should not get here.");
367 printf(
"brother was infeasible!!\n``");
376 return CbcTree::bestNode(cutoff);
379 printf(
"Diving on %i. obj=%g guessed=%g\n",
388 assert(
true &&
"Should not get here.");
390 CbcNode * ret_val = CbcTree::bestNode(cutoff);
392 printf(
"Picking top of the heap node %i", ret_val);
417 CbcTree::cleanTree(model,cutoff, bestPossibleObjective);
428 for (
unsigned int i = 0 ; i < nodes_.size() ; i++) {
429 if (nodes_[i] == NULL)
continue;
430 const double & obj = nodes_[i]->objectiveValue();
431 if (obj < bestPossibleObjective) {
432 bestPossibleObjective = obj;
435 return bestPossibleObjective;
451 treeCleaning_(false),
454 divingBoardDepth_(-1),
458 maxDiveBacktracks_(2),
459 maxDiveDepth_(COIN_INT_MAX),
465 treeCleaning_(rhs.treeCleaning_),
467 diveListSize_(rhs.diveListSize_),
468 divingBoardDepth_(rhs.divingBoardDepth_),
469 cutoff_(rhs.cutoff_),
470 nBacktracks_(rhs.nBacktracks_),
471 maxDepthBFS_(rhs.maxDepthBFS_),
472 maxDiveBacktracks_(rhs.maxDiveBacktracks_),
473 maxDiveDepth_(rhs.maxDiveDepth_),
481 CbcTree::operator=(rhs);
513 std::cout<<
"CbcDfsDiver::top"<<std::endl;
516 assert(
dive_.empty());
520 return dive_.front();
522 else return CbcTree::top();
531 std::cout<<
"CbcDfsDiver::push"<<std::endl;
535 assert(
dive_.empty());
553 std::cout<<
"CbcDfsDiver::pop"<<std::endl;
556 assert(
dive_.empty());
558 if (!
dive_.empty()) {
571 std::cout<<
"CbcDfsDiver::bestNode"<<std::endl;
575 for (
unsigned int i = 0 ; i < nodes_.size() ; i++) {
576 if (nodes_[i]->objectiveValue() >= cutoff)
577 std::cerr<<
"CbcDfsDiver::bestNode"<<std::endl
578 <<nodes_[i]->objectiveValue()<<
", "<<cutoff<<std::endl;
579 assert(nodes_[i]->objectiveValue() < cutoff);
586 CbcNode * node =
dive_.back();
587 assert(node != NULL);
601 assert(
dive_.empty());
602 CbcTree::bestNode(cutoff);
605 CbcNode * node = NULL;
608 std::cerr<<
"CbcDfsDiver::bestNode"
609 <<
", examining node"<<std::endl;
611 assert(!
dive_.empty());
612 node =
dive_.front();
617 if (node->objectiveValue() > cutoff) {
620 std::cout<<
"CbcDfsDiver::bestNode"
621 <<
", node above cutoff"<<std::endl;
627 else if (0 && node->guessedObjectiveValue() > cutoff) {
629 std::cout<<
"CbcDfsDiver::bestNode"
630 <<
", node estimates "<<node->guessedObjectiveValue()<<
"above cutoff"
639 std::cout<<
"CbcDfsDiver::bestNode"
640 <<
", node too deep"<<std::endl;
646 else if (node->branchingObject()->numberBranchesLeft() < node->branchingObject()->numberBranches()) {
649 std::cout<<
"CbcDfsDiver::bestNode"
650 <<
", backtracking"<<std::endl;
655 std::cout<<
"CbcDfsDiver::bestNode"
656 <<
", maximum number of backtracks attained emptying dive_"<<std::endl;
659 if (node != NULL) CbcTree::push(node);
665 assert(node == NULL);
666 assert(
dive_.empty());
668 node = CbcTree::bestNode(cutoff);
677 while (!
dive_.empty() ){
678 CbcTree::push(
dive_.front());
682 for (std::list<CbcNode *>::iterator i =
dive_.begin() ; i !=
dive_.end();
690 return (CbcTree::empty() &&
dive_.empty());
700 std::cout<<
"CbcDfsDiver::cleanTree"<<std::endl;
701 std::cout<<
"cutoff: "<<cutoff<<std::endl;
705 CbcTree::cleanTree(model,cutoff, bestPossibleObjective);
714 std::cout<<
"CbcDfsDiver::getBestPossibleObjective"<<std::endl;
716 double bestPossibleObjective = CbcTree::empty() ? COIN_DBL_MAX : CbcTree::getBestPossibleObjective();
717 for (std::list<CbcNode *>::iterator i =
dive_.begin() ; i !=
dive_.end() ; i++) {
718 if (*i == NULL)
continue;
719 const double & obj = (*i)->objectiveValue();
720 if (obj < bestPossibleObjective) {
721 bestPossibleObjective = obj;
724 return bestPossibleObjective;
732 roptions->AddLowerBoundedIntegerOption(
"max_backtracks_in_dive",
733 "Set the number of backtracks in a dive when using dfs-dive tree search"
737 roptions->setOptionExtraInfo(
"max_backtracks_in_dive",27);
739 roptions->AddLowerBoundedIntegerOption(
"max_dive_depth",
740 "When using dfs-dive search. Maximum depth to go to from the diving "
741 "board (node where the diving started.",
744 roptions->setOptionExtraInfo(
"max_dive_depth",27);
762 if (newMode !=
mode_) {
768 std::cout<<
"CbcDfsDiver::setComparisonMode"
772 std::cout<<
"Enlarge"<<std::endl;
775 std::cout<<
"FindSolutions"<<std::endl;
778 std::cout<<
"CloseBound"<<std::endl;
781 std::cout<<
"LimitTreeSize"<<std::endl;
785 CbcTree::setComparison(*comparison_.test_);
798 std::cout<<
"CbcDfsDiver::newSolution"
800 std::cout<<
"Found "<<model->getSolutionCount()<<
" solutions"<<std::endl;
802 bool r_value =
false;
831 throw CoinError(
"DiverCompare",
"test",
" Unknown mode for comparison.");
840 double objectiveAtContinuous,
841 int numberInfeasibilitiesAtContinuous)
virtual ~CbcDfsDiver()
Destructor.
void initialize(BabSetupBase &b)
Initialize the method (get options)
void setComparisonMode(ComparisonModes newMode)
Changes the mode of comparison of the tree for "safety reasons" if the mode really changes we always ...
bool treeCleaning_
Say if we are cleaning the tree (then only call CbcTree functions).
CbcDiver()
Default constructor.
For undocumented options.
void initialize(BabSetupBase &b)
Initialize the method (get options)
virtual bool empty()
Test if empty.
CbcNode * candidateChild_
Candidate child explored.
virtual bool every1000Nodes(CbcModel *model, int numberNodes)
Called 1000 nodes.
CbcDiver & operator=(const CbcDiver &rhs)
Assignment operator.
virtual void push(CbcNode *x)
Add node to the heap.
double cutoff_
Last reported cutoff.
std::list< CbcNode * > dive_
List of the nodes in the current dive.
virtual ~CbcDiver()
Destructor.
CbcCompareBase * comparisonDive_
Comparison method used in diving mode.
void initialize(BabSetupBase &b)
Initialize the method (get options)
bool treeCleaning_
Say if we are cleaning the tree (then only call CbcTree functions).
virtual CbcNode * top() const
Return top node (next node to process.*/.
virtual CbcNode * top() const
Return top node (next node to process.*/.
virtual void push(CbcNode *x)
Add node to the heap.
int nBacktracks_
number of backtracks done in current dive.
int treeCleaning_
Flag to say that we are currently cleaning the tree and should work only on the heap.
virtual void pop()
Remove the top node of the heap.
CbcNode * nextOnBranch_
Noext node on the branch.
virtual double getBestPossibleObjective()
Get best possible objective function in the tree.
A class to have all elements necessary to setup a branch-and-bound.
virtual bool empty()
Test if empty.
static void registerOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
Register the options of the method.
virtual CbcTree * clone() const
Virtual copy constructor.
CbcDfsDiver * diver_
Pointer to the CbcDfsDiver handling the tree.
virtual CbcNode * bestNode(double cutoff)
Remove the best node from the heap and return it.
int maxDiveBacktracks_
Maximum number of backtrack in one dive.
bool stop_diving_on_cutoff_
Flag indicating if we want to stop diving based on the guessed objective value and the cutoff value ...
virtual CbcNode * bestNode(double cutoff)
Remove the best node from the heap and return it.
int maxDepthBFS_
Maximum depth until which we'll do a bredth-first-search.
virtual void cleanTree(CbcModel *model, double cutoff, double &bestPossibleObjective)
Prune the tree using an objective function cutoff.
virtual bool newSolution(CbcModel *model)
Called after each new solution.
virtual CbcNode * top() const
Return top node (next node to process.*/.
A more elaborate diving class.
virtual void cleanTree(CbcModel *model, double cutoff, double &bestPossibleObjective)
Prune the tree using an objective function cutoff.
CbcDfsDiver()
Default constructor.
virtual double getBestPossibleObjective()
Get best possible objective function in the tree.
CbcDfsDiver & operator=(const CbcDfsDiver &rhs)
Assignment operator.
ComparisonModes getComparisonMode()
get the mode of comparison of the tree.
ComparisonModes mode_
Current mode of the diving strategy.
virtual bool test(CbcNode *x, CbcNode *y)
This is test function.
int numberNodesToLimitTreeSize_
Number of nodes before we command diver_ to limit the tree size.
At the very beginning we might want to enlarge the tree just a bit.
CbcProbedDiver()
Default constructor.
bool stop_diving_on_cutoff_
Flag indicating if we want to stop diving based on the guessed objective value and the cutoff value ...
CbcProbedDiver & operator=(const CbcProbedDiver &rhs)
Assignment operator.
virtual void pop()
Remove the top node of the heap.
virtual CbcTree * clone() const
Virtual copy constructor.
int divingBoardDepth_
Depth of the node from which diving was started (we call this node the diving board).
virtual CbcTree * clone() const
Virtual copy constructor.
virtual void pop()
Remove the top node of the heap.
CbcCompareBase * comparisonBound_
Comparison method used bound mode.
static void registerOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
Register the options of the method.
Ipopt::SmartPtr< Ipopt::OptionsList > options()
Acces list of Options.
CbcCompareDepth comparisonDepth_
Comparison method used when limit tree size.
int numberSolToStopDive_
Number of solution before we command diver_ to stop diving.
void pushDiveOntoHeap(double cutoff)
Pushes onto heap all the nodes with objective value > cutoff.
virtual void cleanTree(CbcModel *model, double cutoff, double &bestPossibleObjective)
Prune the tree using an objective function cutoff.
Class to do probed diving in the tree.
CbcNode * nextOnBranch_
Next node on the branch.
virtual bool empty()
Test if empty.
virtual CbcNode * bestNode(double cutoff)
Remove the best node from the heap and return it.
virtual ~CbcProbedDiver()
Destructor.
virtual void push(CbcNode *x)
Add node to the heap.
Class to do diving in the tree.
virtual double getBestPossibleObjective()
Get best possible objective function in the tree.
int diveListSize_
Record dive list size for constant time access.
const char * prefix() const
Get prefix to use for options.
int maxDiveDepth_
Maximum depth to go from divingBoard.
void fint fint fint real fint real * x