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

Last change on this file since 2464 was 2464, checked in by unxusr, 11 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: 8.0 KB
Line 
1// $Id: CbcGeneralDepth.hpp 2464 2019-01-03 19:03:23Z unxusr $
2// Copyright (C) 2002, 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// Edwin 11/10/2009-- carved out of CbcBranchActual
7
8#ifndef CbcGeneralDepth_H
9#define CbcGeneralDepth_H
10
11#include "CbcGeneral.hpp"
12#include "CbcBranchBase.hpp"
13#include "CbcSubProblem.hpp"
14
15#ifdef COIN_HAS_CLP
16
17/** Define a catch all class.
18    This will create a list of subproblems using partial evaluation
19*/
20#include "ClpSimplex.hpp"
21#include "ClpNode.hpp"
22
23class CbcGeneralDepth : public CbcGeneral {
24
25public:
26  // Default Constructor
27  CbcGeneralDepth();
28
29  /** Useful constructor
30        Just needs to point to model.
31        Initial version does evaluation to depth N
32        This is stored in CbcModel but may be
33        better here
34    */
35  CbcGeneralDepth(CbcModel *model, int maximumDepth);
36
37  // Copy constructor
38  CbcGeneralDepth(const CbcGeneralDepth &);
39
40  /// Clone
41  virtual CbcObject *clone() const;
42
43  // Assignment operator
44  CbcGeneralDepth &operator=(const CbcGeneralDepth &rhs);
45
46  // Destructor
47  ~CbcGeneralDepth();
48
49  /// Infeasibility - large is 0.5
50  virtual double infeasibility(const OsiBranchingInformation *info,
51    int &preferredWay) const;
52
53  using CbcObject::feasibleRegion;
54  /// This looks at solution and sets bounds to contain solution
55  virtual void feasibleRegion();
56
57  /// Creates a branching object
58  virtual CbcBranchingObject *createCbcBranch(OsiSolverInterface *solver, const OsiBranchingInformation *info, int way);
59  /// Return maximum number of nodes
60  inline int maximumNodes() const
61  {
62    return maximumNodes_;
63  }
64  /// Get maximum depth
65  inline int maximumDepth() const
66  {
67    return maximumDepth_;
68  }
69  /// Set maximum depth
70  inline void setMaximumDepth(int value)
71  {
72    maximumDepth_ = value;
73  }
74  /// Return number of nodes
75  inline int numberNodes() const
76  {
77    return numberNodes_;
78  }
79  /// Get which solution
80  inline int whichSolution() const
81  {
82    return whichSolution_;
83  }
84  /// Get ClpNode info
85  inline ClpNode *nodeInfo(int which)
86  {
87    return nodeInfo_->nodeInfo_[which];
88  }
89
90  /// Redoes data when sequence numbers change
91  virtual void redoSequenceEtc(CbcModel *model, int numberColumns, const int *originalColumns);
92
93protected:
94  /// data
95  /// Maximum depth
96  int maximumDepth_;
97  /// Maximum nodes
98  int maximumNodes_;
99  /// Which node has solution (or -1)
100  mutable int whichSolution_;
101  /// Number of valid nodes (including whichSolution_)
102  mutable int numberNodes_;
103  /// For solving nodes
104  mutable ClpNodeStuff *nodeInfo_;
105};
106/** Branching object for general objects
107
108 */
109class CbcNode;
110class CbcGeneralBranchingObject : public CbcBranchingObject {
111
112public:
113  // Default Constructor
114  CbcGeneralBranchingObject();
115
116  // Useful constructor
117  CbcGeneralBranchingObject(CbcModel *model);
118
119  // Copy constructor
120  CbcGeneralBranchingObject(const CbcGeneralBranchingObject &);
121
122  // Assignment operator
123  CbcGeneralBranchingObject &operator=(const CbcGeneralBranchingObject &rhs);
124
125  /// Clone
126  virtual CbcBranchingObject *clone() const;
127
128  // Destructor
129  virtual ~CbcGeneralBranchingObject();
130
131  using CbcBranchingObject::branch;
132  /// Does next branch and updates state
133  virtual double branch();
134  /** Double checks in case node can change its mind!
135        Can change objective etc */
136  virtual void checkIsCutoff(double cutoff);
137
138  using CbcBranchingObject::print;
139  /** \brief Print something about branch - only if log level high
140    */
141  virtual void print();
142  /// Fill in current objective etc
143  void state(double &objectiveValue, double &sumInfeasibilities,
144    int &numberUnsatisfied, int which) const;
145  /// Set CbcNode
146  inline void setNode(CbcNode *node)
147  {
148    node_ = node;
149  }
150  /** Return the type (an integer identifier) of \c this */
151  virtual CbcBranchObjType type() const
152  {
153    return GeneralDepthBranchObj;
154  }
155
156  /** Compare the original object of \c this with the original object of \c
157        brObj. Assumes that there is an ordering of the original objects.
158        This method should be invoked only if \c this and brObj are of the same
159        type.
160        Return negative/0/positive depending on whether \c this is
161        smaller/same/larger than the argument.
162    */
163  virtual int compareOriginalObject(const CbcBranchingObject *brObj) const;
164
165  /** Compare the \c this with \c brObj. \c this and \c brObj must be os the
166        same type and must have the same original object, but they may have
167        different feasible regions.
168        Return the appropriate CbcRangeCompare value (first argument being the
169        sub/superset if that's the case). In case of overlap (and if \c
170        replaceIfOverlap is true) replace the current branching object with one
171        whose feasible region is the overlap.
172     */
173  virtual CbcRangeCompare compareBranchingObject(const CbcBranchingObject *brObj, const bool replaceIfOverlap = false);
174  /// Number of subproblems
175  inline int numberSubProblems() const
176  {
177    return numberSubProblems_;
178  }
179  /// Decrement number left and return number
180  inline int decrementNumberLeft()
181  {
182    numberSubLeft_--;
183    return numberSubLeft_;
184  }
185  /// Which node we want to use
186  inline int whichNode() const
187  {
188    return whichNode_;
189  }
190  /// Set which node we want to use
191  inline void setWhichNode(int value)
192  {
193    whichNode_ = value;
194  }
195  // Sub problem
196  const CbcSubProblem *subProblem(int which) const
197  {
198    return subProblems_ + which;
199  }
200
201public:
202  /// data
203  // Sub problems
204  CbcSubProblem *subProblems_;
205  /// Node
206  CbcNode *node_;
207  /// Number of subproblems
208  int numberSubProblems_;
209  /// Number of subproblems left
210  int numberSubLeft_;
211  /// Which node we want to use (-1 for default)
212  int whichNode_;
213  /// Number of rows
214  int numberRows_;
215};
216/** Branching object for general objects - just one
217
218 */
219class CbcOneGeneralBranchingObject : public CbcBranchingObject {
220
221public:
222  // Default Constructor
223  CbcOneGeneralBranchingObject();
224
225  // Useful constructor
226  CbcOneGeneralBranchingObject(CbcModel *model,
227    CbcGeneralBranchingObject *object,
228    int whichOne);
229
230  // Copy constructor
231  CbcOneGeneralBranchingObject(const CbcOneGeneralBranchingObject &);
232
233  // Assignment operator
234  CbcOneGeneralBranchingObject &operator=(const CbcOneGeneralBranchingObject &rhs);
235
236  /// Clone
237  virtual CbcBranchingObject *clone() const;
238
239  // Destructor
240  virtual ~CbcOneGeneralBranchingObject();
241
242  using CbcBranchingObject::branch;
243  /// Does next branch and updates state
244  virtual double branch();
245  /** Double checks in case node can change its mind!
246        Can change objective etc */
247  virtual void checkIsCutoff(double cutoff);
248
249  using CbcBranchingObject::print;
250  /** \brief Print something about branch - only if log level high
251    */
252  virtual void print();
253  /** Return the type (an integer identifier) of \c this */
254  virtual CbcBranchObjType type() const
255  {
256    return OneGeneralBranchingObj;
257  }
258
259  /** Compare the original object of \c this with the original object of \c
260        brObj. Assumes that there is an ordering of the original objects.
261        This method should be invoked only if \c this and brObj are of the same
262        type.
263        Return negative/0/positive depending on whether \c this is
264        smaller/same/larger than the argument.
265    */
266  virtual int compareOriginalObject(const CbcBranchingObject *brObj) const;
267
268  /** Compare the \c this with \c brObj. \c this and \c brObj must be os the
269        same type and must have the same original object, but they may have
270        different feasible regions.
271        Return the appropriate CbcRangeCompare value (first argument being the
272        sub/superset if that's the case). In case of overlap (and if \c
273        replaceIfOverlap is true) replace the current branching object with one
274        whose feasible region is the overlap.
275     */
276  virtual CbcRangeCompare compareBranchingObject(const CbcBranchingObject *brObj, const bool replaceIfOverlap = false);
277
278public:
279  /// data
280  /// Object
281  CbcGeneralBranchingObject *object_;
282  /// Which one
283  int whichOne_;
284};
285#endif //COIN_HAS_CLP
286#endif
Note: See TracBrowser for help on using the repository browser.