11 #include "CoinPackedMatrix.hpp" 12 #include "OsiCuts.hpp" 13 #include "CoinHelperFunctions.hpp" 14 #include "OsiBranchingObject.hpp" 16 class OsiSolverInterface;
20 #include "OsiClpSolverInterface.hpp" 32 void gutsOfConstructor(
CbcModel &model);
52 const double threshold)
const;
62 std::vector< CbcHeuristicNode * > nodes_;
78 return static_cast< int >(nodes_.size());
87 void gutsOfDelete() {}
109 virtual void setModel(
CbcModel *model);
112 virtual void resetModel(
CbcModel *model) = 0;
119 virtual int solution(
double &objectiveValue,
157 numberNodes_ = value;
194 bool exitNow(
double bestObjective)
const;
198 feasibilityPumpOptions_ = value;
203 return feasibilityPumpOptions_;
214 fractionSmall_ = value;
219 return fractionSmall_;
224 return numberSolutionsFound_;
229 numberSolutionsFound_++;
241 int smallBranchAndBound(OsiSolverInterface *solver,
int numberNodes,
242 double *newSolution,
double &newSolutionValue,
243 double cutoff, std::string name)
const;
247 void generateCpp(FILE *fp,
const char *heuristic);
256 return heuristicName_.c_str();
261 heuristicName_ = name;
264 void setSeed(
int value);
270 decayFactor_ = value;
273 void setInputSolution(
const double *solution,
double objValue);
298 shallowDepth_ = value;
303 howOftenShallow_ = value;
310 minDistanceToRun_ = value;
321 virtual bool shouldHeurRun(
int whereFrom);
323 bool shouldHeurRun_randomChoice();
325 void printDistanceToNodes();
339 inline bool isHeuristicInteger(
const OsiSolverInterface *solver,
int iColumn)
const 341 const OsiClpSolverInterface *clpSolver
342 =
dynamic_cast< const OsiClpSolverInterface *
>(solver);
344 return clpSolver->isHeuristicInteger(iColumn);
346 return solver->isInteger(iColumn);
351 return solver->isInteger(iColumn);
362 OsiSolverInterface *cloneBut(
int type);
448 double *lowerBoundLastNode_;
451 double *upperBoundLastNode_;
477 virtual void generateCpp(FILE *fp);
480 virtual void resetModel(
CbcModel *model);
483 virtual void setModel(
CbcModel *model);
491 virtual int solution(
double &objectiveValue,
492 double *newSolution);
499 virtual int solution(
double &objectiveValue,
501 double solutionValue);
503 virtual void validate();
518 virtual bool shouldHeurRun(
int whereFrom);
570 virtual void generateCpp(FILE *fp);
573 virtual void resetModel(
CbcModel *model);
576 virtual void setModel(
CbcModel *model);
584 virtual int solution(
double &objectiveValue,
585 double *newSolution);
587 virtual void validate();
592 fixPriority_ = value;
596 virtual bool shouldHeurRun(
int whereFrom);
630 virtual void generateCpp(FILE *fp);
633 virtual void setModel(
CbcModel *model);
646 virtual int solution(
double &objectiveValue,
647 double *newSolution);
649 virtual void resetModel(
CbcModel *model);
678 virtual void generateCpp(FILE *fp);
686 virtual int solution(
double &objectiveValue,
687 double *newSolution);
689 virtual void resetModel(
CbcModel *model);
692 virtual void setModel(
CbcModel *model);
708 virtual void validate();
710 void addHeuristic(
const CbcHeuristic *heuristic,
double probability);
712 void normalizeProbabilities();
void incrementNumberSolutionsFound()
Increment how many solutions the heuristic thought it got.
double decayFactor_
How much to increase how often.
int howOftenShallow_
How often to invoke the heuristics in the shallow part of the tree.
int when_
When flag - 0 off, 1 at root, 2 other than root, 3 always.
int numberNodesDone_
How many nodes the heuristic did this go.
double fractionSmall_
Fraction of new(rows+columns)/old(rows+columns) before doing small branch and bound.
CoinThreadRandom randomNumberGenerator_
Thread specific random number generator.
void setFixPriority(int value)
Set priority level.
int lastRunDeep_
After how many deep invocations was the heuristic run last time.
void setFeasibilityPumpOptions(int value)
Sets feasibility pump options (-1 is off)
int switches_
Switches (does not apply equally to all heuristics) 1 bit - stop once allowable gap on objective reac...
double avgDistance(const CbcHeuristicNodeList &nodeList) const
virtual bool canDealWithOdd() const
Returns true if can deal with "odd" problems e.g. sos type 2.
int feasibilityPumpOptions() const
Gets feasibility pump options (-1 is off)
void setSeed(int value)
Set seed.
int numInvocationsInShallow_
How many invocations happened within the same node when in a shallow part of the tree.
void setShallowDepth(int value)
Upto this depth we call the tree shallow and the heuristic can be called multiple times...
bool isHeuristicInteger(const OsiSolverInterface *solver, int iColumn)
Is it integer for heuristics?
double minDistance(const CbcHeuristicNodeList &nodeList) const
int numInvocationsInDeep_
How many invocations happened when in the deep part of the tree.
int numberNodes_
Number of nodes in any sub tree.
int minDistanceToRun_
How "far" should this node be from every other where the heuristic was run in order to allow the heur...
void setFractionSmall(double value)
Sets fraction of new(rows+columns)/old(rows+columns) before doing small branch and bound (default 1...
void setDecayFactor(double value)
Sets decay factor (for howOften) on failure.
void setNumberNodes(int value)
Sets number of nodes in subtree (default 200)
int feasibilityPumpOptions_
Feasibility pump options , -1 is off >=0 for feasibility pump itself -2 quick proximity search -3 lon...
void setMinDistanceToRun(int value)
How "far" should this node be from every other where the heuristic was run in order to allow the heur...
void setModelOnly(CbcModel *model)
Just set model - do not do anything else.
void setWhen(int value)
Sets "when" flag - 0 off, 1 at root, 2 other than root, 3 always.
int numRuns_
how many times the heuristic has actually run
const CbcHeuristicNode * node(int i) const
void setHeuristicName(const char *name)
set name of heuristic
const char * heuristicName() const
return name of heuristic
int howOften_
How often to do (code can change)
CbcHeuristic ** heuristic_
Abstract branching object base class Now just difference with OsiBranchingObject. ...
Partial solution class If user knows a partial solution this tries to get an integer solution it uses...
bool minDistanceIsSmall(const CbcHeuristicNodeList &nodeList, const double threshold) const
CoinPackedMatrix matrixByRow_
int numCouldRun_
How many times the heuristic could run.
Just One class - this chooses one at random.
int switches() const
Switches (does not apply equally to all heuristics) 1 bit - stop once allowable gap on objective reac...
CbcHeuristicNodeList runNodes_
The description of the nodes where this heuristic has been applied.
void setWhereFrom(int value)
int shallowDepth_
Upto this depth we call the tree shallow and the heuristic can be called multiple times...
double distance(const CbcHeuristicNode *node) const
int numberSolutionsFound_
How many solutions the heuristic thought it got.
int numRuns() const
how many times the heuristic has actually run
virtual int solution(double &objectiveValue, double *newSolution)=0
returns 0 if no solution, 1 if valid solution with better objective value than one passed in Sets sol...
int when() const
Gets "when" flag - 0 off, 1 at root, 2 other than root, 3 always.
virtual void generateCpp(FILE *)
Create C++ lines to get to current state.
std::string heuristicName_
Name for printing.
double fractionSmall() const
Gets fraction of new(rows+columns)/old(rows+columns) before doing small branch and bound (default 1...
A class describing the branching decisions that were made to get to the node where a heuristic was in...
void setSwitches(int value)
Switches (does not apply equally to all heuristics) 1 bit - stop once allowable gap on objective reac...
int numberNodes() const
Gets number of nodes in a subtree (default 200)
int numCouldRun() const
How many times the heuristic could run.
virtual bool selectVariableToBranch(OsiSolverInterface *, const double *, int &, int &)
Selects the next variable to branch on.
virtual int solution2(double &, double *, OsiCuts &)
returns 0 if no solution, 1 if valid solution, -1 if just returning an estimate of best possible solu...
Simple Branch and bound class.
void setHowOftenShallow(int value)
How often to invoke the heuristics in the shallow part of the tree.
int numberSolutionsFound() const
Get how many solutions the heuristic thought it got.
heuristic - just picks up any good solution found by solver - see OsiBabSolver
virtual void validate()
Validate model i.e. sets when_ to 0 if necessary (may be NULL)