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

Last change on this file since 2464 was 2464, checked in by unxusr, 10 months ago

.clang-format with proposal for formatting code

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