source: trunk/Clp/src/ClpNode.hpp @ 1286

Last change on this file since 1286 was 1286, checked in by forrest, 11 years ago

changes for factorization and aux region

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