Ignore:
Timestamp:
Apr 10, 2008 1:55:10 PM (13 years ago)
Author:
ladanyi
Message:

Incorporated changes from branches/heur

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cbc/src/CbcHeuristic.hpp

    r854 r912  
    99#include "OsiCuts.hpp"
    1010#include "CoinHelperFunctions.hpp"
     11#include "OsiBranchingObject.hpp"
    1112
    1213class OsiSolverInterface;
    1314
    1415class CbcModel;
     16
     17//#############################################################################
     18
     19class CbcHeuristicNodeList;
     20class CbcBranchingObject;
     21
     22/** A class describing the branching decisions that were made to get
     23    to the node where a heuristics was invoked from */
     24
     25class CbcHeuristicNode {
     26private:
     27  void gutsOfConstructor(CbcModel& model);
     28  CbcHeuristicNode();
     29  CbcHeuristicNode& operator=(const CbcHeuristicNode&);
     30private:
     31  /// The number of branching decisions made
     32  int numObjects_;
     33  /** The indices of the branching objects. Note: an index may be
     34      listed multiple times. E.g., a general integer variable that has
     35      been branched on multiple times. */
     36  CbcBranchingObject** brObj_;
     37public:
     38  CbcHeuristicNode(CbcModel& model);
     39
     40  CbcHeuristicNode(const CbcHeuristicNode& rhs);
     41  ~CbcHeuristicNode();
     42  double distance(const CbcHeuristicNode* node) const;
     43  double minDistance(const CbcHeuristicNodeList& nodeList);
     44  double avgDistance(const CbcHeuristicNodeList& nodeList);
     45};
     46
     47class CbcHeuristicNodeList {
     48private:
     49  void gutsOfDelete();
     50  void gutsOfCopy(const CbcHeuristicNodeList& rhs);
     51private:
     52  std::vector<CbcHeuristicNode*> nodes_;
     53public:
     54  CbcHeuristicNodeList() {}
     55  CbcHeuristicNodeList(const CbcHeuristicNodeList& rhs);
     56  CbcHeuristicNodeList& operator=(const CbcHeuristicNodeList& rhs);
     57  ~CbcHeuristicNodeList();
     58 
     59  void append(CbcHeuristicNode*& node);
     60  void append(const CbcHeuristicNodeList& nodes);
     61  inline const CbcHeuristicNode* node(int i) const { return nodes_[i]; }
     62  inline int size() const { return nodes_.size(); }
     63};
    1564
    1665//#############################################################################
     
    1867
    1968class CbcHeuristic {
     69private:
     70  void gutsOfDelete() {}
     71  void gutsOfCopy(const CbcHeuristic & rhs);
     72
    2073public:
    2174  // Default Constructor
     
    124177  void setSeed(int value);
    125178
     179  /** Check whether the heuristic should run */
     180  bool shouldHeurRun();
     181  bool shouldHeurRun_randomChoice();
     182  void debugNodes();
     183  void printDistanceToNodes();
     184
    126185protected:
    127186
     
    140199  /// Name for printing
    141200  std::string heuristicName_;
    142  
     201
     202  /// How often to do (code can change)
     203  int howOften_;
     204  /// How much to increase how often
     205  double decayFactor_;
     206  /** Upto this depth we call the tree shallow and the heuristic can be called
     207      multiple times. That is, the test whether the current node is far from
     208      the others where the jeuristic was invoked will not be done, only the
     209      frequency will be tested. After that depth the heuristic will can be
     210      invoked only once per node, right before branching. That's when it'll be
     211      tested whether the heur should run at all. */
     212  int shallowDepth_;
     213  /** How often to invoke the heuristics in the shallow part of the tree */
     214  int howOftenShallow_;
     215  /** How many invocations happened within the same node when in a shallow
     216      part of the tree. */
     217  int numInvocationsInShallow_;
     218  /** How many invocations happened when in the deep part of the tree. For
     219      every node we count only one invocation. */
     220  int numInvocationsInDeep_;
     221  /** After how many deep invocations was the heuristic run last time */
     222  int lastRunDeep_;
     223  /// how many times the heuristic has actually run
     224  int numRuns_;
     225  /** How "far" should this node be from every other where the heuristic was
     226      run in order to allow the heuristic to run in this node, too. Currently
     227      this is tested, but we may switch to avgDistanceToRun_ in the future. */
     228  int minDistanceToRun_;
     229
     230  /// The description of the nodes where this heuristic has been applied
     231  CbcHeuristicNodeList runNodes_;
     232
     233  /// How many times the heuristic could run
     234  int numCouldRun_;
     235
     236
     237#if 0
     238  /// Lower bounds of last node where the heuristic found a solution
     239  double * lowerBoundLastNode_;
     240  /// Upper bounds of last node where the heuristic found a solution
     241  double * upperBoundLastNode_;
     242#endif
    143243};
    144244/** Rounding class
Note: See TracChangeset for help on using the changeset viewer.