Skip to content

Commit

Permalink
changes for fathomMany and deterministic parallel - see top of CbcGen…
Browse files Browse the repository at this point in the history
…eralDepth.cpp for more
  • Loading branch information
jjhforrest committed Jun 25, 2024
1 parent ca088df commit 9a2048c
Show file tree
Hide file tree
Showing 7 changed files with 483 additions and 59 deletions.
3 changes: 3 additions & 0 deletions src/CbcBranchingObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class CBCLIB_EXPORT CbcBranchingObject : public OsiBranchingObject {
branchIndex_ = 0;
numberBranches_ = value;
}
/// Number of branches to do
inline int numberBranches() const
{ return numberBranches_; }

/** \brief Execute the actions required to branch, as specified by the
current state of the branching object, and advance the object's
Expand Down
58 changes: 50 additions & 8 deletions src/CbcGeneralDepth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@
#include "ClpNode.hpp"
#include "ClpFactorization.hpp"
#include "CbcBranchDynamic.hpp"
/* I (JJHF) am looking at the fathomMany option in Cbc. This does a few
branches using Clp and tries to be much more efficient as it knows
about Clp. It will also lend itself well to deterministc parallel
and that is what this update to master is all about. As checked in
this time it should give identical results as before but now allows
fathomMany in deterministic parallel. fathomMany is switched on by
-depth +n which varies size of mini tree. Deterministic parallel
is switched on by -thread 10k where k is number of threads
(k > number of cpus can be good).
I will be trying to tune further. Ideas which seem possible but
changed current behavior will be found in areas marked with
DETERMINISTIC_TUNING e.g.
// DETERMINISTIC_TUNING think harder or
#if 0 // DETERMINISTIC_TUNING or just
#if DETERMINISTIC_TUNING > n etc
*/
// Default Constructor
CbcGeneralDepth::CbcGeneralDepth()
: CbcGeneral()
Expand All @@ -54,6 +71,7 @@ CbcGeneralDepth::CbcGeneralDepth(CbcModel *model, int maximumDepth)
assert(maximumDepth_ < 10000000);
if (maximumDepth_ == 0)
maximumDepth_ = 1;
// DETERMINISTIC_TUNING think harder
#define MAX_DEPTH 1000
#define MAX_NODES 200
int realMaximumDepth = maximumDepth_ % MAX_DEPTH;
Expand All @@ -63,7 +81,13 @@ CbcGeneralDepth::CbcGeneralDepth(CbcModel *model, int maximumDepth)
maximumNodes_ = 1 + 1 - maximumDepth_;
maximumNodes_ = CoinMin(maximumNodes_, 1 + abs(realMaximumDepth) + MAX_NODES);
maximumNodes_ = CoinMax(maximumNodes_, 10);
if (maximumNodes_) {
// special for 1
if (maximumDepth_==1) {
// DETERMINISTIC_TUNING think harder
// amount will vary
maximumNodes_ = 1 + 20 + MAX_NODES;
}
{
nodeInfo_ = new ClpNodeStuff();
nodeInfo_->maximumNodes_ = maximumNodes_;
ClpNodeStuff *info = nodeInfo_;
Expand All @@ -79,8 +103,6 @@ CbcGeneralDepth::CbcGeneralDepth(CbcModel *model, int maximumDepth)
for (int i = 0; i < maximumNodes_; i++)
nodeInfo[i] = NULL;
info->nodeInfo_ = nodeInfo;
} else {
nodeInfo_ = NULL;
}
}

Expand Down Expand Up @@ -156,6 +178,22 @@ CbcGeneralDepth::infeasibility(const OsiBranchingInformation * /*info*/,
int & /*preferredWay*/) const
{
whichSolution_ = -1;
if (maximumDepth_==1) {
// DETERMINISTIC_TUNING think harder
// vary
cbc_node_count nfathoms = model_->getFathomCount();
int depth =5 ;
while (nfathoms && depth <20) {
nfathoms /= 2;
depth++;
}
int nnodes = (1 << depth) + 1 + depth;
nnodes = CoinMin(nnodes, 1 + 20 + MAX_NODES);
nnodes = CoinMax(nnodes, 10);
nodeInfo_->maximumNodes_ = nnodes;
nodeInfo_->nDepth_ = depth;
}
double returnValue;
// should use genuine OsiBranchingInformation usefulInfo = model_->usefulInformation();
// for now assume only called when correct
//if (usefulInfo.depth_>=4&&!model_->parentModel()
Expand Down Expand Up @@ -193,7 +231,6 @@ CbcGeneralDepth::infeasibility(const OsiBranchingInformation * /*info*/,
info->fillPseudoCosts(down, up, priority, numberDown, numberUp,
numberDownInfeasible,
numberUpInfeasible, numberIntegers);
info->presolveType_ = 1;
// possible bug if 0 as can have mismatch on dense/nondense factorization
// could check if number rows large enough
info->presolveType_ = 1;
Expand Down Expand Up @@ -231,6 +268,8 @@ CbcGeneralDepth::infeasibility(const OsiBranchingInformation * /*info*/,
if (strength != OsiHintIgnore && takeHint && saveLevel == 1)
simplex->setLogLevel(0);
clpSolver->setBasis();
// DETERMINISTIC_TUNING think harder
//info->presolveType_=1;
whichSolution_ = simplex->fathomMany(info);
//printf("FAT %d nodes, %d iterations\n",
//info->numberNodesExplored_,info->numberIterations_);
Expand Down Expand Up @@ -313,17 +352,19 @@ CbcGeneralDepth::infeasibility(const OsiBranchingInformation * /*info*/,
}
int numberDo = numberNodes_;
if (numberDo > 0 || whichSolution_ >= 0) {
return 0.5;
returnValue = 0.5;
} else {
// no solution
return COIN_DBL_MAX; // say infeasible
returnValue = COIN_DBL_MAX; // say infeasible
}
} else {
return -1.0;
returnValue = -1.0;
}
} else {
return -1.0;
returnValue = -1.0;
}
//nodeInfo_->maximumNodes_ = saveMaximumNodes;
return returnValue;
}

// This looks at solution and sets bounds to contain solution
Expand Down Expand Up @@ -739,6 +780,7 @@ CbcOneGeneralBranchingObject::branch()
decrementNumberBranchesLeft();
assert(!numberBranchesLeft());
object_->setWhichNode(whichOne_);
object_->setModel(model_);
object_->branch();
return 0.0;
}
Expand Down
Loading

0 comments on commit 9a2048c

Please sign in to comment.