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 | |
---|
8 | class CoinPresolveAction; |
---|
9 | #include "CoinPresolveMatrix.hpp" |
---|
10 | /** This is the Clp interface to CoinPresolve |
---|
11 | |
---|
12 | */ |
---|
13 | class ClpPresolve { |
---|
14 | public: |
---|
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 doDualPresolve() const |
---|
73 | { return (presolveActions_&1)==0;}; |
---|
74 | inline void setDoDualPresolve(bool doDual) |
---|
75 | { if (doDual) presolveActions_ &= ~1; else presolveActions_ |= 1;}; |
---|
76 | |
---|
77 | /**@name postsolve - postsolve the problem. If the problem |
---|
78 | has not been solved to optimality, there are no guarantees. |
---|
79 | If you are using an algorithm like simplex that has a concept |
---|
80 | of "basic" rows/cols, then set updateStatus |
---|
81 | |
---|
82 | Note that if you modified the original problem after presolving, |
---|
83 | then you must ``undo'' these modifications before calling postsolve. |
---|
84 | This version updates original*/ |
---|
85 | virtual void postsolve(bool updateStatus=true); |
---|
86 | |
---|
87 | /// Gets rid of presolve actions (e.g.when infeasible) |
---|
88 | void destroyPresolve(); |
---|
89 | |
---|
90 | /**@name private or protected data */ |
---|
91 | private: |
---|
92 | /// Original model - must not be destroyed before postsolve |
---|
93 | ClpSimplex * originalModel_; |
---|
94 | |
---|
95 | /// ClpPresolved model - up to user to destroy by deleteClpPresolvedModel |
---|
96 | ClpSimplex * presolvedModel_; |
---|
97 | /** "Magic" number. If this is non-zero then any elements with this value |
---|
98 | may change and so presolve is very limited in what can be done |
---|
99 | to the row and column. This is for non-linear problems. |
---|
100 | One could also allow for cases where sign of coefficient is known. |
---|
101 | */ |
---|
102 | double nonLinearValue_; |
---|
103 | /// Original column numbers |
---|
104 | int * originalColumn_; |
---|
105 | /// Original row numbers |
---|
106 | int * originalRow_; |
---|
107 | /// The list of transformations applied. |
---|
108 | const CoinPresolveAction *paction_; |
---|
109 | |
---|
110 | /// The postsolved problem will expand back to its former size |
---|
111 | /// as postsolve transformations are applied. |
---|
112 | /// It is efficient to allocate data structures for the final size |
---|
113 | /// of the problem rather than expand them as needed. |
---|
114 | /// These fields give the size of the original problem. |
---|
115 | int ncols_; |
---|
116 | int nrows_; |
---|
117 | CoinBigIndex nelems_; |
---|
118 | /// Number of major passes |
---|
119 | int numberPasses_; |
---|
120 | /// Name of saved model file |
---|
121 | std::string saveFile_; |
---|
122 | /// Whether we want to skip dual part of presolve etc |
---|
123 | int presolveActions_; |
---|
124 | protected: |
---|
125 | /// If you want to apply the individual presolve routines differently, |
---|
126 | /// or perhaps add your own to the mix, |
---|
127 | /// define a derived class and override this method |
---|
128 | virtual const CoinPresolveAction *presolve(CoinPresolveMatrix *prob); |
---|
129 | |
---|
130 | /// Postsolving is pretty generic; just apply the transformations |
---|
131 | /// in reverse order. |
---|
132 | /// You will probably only be interested in overriding this method |
---|
133 | /// if you want to add code to test for consistency |
---|
134 | /// while debugging new presolve techniques. |
---|
135 | virtual void postsolve(CoinPostsolveMatrix &prob); |
---|
136 | /** This is main part of Presolve */ |
---|
137 | virtual ClpSimplex * gutsOfPresolvedModel(ClpSimplex * originalModel |
---|
138 | ,double feasibilityTolerance, |
---|
139 | bool keepIntegers, |
---|
140 | int numberPasses, |
---|
141 | bool dropNames); |
---|
142 | }; |
---|
143 | #endif |
---|