source: trunk/Cbc/src/CbcFathomDynamicProgramming.hpp @ 862

Last change on this file since 862 was 765, checked in by andreasw, 12 years ago

merging changes from Bug Squashing Party Aug 2007 to regular trunk

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