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

Last change on this file since 2385 was 2385, checked in by unxusr, 3 months ago

formatting

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 10.8 KB
Line 
1/* $Id: ClpPresolve.hpp 2385 2019-01-06 19:43:06Z unxusr $ */
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  {
78    nonLinearValue_ = value;
79  }
80  inline double nonLinearValue() const
81  {
82    return nonLinearValue_;
83  }
84  /// Whether we want to do dual part of presolve
85  inline bool doDual() const
86  {
87    return (presolveActions_ & 1) == 0;
88  }
89  inline void setDoDual(bool doDual)
90  {
91    if (doDual)
92      presolveActions_ &= ~1;
93    else
94      presolveActions_ |= 1;
95  }
96  /// Whether we want to do singleton part of presolve
97  inline bool doSingleton() const
98  {
99    return (presolveActions_ & 2) == 0;
100  }
101  inline void setDoSingleton(bool doSingleton)
102  {
103    if (doSingleton)
104      presolveActions_ &= ~2;
105    else
106      presolveActions_ |= 2;
107  }
108  /// Whether we want to do doubleton part of presolve
109  inline bool doDoubleton() const
110  {
111    return (presolveActions_ & 4) == 0;
112  }
113  inline void setDoDoubleton(bool doDoubleton)
114  {
115    if (doDoubleton)
116      presolveActions_ &= ~4;
117    else
118      presolveActions_ |= 4;
119  }
120  /// Whether we want to do tripleton part of presolve
121  inline bool doTripleton() const
122  {
123    return (presolveActions_ & 8) == 0;
124  }
125  inline void setDoTripleton(bool doTripleton)
126  {
127    if (doTripleton)
128      presolveActions_ &= ~8;
129    else
130      presolveActions_ |= 8;
131  }
132  /// Whether we want to do tighten part of presolve
133  inline bool doTighten() const
134  {
135    return (presolveActions_ & 16) == 0;
136  }
137  inline void setDoTighten(bool doTighten)
138  {
139    if (doTighten)
140      presolveActions_ &= ~16;
141    else
142      presolveActions_ |= 16;
143  }
144  /// Whether we want to do forcing part of presolve
145  inline bool doForcing() const
146  {
147    return (presolveActions_ & 32) == 0;
148  }
149  inline void setDoForcing(bool doForcing)
150  {
151    if (doForcing)
152      presolveActions_ &= ~32;
153    else
154      presolveActions_ |= 32;
155  }
156  /// Whether we want to do impliedfree part of presolve
157  inline bool doImpliedFree() const
158  {
159    return (presolveActions_ & 64) == 0;
160  }
161  inline void setDoImpliedFree(bool doImpliedfree)
162  {
163    if (doImpliedfree)
164      presolveActions_ &= ~64;
165    else
166      presolveActions_ |= 64;
167  }
168  /// Whether we want to do dupcol part of presolve
169  inline bool doDupcol() const
170  {
171    return (presolveActions_ & 128) == 0;
172  }
173  inline void setDoDupcol(bool doDupcol)
174  {
175    if (doDupcol)
176      presolveActions_ &= ~128;
177    else
178      presolveActions_ |= 128;
179  }
180  /// Whether we want to do duprow part of presolve
181  inline bool doDuprow() const
182  {
183    return (presolveActions_ & 256) == 0;
184  }
185  inline void setDoDuprow(bool doDuprow)
186  {
187    if (doDuprow)
188      presolveActions_ &= ~256;
189    else
190      presolveActions_ |= 256;
191  }
192  /// Whether we want to do dependency part of presolve
193  inline bool doDependency() const
194  {
195    return (presolveActions_ & 32768) != 0;
196  }
197  inline void setDoDependency(bool doDependency)
198  {
199    if (doDependency)
200      presolveActions_ |= 32768;
201    else
202      presolveActions_ &= ~32768;
203  }
204  /// Whether we want to do transfer part of presolve
205  inline bool doTransfer() const
206  {
207    return (presolveActions_ & 65536) != 0;
208  }
209  inline void setDoTransfer(bool doTransfer)
210  {
211    if (doTransfer)
212      presolveActions_ |= 65536;
213    else
214      presolveActions_ &= ~65536;
215  }
216  /// Whether we want to do singleton column part of presolve
217  inline bool doSingletonColumn() const
218  {
219    return (presolveActions_ & 512) == 0;
220  }
221  inline void setDoSingletonColumn(bool doSingleton)
222  {
223    if (doSingleton)
224      presolveActions_ &= ~512;
225    else
226      presolveActions_ |= 512;
227  }
228  /// Whether we want to do gubrow part of presolve
229  inline bool doGubrow() const
230  {
231    return (presolveActions_ & 1024) == 0;
232  }
233  inline void setDoGubrow(bool doGubrow)
234  {
235    if (doGubrow)
236      presolveActions_ &= ~1024;
237    else
238      presolveActions_ |= 1024;
239  }
240  /// Whether we want to do twoxtwo part of presolve
241  inline bool doTwoxTwo() const
242  {
243    return (presolveActions_ & 2048) != 0;
244  }
245  inline void setDoTwoxtwo(bool doTwoxTwo)
246  {
247    if (!doTwoxTwo)
248      presolveActions_ &= ~2048;
249    else
250      presolveActions_ |= 2048;
251  }
252  /// Whether we want to allow duplicate intersections
253  inline bool doIntersection() const
254  {
255    return (presolveActions_ & 4096) != 0;
256  }
257  inline void setDoIntersection(bool doIntersection)
258  {
259    if (doIntersection)
260      presolveActions_ &= ~4096;
261    else
262      presolveActions_ |= 4096;
263  }
264  /** How much we want to zero small values from aggregation - ratio
265         0 - 1.0e-12, 1 1.0e-11, 2 1.0e-10, 3 1.0e-9 */
266  inline int zeroSmall() const
267  {
268    return (presolveActions_ & (8192 | 16384)) >> 13;
269  }
270  inline void setZeroSmall(int value)
271  {
272    presolveActions_ &= ~(8192 | 16384);
273    presolveActions_ |= value << 13;
274  }
275  /// Set whole group
276  inline int presolveActions() const
277  {
278    return presolveActions_ & 0xffffff;
279  }
280  inline void setPresolveActions(int action)
281  {
282    presolveActions_ = (presolveActions_ & 0xff000000) | (action & 0xffffff);
283  }
284  /// Substitution level
285  inline void setSubstitution(int value)
286  {
287    substitution_ = value;
288  }
289  /// Asks for statistics
290  inline void statistics()
291  {
292    presolveActions_ |= 0x80000000;
293  }
294  /// Return presolve status (0,1,2)
295  int presolveStatus() const;
296
297  /**@name postsolve - postsolve the problem.  If the problem
298       has not been solved to optimality, there are no guarantees.
299      If you are using an algorithm like simplex that has a concept
300      of "basic" rows/cols, then set updateStatus
301
302      Note that if you modified the original problem after presolving,
303      then you must ``undo'' these modifications before calling postsolve.
304     This version updates original*/
305  virtual void postsolve(bool updateStatus = true);
306
307  /// Gets rid of presolve actions (e.g.when infeasible)
308  void destroyPresolve();
309
310  /**@name private or protected data */
311private:
312  /// Original model - must not be destroyed before postsolve
313  ClpSimplex *originalModel_;
314
315  /// ClpPresolved model - up to user to destroy by deleteClpPresolvedModel
316  ClpSimplex *presolvedModel_;
317  /** "Magic" number. If this is non-zero then any elements with this value
318         may change and so presolve is very limited in what can be done
319         to the row and column.  This is for non-linear problems.
320         One could also allow for cases where sign of coefficient is known.
321     */
322  double nonLinearValue_;
323  /// Original column numbers
324  int *originalColumn_;
325  /// Original row numbers
326  int *originalRow_;
327  /// Row objective
328  double *rowObjective_;
329  /// The list of transformations applied.
330  const CoinPresolveAction *paction_;
331
332  /// The postsolved problem will expand back to its former size
333  /// as postsolve transformations are applied.
334  /// It is efficient to allocate data structures for the final size
335  /// of the problem rather than expand them as needed.
336  /// These fields give the size of the original problem.
337  int ncols_;
338  int nrows_;
339  CoinBigIndex nelems_;
340  /// Number of major passes
341  int numberPasses_;
342  /// Substitution level
343  int substitution_;
344#ifndef CLP_NO_STD
345  /// Name of saved model file
346  std::string saveFile_;
347#endif
348  /** Whether we want to skip dual part of presolve etc.
349         512 bit allows duplicate column processing on integer columns
350         and dual stuff on integers
351     */
352  int presolveActions_;
353
354protected:
355  /// If you want to apply the individual presolve routines differently,
356  /// or perhaps add your own to the mix,
357  /// define a derived class and override this method
358  virtual const CoinPresolveAction *presolve(CoinPresolveMatrix *prob);
359
360  /// Postsolving is pretty generic; just apply the transformations
361  /// in reverse order.
362  /// You will probably only be interested in overriding this method
363  /// if you want to add code to test for consistency
364  /// while debugging new presolve techniques.
365  virtual void postsolve(CoinPostsolveMatrix &prob);
366  /** This is main part of Presolve */
367  virtual ClpSimplex *gutsOfPresolvedModel(ClpSimplex *originalModel,
368    double feasibilityTolerance,
369    bool keepIntegers,
370    int numberPasses,
371    bool dropNames,
372    bool doRowObjective,
373    const char *prohibitedRows = NULL,
374    const char *prohibitedColumns = NULL);
375};
376#endif
377
378/* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
379*/
Note: See TracBrowser for help on using the repository browser.