source: stable/2.4/Cbc/src/CbcFathomDynamicProgramming.hpp @ 1271

Last change on this file since 1271 was 1271, checked in by forrest, 10 years ago

Creating new stable branch 2.4 from trunk (rev 1270)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1/* $Id: CbcFathomDynamicProgramming.hpp 1271 2009-11-05 15:57:25Z forrest $ */
2// Copyright (C) 2004, International Business Machines
3// Corporation and others.  All Rights Reserved.
4#ifndef CbcFathomDynamicProgramming_H
5#define CbcFathomDynamicProgramming_H
6
7#include "CbcFathom.hpp"
8
9//#############################################################################
10/** FathomDynamicProgramming class.
11
12    The idea is that after some branching the problem will be effectively smaller than
13    the original problem and maybe there will be a more specialized technique which can completely
14    fathom this branch quickly.
15
16    This is a dynamic programming implementation which is very fast for some
17    specialized problems.  It expects small integral rhs, an all integer problem
18    and positive integral coefficients. At present it can not do general set covering
19    problems just set partitioning.  It can find multiple optima for various rhs
20    combinations.
21   
22    The main limiting factor is size of state space.  Each 1 rhs doubles the size of the problem.
23    2 or 3 rhs quadruples, 4,5,6,7 by 8 etc.
24 */
25
26class CbcFathomDynamicProgramming : public CbcFathom {
27public:
28  // Default Constructor
29  CbcFathomDynamicProgramming ();
30
31  // Constructor with model - assumed before cuts
32  CbcFathomDynamicProgramming (CbcModel & model);
33  // Copy constructor
34  CbcFathomDynamicProgramming(const CbcFathomDynamicProgramming & rhs);
35
36  virtual ~CbcFathomDynamicProgramming();
37
38  /// update model (This is needed if cliques update matrix etc)
39  virtual void setModel(CbcModel * model);
40 
41  /// Clone
42  virtual CbcFathom * clone() const;
43
44  /// Resets stuff if model changes
45  virtual void resetModel(CbcModel * model);
46
47  /** returns 0 if no fathoming attempted, 1 fully fathomed ,
48      2 incomplete search, 3 incomplete search but treat as complete.
49      If solution then newSolution will not be NULL and
50      will be freed by CbcModel.  It is expected that the solution is better
51      than best so far but CbcModel will double check.
52
53      If returns 3 then of course there is no guarantee of global optimum
54  */
55  virtual int fathom(double *& newSolution);
56
57  /// Maximum size allowed
58  inline int maximumSize() const
59  { return maximumSizeAllowed_;}
60  inline void setMaximumSize(int value)
61  { maximumSizeAllowed_=value;}
62  /// Returns type of algorithm and sets up arrays
63  int checkPossible(int allowableSize=0);
64  // set algorithm
65  inline void setAlgorithm(int value)
66  { algorithm_=value;}
67  /** Tries a column
68      returns true if was used in making any changes.
69  */
70  bool tryColumn(int numberElements, const int * rows,
71                    const double * coefficients, double cost,
72                    int upper=COIN_INT_MAX);
73  /// Returns cost array
74  inline const double * cost() const
75  { return cost_;}
76  /// Returns back array
77  inline const int * back() const
78  { return back_;}
79  /// Gets bit pattern for target result
80  inline int target() const
81  { return target_;}
82  /// Sets bit pattern for target result
83  inline void setTarget(int value)
84  { target_=value;}
85private:
86  /// Does deleteions
87  void gutsOfDelete();
88
89  /** Adds one attempt of one column of type 0,
90      returns true if was used in making any changes
91  */
92  bool addOneColumn0(int numberElements, const int * rows,
93                     double cost);
94  /** Adds one attempt of one column of type 1,
95      returns true if was used in making any changes.
96      At present the user has to call it once for each possible value
97  */
98  bool addOneColumn1(int numberElements, const int * rows,
99                     const int * coefficients, double cost);
100  /** Adds one attempt of one column of type 1,
101      returns true if was used in making any changes.
102      At present the user has to call it once for each possible value.
103      This version is when there are enough 1 rhs to do faster
104  */
105  bool addOneColumn1A(int numberElements, const int * rows,
106                     const int * coefficients, double cost);
107  /// Gets bit pattern from original column
108  int bitPattern(int numberElements, const int * rows,
109                     const int * coefficients);
110  /// Gets bit pattern from original column
111  int bitPattern(int numberElements, const int * rows,
112                     const double * coefficients);
113  /// Fills in original column (dense) from bit pattern - returning number nonzero
114  int decodeBitPattern(int bitPattern, int * values, int numberRows);
115
116protected:
117
118  /// Size of states (power of 2 unless just one constraint)
119  int size_;
120  /** Type - 0 coefficients and rhs all 1,
121      1 - coefficients > 1 or rhs > 1
122  */
123  int type_;
124  /// Space for states
125  double * cost_;
126  /// Which state produced this cheapest one
127  int * back_;
128  /// Some rows may be satisified so we need a lookup
129  int * lookup_;
130  /// Space for sorted indices
131  int * indices_;
132  /// Number of active rows
133  int numberActive_;
134  /// Maximum size allowed
135  int maximumSizeAllowed_;
136  /// Start bit for each active row
137  int * startBit_;
138  /// Number bits for each active row
139  int * numberBits_;
140  /// Effective rhs
141  int * rhs_;
142  /// Space for sorted coefficients
143  int * coefficients_;
144  /// Target pattern
145  int target_;
146  /// Number of Non 1 rhs
147  int numberNonOne_;
148  /// Current bit pattern
149  int bitPattern_;
150  /// Current algorithm
151  int algorithm_;
152private:
153 
154  /// Illegal Assignment operator
155  CbcFathomDynamicProgramming & operator=(const CbcFathomDynamicProgramming& rhs);
156 
157};
158
159#endif
Note: See TracBrowser for help on using the repository browser.