source: trunk/include/ClpPresolve.hpp @ 461

Last change on this file since 461 was 461, checked in by forrest, 16 years ago

Trying to make faster

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.6 KB
Line 
1// Copyright (C) 2002, International Business Machines
2// Corporation and others.  All Rights Reserved.
3
4#ifndef ClpPresolve_H
5#define ClpPresolve_H
6#include "ClpSimplex.hpp"
7
8class CoinPresolveAction;
9#include "CoinPresolveMatrix.hpp"
10/** This is the Clp interface to CoinPresolve
11
12*/
13class ClpPresolve {
14public:
15  /**@name Main Constructor, destructor */
16   //@{
17  /// Default constructor
18  ClpPresolve();
19
20  /// Virtual destructor
21  virtual ~ClpPresolve();
22  //@}
23  /**@name presolve - presolves a model, transforming the model
24   * and saving information in the ClpPresolve object needed for postsolving.
25   * This underlying (protected) method is virtual; the idea is that in the future,
26   * one could override this method to customize how the various
27   * presolve techniques are applied.
28
29   This version of presolve returns a pointer to a new presolved
30      model.  NULL if infeasible or unbounded. 
31      This should be paired with postsolve
32      below.  The advantage of going back to original model is that it
33      will be exactly as it was i.e. 0.0 will not become 1.0e-19.
34      If keepIntegers is true then bounds may be tightened in
35      original.  Bounds will be moved by up to feasibilityTolerance
36      to try and stay feasible.
37      Names will be dropped in presolved model if asked
38  */
39  ClpSimplex * presolvedModel(ClpSimplex & si,
40                                      double feasibilityTolerance=0.0,
41                                      bool keepIntegers=true,
42                                      int numberPasses=5,
43                                      bool dropNames=false);
44  /** This version saves data in a file.  The passed in model
45      is updated to be presolved model.  names are always dropped.
46      Returns non-zero if infeasible*/
47  int presolvedModelToFile(ClpSimplex &si,std::string fileName,
48                              double feasibilityTolerance=0.0,
49                              bool keepIntegers=true,
50                              int numberPasses=5);
51  /** Return pointer to presolved model,
52      Up to user to destroy */
53  ClpSimplex * model() const;
54  /// Return pointer to original model
55  ClpSimplex * originalModel() const;
56  /// Set pointer to original model
57  void setOriginalModel(ClpSimplex * model);
58   
59  /// return pointer to original columns
60  const int * originalColumns() const;
61  /// return pointer to original rows
62  const int * originalRows() const;
63  /** "Magic" number. If this is non-zero then any elements with this value
64      may change and so presolve is very limited in what can be done
65      to the row and column.  This is for non-linear problems.
66  */
67  inline void setNonLinearValue(double value)
68  { nonLinearValue_ = value;};
69  inline double nonLinearValue() const
70    { return nonLinearValue_;};
71  /// Whether we want to do dual part of presolve
72  inline bool doDual() const
73  { return (presolveActions_&1)==0;};
74  inline void setDoDual(bool doDual)
75  { if (doDual) presolveActions_  &= ~1; else presolveActions_ |= 1;};
76  /// Whether we want to do singleton part of presolve
77  inline bool doSingleton() const
78  { return (presolveActions_&2)==0;};
79  inline void setDoSingleton(bool doSingleton)
80  { if (doSingleton) presolveActions_  &= ~2; else presolveActions_ |= 2;};
81  /// Whether we want to do doubleton part of presolve
82  inline bool doDoubleton() const
83  { return (presolveActions_&4)==0;};
84  inline void setDoDoubleton(bool doDoubleton)
85  { if (doDoubleton) presolveActions_  &= ~4; else presolveActions_ |= 4;};
86  /// Whether we want to do tripleton part of presolve
87  inline bool doTripleton() const
88  { return (presolveActions_&8)==0;};
89  inline void setDoTripleton(bool doTripleton)
90  { if (doTripleton) presolveActions_  &= ~8; else presolveActions_ |= 8;};
91  /// Whether we want to do tighten part of presolve
92  inline bool doTighten() const
93  { return (presolveActions_&16)==0;};
94  inline void setDoTighten(bool doTighten)
95  { if (doTighten) presolveActions_  &= ~16; else presolveActions_ |= 16;};
96  /// Whether we want to do forcing part of presolve
97  inline bool doForcing() const
98  { return (presolveActions_&32)==0;};
99  inline void setDoForcing(bool doForcing)
100  { if (doForcing) presolveActions_  &= ~32; else presolveActions_ |= 32;};
101  /// Whether we want to do impliedfree part of presolve
102  inline bool doImpliedFree() const
103  { return (presolveActions_&64)==0;};
104  inline void setDoImpliedFree(bool doImpliedfree)
105  { if (doImpliedfree) presolveActions_  &= ~64; else presolveActions_ |= 64;};
106  /// Whether we want to do dupcol part of presolve
107  inline bool doDupcol() const
108  { return (presolveActions_&128)==0;};
109  inline void setDoDupcol(bool doDupcol)
110  { if (doDupcol) presolveActions_  &= ~128; else presolveActions_ |= 128;};
111  /// Whether we want to do duprow part of presolve
112  inline bool doDuprow() const
113  { return (presolveActions_&256)==0;};
114  inline void setDoDuprow(bool doDuprow)
115  { if (doDuprow) presolveActions_  &= ~256; else presolveActions_ |= 256;};
116  /// Set whole group
117  inline bool presolveActions() const
118  { return presolveActions_&0xffff;};
119  inline void setPresolveActions(int action)
120  { presolveActions_  = (presolveActions_&0xffff0000)|(action&0xffff);};
121  /// Asks for statistics
122  inline void statistics()
123  { presolveActions_ |= 0x80000000;};
124
125  /**@name postsolve - postsolve the problem.  If the problem
126    has not been solved to optimality, there are no guarantees.
127   If you are using an algorithm like simplex that has a concept
128   of "basic" rows/cols, then set updateStatus
129 
130   Note that if you modified the original problem after presolving,
131   then you must ``undo'' these modifications before calling postsolve.
132  This version updates original*/
133  virtual void postsolve(bool updateStatus=true);
134
135  /// Gets rid of presolve actions (e.g.when infeasible)
136  void destroyPresolve();
137
138  /**@name private or protected data */
139private:
140  /// Original model - must not be destroyed before postsolve
141  ClpSimplex * originalModel_;
142
143  /// ClpPresolved model - up to user to destroy by deleteClpPresolvedModel
144  ClpSimplex * presolvedModel_;
145  /** "Magic" number. If this is non-zero then any elements with this value
146      may change and so presolve is very limited in what can be done
147      to the row and column.  This is for non-linear problems.
148      One could also allow for cases where sign of coefficient is known.
149  */
150  double nonLinearValue_;
151  /// Original column numbers
152  int * originalColumn_;
153  /// Original row numbers
154  int * originalRow_;
155  /// The list of transformations applied.
156  const CoinPresolveAction *paction_;
157
158  /// The postsolved problem will expand back to its former size
159  /// as postsolve transformations are applied.
160  /// It is efficient to allocate data structures for the final size
161  /// of the problem rather than expand them as needed.
162  /// These fields give the size of the original problem.
163  int ncols_;
164  int nrows_;
165  CoinBigIndex nelems_;
166  /// Number of major passes
167  int numberPasses_;
168  /// Name of saved model file
169  std::string saveFile_;
170  /// Whether we want to skip dual part of presolve etc
171  int presolveActions_;
172protected:
173  /// If you want to apply the individual presolve routines differently,
174  /// or perhaps add your own to the mix,
175  /// define a derived class and override this method
176  virtual const CoinPresolveAction *presolve(CoinPresolveMatrix *prob);
177
178  /// Postsolving is pretty generic; just apply the transformations
179  /// in reverse order.
180  /// You will probably only be interested in overriding this method
181  /// if you want to add code to test for consistency
182  /// while debugging new presolve techniques.
183  virtual void postsolve(CoinPostsolveMatrix &prob);
184  /** This is main part of Presolve */
185  virtual ClpSimplex * gutsOfPresolvedModel(ClpSimplex * originalModel
186                                            ,double feasibilityTolerance,
187                                            bool keepIntegers,
188                                            int numberPasses,
189                                            bool dropNames);
190};
191#endif
Note: See TracBrowser for help on using the repository browser.