Ignore:
Timestamp:
Jan 29, 2010 9:25:07 AM (10 years ago)
Author:
forrest
Message:

moving sandbox stuff to trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Clp/src/ClpNode.hpp

    r1430 r1502  
    99// This implements all stuff for Clp fathom
    1010/** This contains what is in a Clp "node"
    11    
     11
    1212 */
    1313
     
    1616class ClpNodeStuff;
    1717class ClpNode {
    18  
     18
    1919public:
    20   /**@name Useful methods */
    21   //@{
    22   /** Applies node to model
    23       0 - just tree bounds
    24       1 - tree bounds and basis etc
    25       2 - saved bounds and basis etc
    26   */
    27   void applyNode(ClpSimplex * model, int doBoundsEtc );
    28   /// Choose a new variable
    29   void chooseVariable(ClpSimplex * model, ClpNodeStuff * info);
    30   /// Fix on reduced costs
    31   int fixOnReducedCosts(ClpSimplex * model);
    32   /// Create odd arrays
    33   void createArrays(ClpSimplex * model);
    34   /// Clean up as crunch is different model
    35   void cleanUpForCrunch();
    36   //@}
    37  
    38   /**@name Gets and sets */
    39   //@{
    40   /// Objective value
    41   inline double objectiveValue() const
    42   { return objectiveValue_;}
    43   /// Set objective value
    44   inline void setObjectiveValue(double value)
    45   { objectiveValue_=value;}
    46   /// Primal solution
    47   inline const double * primalSolution() const
    48   { return primalSolution_;}
    49   /// Dual solution
    50   inline const double * dualSolution() const
    51   { return dualSolution_;}
    52   /// Initial value of integer variable
    53   inline double branchingValue() const
    54   { return branchingValue_;}
    55   /// Sum infeasibilities
    56   inline double sumInfeasibilities() const
    57   { return sumInfeasibilities_;}
    58   /// Number infeasibilities
    59   inline int numberInfeasibilities() const
    60   { return numberInfeasibilities_;}
    61   /// Relative depth
    62   inline int depth() const
    63   { return depth_;}
    64   /// Estimated solution value
    65   inline double estimatedSolution() const
    66   { return estimatedSolution_;}
    67   /** Way for integer variable -1 down , +1 up */
    68   int way() const;
    69   /// Return true if branch exhausted
    70   bool fathomed() const;
    71   /// Change state of variable i.e. go other way
    72   void changeState();
    73   /// Sequence number of integer variable (-1 if none)
    74   inline int sequence() const
    75   { return sequence_;}
    76   /// If odd arrays exist
    77   inline bool oddArraysExist() const
    78   { return lower_!=NULL;}
    79   /// Status array
    80   inline const unsigned char * statusArray() const
    81   { return status_; }
    82   //@}
    83  
    84   /**@name Constructors, destructor */
    85   //@{
    86   /** Default constructor. */
    87   ClpNode();
    88   /// Constructor from model
    89   ClpNode (ClpSimplex * model, const ClpNodeStuff * stuff,int depth);
    90   /// Does work of constructor (partly so gdb will work)
    91   void gutsOfConstructor(ClpSimplex * model, const ClpNodeStuff * stuff,
    92                          int arraysExist,int depth);
    93   /** Destructor */
    94   virtual ~ClpNode();
    95   //@}
    96  
    97   /**@name Copy methods (at present illegal - will abort) */
    98   //@{
    99   /** The copy constructor. */
    100   ClpNode(const ClpNode&);
    101   /// Operator =
    102   ClpNode& operator=(const ClpNode&);
    103   //@}
    104  
     20    /**@name Useful methods */
     21    //@{
     22    /** Applies node to model
     23        0 - just tree bounds
     24        1 - tree bounds and basis etc
     25        2 - saved bounds and basis etc
     26    */
     27    void applyNode(ClpSimplex * model, int doBoundsEtc );
     28    /// Choose a new variable
     29    void chooseVariable(ClpSimplex * model, ClpNodeStuff * info);
     30    /// Fix on reduced costs
     31    int fixOnReducedCosts(ClpSimplex * model);
     32    /// Create odd arrays
     33    void createArrays(ClpSimplex * model);
     34    /// Clean up as crunch is different model
     35    void cleanUpForCrunch();
     36    //@}
     37
     38    /**@name Gets and sets */
     39    //@{
     40    /// Objective value
     41    inline double objectiveValue() const {
     42        return objectiveValue_;
     43    }
     44    /// Set objective value
     45    inline void setObjectiveValue(double value) {
     46        objectiveValue_ = value;
     47    }
     48    /// Primal solution
     49    inline const double * primalSolution() const {
     50        return primalSolution_;
     51    }
     52    /// Dual solution
     53    inline const double * dualSolution() const {
     54        return dualSolution_;
     55    }
     56    /// Initial value of integer variable
     57    inline double branchingValue() const {
     58        return branchingValue_;
     59    }
     60    /// Sum infeasibilities
     61    inline double sumInfeasibilities() const {
     62        return sumInfeasibilities_;
     63    }
     64    /// Number infeasibilities
     65    inline int numberInfeasibilities() const {
     66        return numberInfeasibilities_;
     67    }
     68    /// Relative depth
     69    inline int depth() const {
     70        return depth_;
     71    }
     72    /// Estimated solution value
     73    inline double estimatedSolution() const {
     74        return estimatedSolution_;
     75    }
     76    /** Way for integer variable -1 down , +1 up */
     77    int way() const;
     78    /// Return true if branch exhausted
     79    bool fathomed() const;
     80    /// Change state of variable i.e. go other way
     81    void changeState();
     82    /// Sequence number of integer variable (-1 if none)
     83    inline int sequence() const {
     84        return sequence_;
     85    }
     86    /// If odd arrays exist
     87    inline bool oddArraysExist() const {
     88        return lower_ != NULL;
     89    }
     90    /// Status array
     91    inline const unsigned char * statusArray() const {
     92        return status_;
     93    }
     94    //@}
     95
     96    /**@name Constructors, destructor */
     97    //@{
     98    /** Default constructor. */
     99    ClpNode();
     100    /// Constructor from model
     101    ClpNode (ClpSimplex * model, const ClpNodeStuff * stuff, int depth);
     102    /// Does work of constructor (partly so gdb will work)
     103    void gutsOfConstructor(ClpSimplex * model, const ClpNodeStuff * stuff,
     104                           int arraysExist, int depth);
     105    /** Destructor */
     106    virtual ~ClpNode();
     107    //@}
     108
     109    /**@name Copy methods (at present illegal - will abort) */
     110    //@{
     111    /** The copy constructor. */
     112    ClpNode(const ClpNode&);
     113    /// Operator =
     114    ClpNode& operator=(const ClpNode&);
     115    //@}
     116
    105117protected:
    106118// For state of branch
    107 typedef struct {
    108   unsigned int firstBranch:1; //  nonzero if first branch on variable is up
    109   unsigned int branch:2; //  0 means do first branch next, 1 second, 2 finished
    110   unsigned int spare:29;
    111 } branchState;
    112   /**@name Data */
    113   //@{
    114   /// Initial value of integer variable
    115   double branchingValue_;
    116   /// Value of objective
    117   double objectiveValue_;
    118   /// Sum of infeasibilities
    119   double sumInfeasibilities_;
    120   /// Estimated solution value
    121   double estimatedSolution_;
    122   /// Factorization
    123   ClpFactorization * factorization_;
    124   /// Steepest edge weights
    125   ClpDualRowSteepest * weights_;
    126   /// Status vector
    127   unsigned char * status_;
    128   /// Primal solution
    129   double * primalSolution_;
    130   /// Dual solution
    131   double * dualSolution_;
    132   /// Integer lower bounds (only used in fathomMany)
    133   int * lower_;
    134   /// Integer upper bounds (only used in fathomMany)
    135   int * upper_;
    136   /// Pivot variables for factorization
    137   int * pivotVariables_;
    138   /// Variables fixed by reduced costs (at end of branch) 0x10000000 added if fixed to UB
    139   int * fixed_;
    140   /// State of branch
    141   branchState branchState_;
    142   /// Sequence number of integer variable (-1 if none)
    143   int sequence_;
    144   /// Number of infeasibilities
    145   int numberInfeasibilities_;
    146   /// Relative depth
    147   int depth_;
    148   /// Number fixed by reduced cost
    149   int numberFixed_;
    150   /// Flags - 1 duals scaled
    151   int flags_;
    152   /// Maximum number fixed by reduced cost
    153   int maximumFixed_;
    154   /// Maximum rows so far
    155   int maximumRows_;
    156   /// Maximum columns so far
    157   int maximumColumns_;
    158   /// Maximum Integers so far
    159   int maximumIntegers_;
    160   //@}
     119    typedef struct {
     120        unsigned int firstBranch: 1; //  nonzero if first branch on variable is up
     121        unsigned int branch: 2; //  0 means do first branch next, 1 second, 2 finished
     122        unsigned int spare: 29;
     123    } branchState;
     124    /**@name Data */
     125    //@{
     126    /// Initial value of integer variable
     127    double branchingValue_;
     128    /// Value of objective
     129    double objectiveValue_;
     130    /// Sum of infeasibilities
     131    double sumInfeasibilities_;
     132    /// Estimated solution value
     133    double estimatedSolution_;
     134    /// Factorization
     135    ClpFactorization * factorization_;
     136    /// Steepest edge weights
     137    ClpDualRowSteepest * weights_;
     138    /// Status vector
     139    unsigned char * status_;
     140    /// Primal solution
     141    double * primalSolution_;
     142    /// Dual solution
     143    double * dualSolution_;
     144    /// Integer lower bounds (only used in fathomMany)
     145    int * lower_;
     146    /// Integer upper bounds (only used in fathomMany)
     147    int * upper_;
     148    /// Pivot variables for factorization
     149    int * pivotVariables_;
     150    /// Variables fixed by reduced costs (at end of branch) 0x10000000 added if fixed to UB
     151    int * fixed_;
     152    /// State of branch
     153    branchState branchState_;
     154    /// Sequence number of integer variable (-1 if none)
     155    int sequence_;
     156    /// Number of infeasibilities
     157    int numberInfeasibilities_;
     158    /// Relative depth
     159    int depth_;
     160    /// Number fixed by reduced cost
     161    int numberFixed_;
     162    /// Flags - 1 duals scaled
     163    int flags_;
     164    /// Maximum number fixed by reduced cost
     165    int maximumFixed_;
     166    /// Maximum rows so far
     167    int maximumRows_;
     168    /// Maximum columns so far
     169    int maximumColumns_;
     170    /// Maximum Integers so far
     171    int maximumIntegers_;
     172    //@}
    161173};
    162174class ClpNodeStuff {
    163  
     175
    164176public:
    165   /**@name Constructors, destructor */
    166   //@{
    167   /** Default constructor. */
    168   ClpNodeStuff();
    169   /** Destructor */
    170   virtual ~ClpNodeStuff();
    171   //@}
    172  
    173   /**@name Copy methods (only copies ints etc, nulls arrays) */
    174   //@{
    175   /** The copy constructor. */
    176   ClpNodeStuff(const ClpNodeStuff&);
    177   /// Operator =
    178   ClpNodeStuff& operator=(const ClpNodeStuff&);
    179   /// Zaps stuff 1 - arrays, 2 ints, 3 both
    180   void zap(int type);
    181   //@}
    182  
    183  
    184   /**@name Fill methods */
    185   //@{
    186   /** Fill with pseudocosts */
    187   void fillPseudoCosts(const double * down, const double * up,
    188                        const int * priority,
    189                        const int * numberDown, const int * numberUp,
    190                        const int * numberDownInfeasible, const int * numberUpInfeasible,
    191                        int number);
    192   /// Update pseudo costs
    193   void update(int way,int sequence,double change,bool feasible);
    194   /// Return maximum number of nodes
    195   int maximumNodes() const;
    196   /// Return maximum space for nodes
    197   int maximumSpace() const;
    198   //@}
    199  
     177    /**@name Constructors, destructor */
     178    //@{
     179    /** Default constructor. */
     180    ClpNodeStuff();
     181    /** Destructor */
     182    virtual ~ClpNodeStuff();
     183    //@}
     184
     185    /**@name Copy methods (only copies ints etc, nulls arrays) */
     186    //@{
     187    /** The copy constructor. */
     188    ClpNodeStuff(const ClpNodeStuff&);
     189    /// Operator =
     190    ClpNodeStuff& operator=(const ClpNodeStuff&);
     191    /// Zaps stuff 1 - arrays, 2 ints, 3 both
     192    void zap(int type);
     193    //@}
     194
     195
     196    /**@name Fill methods */
     197    //@{
     198    /** Fill with pseudocosts */
     199    void fillPseudoCosts(const double * down, const double * up,
     200                         const int * priority,
     201                         const int * numberDown, const int * numberUp,
     202                         const int * numberDownInfeasible, const int * numberUpInfeasible,
     203                         int number);
     204    /// Update pseudo costs
     205    void update(int way, int sequence, double change, bool feasible);
     206    /// Return maximum number of nodes
     207    int maximumNodes() const;
     208    /// Return maximum space for nodes
     209    int maximumSpace() const;
     210    //@}
     211
    200212public:
    201   /**@name Data */
    202   //@{
    203   /// Integer tolerance
    204   double integerTolerance_;
    205   /// Integer increment
    206   double integerIncrement_;
    207   /// Small chnage in branch
    208   double smallChange_;
    209   /// Down pseudo costs
    210   double * downPseudo_;
    211   /// Up pseudo costs
    212   double * upPseudo_;
    213   /// Priority
    214   int * priority_;
    215   /// Number of times down
    216   int * numberDown_;
    217   /// Number of times up
    218   int * numberUp_;
    219   /// Number of times down infeasible
    220   int * numberDownInfeasible_;
    221   /// Number of times up infeasible
    222   int * numberUpInfeasible_;
    223   /// Copy of costs (local)
    224   double * saveCosts_;
    225   /// Array of ClpNodes
    226   ClpNode ** nodeInfo_;
    227   /// Large model if crunched
    228   ClpSimplex * large_;
    229   /// Which rows in large model
    230   int * whichRow_;
    231   /// Which columns in large model
    232   int * whichColumn_;
    233   /// Number bounds in large model
    234   int nBound_;
    235   /// Save of specialOptions_ (local)
    236   int saveOptions_;
    237   /** Options to pass to solver
    238       1 - create external reduced costs for columns
    239       2 - create external reduced costs for rows
    240       4 - create external row activity (columns always done)
    241       Above only done if feasible
    242       32 - just create up to nDepth_+1 nodes
    243       65536 - set if activated
    244   */
    245   int solverOptions_;
    246   /// Maximum number of nodes to do
    247   int maximumNodes_;
    248   /// Number before trust from CbcModel
    249   int numberBeforeTrust_;
    250   /// State of search from CbcModel
    251   int stateOfSearch_;
    252   /// Number deep
    253   int nDepth_;
    254   /// Number nodes returned (-1 if fathom aborted)
    255   int nNodes_;
    256   /// Number of nodes explored
    257   int numberNodesExplored_;
    258   /// Number of iterations
    259   int numberIterations_;
    260   /// Type of presolve - 0 none, 1 crunch
    261   int presolveType_;
    262   //@}
     213    /**@name Data */
     214    //@{
     215    /// Integer tolerance
     216    double integerTolerance_;
     217    /// Integer increment
     218    double integerIncrement_;
     219    /// Small chnage in branch
     220    double smallChange_;
     221    /// Down pseudo costs
     222    double * downPseudo_;
     223    /// Up pseudo costs
     224    double * upPseudo_;
     225    /// Priority
     226    int * priority_;
     227    /// Number of times down
     228    int * numberDown_;
     229    /// Number of times up
     230    int * numberUp_;
     231    /// Number of times down infeasible
     232    int * numberDownInfeasible_;
     233    /// Number of times up infeasible
     234    int * numberUpInfeasible_;
     235    /// Copy of costs (local)
     236    double * saveCosts_;
     237    /// Array of ClpNodes
     238    ClpNode ** nodeInfo_;
     239    /// Large model if crunched
     240    ClpSimplex * large_;
     241    /// Which rows in large model
     242    int * whichRow_;
     243    /// Which columns in large model
     244    int * whichColumn_;
     245    /// Number bounds in large model
     246    int nBound_;
     247    /// Save of specialOptions_ (local)
     248    int saveOptions_;
     249    /** Options to pass to solver
     250        1 - create external reduced costs for columns
     251        2 - create external reduced costs for rows
     252        4 - create external row activity (columns always done)
     253        Above only done if feasible
     254        32 - just create up to nDepth_+1 nodes
     255        65536 - set if activated
     256    */
     257    int solverOptions_;
     258    /// Maximum number of nodes to do
     259    int maximumNodes_;
     260    /// Number before trust from CbcModel
     261    int numberBeforeTrust_;
     262    /// State of search from CbcModel
     263    int stateOfSearch_;
     264    /// Number deep
     265    int nDepth_;
     266    /// Number nodes returned (-1 if fathom aborted)
     267    int nNodes_;
     268    /// Number of nodes explored
     269    int numberNodesExplored_;
     270    /// Number of iterations
     271    int numberIterations_;
     272    /// Type of presolve - 0 none, 1 crunch
     273    int presolveType_;
     274    //@}
    263275};
    264276class ClpHashValue {
    265  
     277
    266278public:
    267   /**@name Useful methods */
    268   //@{
    269   /// Return index or -1 if not found
    270   int index(double value) const;
    271   /// Add value to list and return index
    272   int addValue(double value) ;
    273   /// Number of different entries
    274   inline int numberEntries() const
    275   { return numberHash_;}
    276   //@}
    277 
    278   /**@name Constructors, destructor */
    279   //@{
    280   /** Default constructor. */
    281   ClpHashValue();
    282   /** Useful constructor. */
    283   ClpHashValue(ClpSimplex * model);
    284   /** Destructor */
    285   virtual ~ClpHashValue();
    286   //@}
    287  
    288   /**@name Copy method */
    289   //@{
    290   /** The copy constructor. */
    291   ClpHashValue(const ClpHashValue&);
    292   /// =
    293   ClpHashValue& operator=(const ClpHashValue&);
    294   //@}
     279    /**@name Useful methods */
     280    //@{
     281    /// Return index or -1 if not found
     282    int index(double value) const;
     283    /// Add value to list and return index
     284    int addValue(double value) ;
     285    /// Number of different entries
     286    inline int numberEntries() const {
     287        return numberHash_;
     288    }
     289    //@}
     290
     291    /**@name Constructors, destructor */
     292    //@{
     293    /** Default constructor. */
     294    ClpHashValue();
     295    /** Useful constructor. */
     296    ClpHashValue(ClpSimplex * model);
     297    /** Destructor */
     298    virtual ~ClpHashValue();
     299    //@}
     300
     301    /**@name Copy method */
     302    //@{
     303    /** The copy constructor. */
     304    ClpHashValue(const ClpHashValue&);
     305    /// =
     306    ClpHashValue& operator=(const ClpHashValue&);
     307    //@}
    295308private:
    296   /**@name private stuff */
    297   //@{
    298   /** returns hash */
    299   int hash(double value) const;
    300   /// Resizes
    301   void resize(bool increaseMax);
    302   //@}
    303    
     309    /**@name private stuff */
     310    //@{
     311    /** returns hash */
     312    int hash(double value) const;
     313    /// Resizes
     314    void resize(bool increaseMax);
     315    //@}
     316
    304317protected:
    305   /**@name Data members
    306      The data members are protected to allow access for derived classes. */
    307   //@{
    308   /// Data
    309   // for hashing
    310   typedef struct {
    311     double value;
    312     int index, next;
    313   } CoinHashLink;
    314   /// Hash table
    315   mutable CoinHashLink *hash_;
    316   /// Number of entries in hash table
    317   int numberHash_;
    318   /// Maximum number of entries in hash table i.e. size
    319   int maxHash_;
    320   /// Last used space
    321   int lastUsed_;
    322   //@}
     318    /**@name Data members
     319       The data members are protected to allow access for derived classes. */
     320    //@{
     321    /// Data
     322    // for hashing
     323    typedef struct {
     324        double value;
     325        int index, next;
     326    } CoinHashLink;
     327    /// Hash table
     328    mutable CoinHashLink *hash_;
     329    /// Number of entries in hash table
     330    int numberHash_;
     331    /// Maximum number of entries in hash table i.e. size
     332    int maxHash_;
     333    /// Last used space
     334    int lastUsed_;
     335    //@}
    323336};
    324337#endif
Note: See TracChangeset for help on using the changeset viewer.