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

Last change on this file since 2030 was 1972, checked in by forrest, 6 years ago

changes to allow more options and stop on feasible (and a few other things)

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