source: stable/1.15/Clp/src/ClpPresolve.hpp @ 2018

Last change on this file since 2018 was 1928, checked in by stefan, 7 years ago

revert r1925 (so we can merge r1926) and sync with rev 1927

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 10.3 KB
Line 
1/* $Id: ClpPresolve.hpp 1928 2013-04-06 12:54:16Z stefan $ */
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     /// Set whole group
179     inline int presolveActions() const {
180          return presolveActions_ & 0xffff;
181     }
182     inline void setPresolveActions(int action) {
183          presolveActions_  = (presolveActions_ & 0xffff0000) | (action & 0xffff);
184     }
185     /// Substitution level
186     inline void setSubstitution(int value) {
187          substitution_ = value;
188     }
189     /// Asks for statistics
190     inline void statistics() {
191          presolveActions_ |= 0x80000000;
192     }
193     /// Return presolve status (0,1,2)
194     int presolveStatus() const;
195
196     /**@name postsolve - postsolve the problem.  If the problem
197       has not been solved to optimality, there are no guarantees.
198      If you are using an algorithm like simplex that has a concept
199      of "basic" rows/cols, then set updateStatus
200
201      Note that if you modified the original problem after presolving,
202      then you must ``undo'' these modifications before calling postsolve.
203     This version updates original*/
204     virtual void postsolve(bool updateStatus = true);
205
206     /// Gets rid of presolve actions (e.g.when infeasible)
207     void destroyPresolve();
208
209     /**@name private or protected data */
210private:
211     /// Original model - must not be destroyed before postsolve
212     ClpSimplex * originalModel_;
213
214     /// ClpPresolved model - up to user to destroy by deleteClpPresolvedModel
215     ClpSimplex * presolvedModel_;
216     /** "Magic" number. If this is non-zero then any elements with this value
217         may change and so presolve is very limited in what can be done
218         to the row and column.  This is for non-linear problems.
219         One could also allow for cases where sign of coefficient is known.
220     */
221     double nonLinearValue_;
222     /// Original column numbers
223     int * originalColumn_;
224     /// Original row numbers
225     int * originalRow_;
226     /// Row objective
227     double * rowObjective_;
228     /// The list of transformations applied.
229     const CoinPresolveAction *paction_;
230
231     /// The postsolved problem will expand back to its former size
232     /// as postsolve transformations are applied.
233     /// It is efficient to allocate data structures for the final size
234     /// of the problem rather than expand them as needed.
235     /// These fields give the size of the original problem.
236     int ncols_;
237     int nrows_;
238     CoinBigIndex nelems_;
239     /// Number of major passes
240     int numberPasses_;
241     /// Substitution level
242     int substitution_;
243#ifndef CLP_NO_STD
244     /// Name of saved model file
245     std::string saveFile_;
246#endif
247     /** Whether we want to skip dual part of presolve etc.
248         512 bit allows duplicate column processing on integer columns
249         and dual stuff on integers
250     */
251     int presolveActions_;
252protected:
253     /// If you want to apply the individual presolve routines differently,
254     /// or perhaps add your own to the mix,
255     /// define a derived class and override this method
256     virtual const CoinPresolveAction *presolve(CoinPresolveMatrix *prob);
257
258     /// Postsolving is pretty generic; just apply the transformations
259     /// in reverse order.
260     /// You will probably only be interested in overriding this method
261     /// if you want to add code to test for consistency
262     /// while debugging new presolve techniques.
263     virtual void postsolve(CoinPostsolveMatrix &prob);
264     /** This is main part of Presolve */
265     virtual ClpSimplex * gutsOfPresolvedModel(ClpSimplex * originalModel,
266               double feasibilityTolerance,
267               bool keepIntegers,
268               int numberPasses,
269               bool dropNames,
270                                               bool doRowObjective,
271                                               const char * prohibitedRows=NULL,
272                                               const char * prohibitedColumns=NULL);
273};
274#endif
Note: See TracBrowser for help on using the repository browser.