source: trunk/Clp/src/ClpPresolve.hpp @ 1525

Last change on this file since 1525 was 1525, checked in by mjs, 10 years ago

Formatted .cpp, .hpp, .c, .h files with "astyle -A4 -p". This matches the formatting used in the grand CBC reorganization.

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