Scippy

SoPlex

Sequential object-oriented simPlex

spxsimplifier.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the class library */
4 /* SoPlex --- the Sequential object-oriented simPlex. */
5 /* */
6 /* Copyright (C) 1996-2015 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SoPlex is distributed under the terms of the ZIB Academic Licence. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SoPlex; see the file COPYING. If not email to soplex@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file spxsimplifier.h
17  * @brief LP simplification base class.
18  */
19 #ifndef _SPXSIMPLIFIER_H_
20 #define _SPXSIMPLIFIER_H_
21 
22 #include <assert.h>
23 
24 #include "spxdefines.h"
25 #include "timerfactory.h"
26 #include "spxlp.h"
27 #include "spxsolver.h"
28 
29 namespace soplex
30 {
31 /**@brief LP simplification abstract base class.
32  @ingroup Algo
33 
34  Instances of classes derived from SPxSimplifier may be loaded to SoPlex in
35  order to simplify LPs before solving them. SoPlex will call #simplify()
36  on itself. Generally any SPxLP can be given to
37  a SPxSimplifier for #simplify()%ing it. The simplification cannot be undone,
38  but given an primal/dual solution for the simplified SPxLP, the simplifier
39  can reconstruct the primal/dual solution of the unsimplified LP.
40 */
42 {
43 protected:
44 
45  //-------------------------------------
46  /**@name Protected Data */
47  //@{
48  /// name of the simplifier
49  const char* m_name;
50  /// user time used for simplification
53  /// number of removed rows
54  int m_remRows;
55  /// number of removed columns
56  int m_remCols;
57  /// number of removed nonzero coefficients
58  int m_remNzos;
59  /// number of changed bounds
60  int m_chgBnds;
61  /// number of change right-hand sides
62  int m_chgLRhs;
63  /// number of kept bounds
65  /// number of kept left- and right-hand sides
67  /// objective offset
69  /// minimal reduction (sum of removed rows/cols) to continue simplification
71  /// message handler
73  //@}
74 
75 public:
76 
77  //-------------------------------------
78  /**@name Types */
79  //@{
80  /// Result of the simplification.
81  enum Result
82  {
83  OKAY = 0, ///< simplification could be done
84  INFEASIBLE = 1, ///< primal infeasibility was detected
85  DUAL_INFEASIBLE = 2, ///< dual infeasibility was detected
86  UNBOUNDED = 3, ///< primal unboundedness was detected
87  VANISHED = 4 ///< the problem was so much simplified that it vanished
88  };
89  //@}
90 
91  //-------------------------------------
92  /**@name Types */
93  //@{
94  /// constructor
95  explicit SPxSimplifier(const char* p_name, Timer::TYPE ttype = Timer::USER_TIME)
96  : m_name(p_name)
97  , m_timeUsed(0)
98  , m_timerType(ttype)
99  , m_remRows(0)
100  , m_remCols(0)
101  , m_remNzos(0)
102  , m_chgBnds(0)
103  , m_chgLRhs(0)
104  , m_keptBnds(0)
105  , m_keptLRhs(0)
106  , m_objoffset(1e-4)
107  , m_minReduction(0.0)
108  , spxout(0)
109  {
110  assert(isConsistent());
111 
113  }
114  /// copy constructor
116  : m_name(old.m_name)
117  , m_timerType(old.m_timerType)
118  , m_remRows(old.m_remRows)
119  , m_remCols(old.m_remCols)
120  , m_remNzos(old.m_remNzos)
121  , m_chgBnds(old.m_chgBnds)
122  , m_chgLRhs(old.m_chgLRhs)
123  , m_keptBnds(old.m_keptBnds)
124  , m_keptLRhs(old.m_keptLRhs)
125  , m_objoffset(old.m_objoffset)
126  , m_minReduction(1e-4)
127  , spxout(old.spxout)
128  {
130  assert(isConsistent());
131  }
132  /// assignment operator
134  {
135  if(this != &rhs)
136  {
137  m_name = rhs.m_name;
138  *m_timeUsed = *(rhs.m_timeUsed);
139  m_timerType = rhs.m_timerType;
140  m_remRows = rhs.m_remRows;
141  m_remCols = rhs.m_remCols;
142  m_remNzos = rhs.m_remNzos;
143  m_chgBnds = rhs.m_chgBnds;
144  m_chgLRhs = rhs.m_chgLRhs;
145  m_keptBnds = rhs.m_keptBnds;
146  m_keptLRhs = rhs.m_keptLRhs;
147  m_objoffset = rhs.m_objoffset;
149  spxout = rhs.spxout;
150 
151  assert(isConsistent());
152  }
153 
154  return *this;
155  }
156  /// destructor.
157  virtual ~SPxSimplifier()
158  {
159  m_name = 0;
160  m_timeUsed->~Timer();
162  }
163  /// clone function for polymorphism
164  virtual SPxSimplifier* clone() const = 0;
165  //@}
166 
167  //-------------------------------------
168  /**@name Access / modfication */
169  //@{
170  /// get name of simplifier.
171  virtual const char* getName() const
172  {
173  return m_name;
174  }
175  virtual Real timeUsed() const
176  {
177  return m_timeUsed->time();
178  }
179  //@}
180 
181  //-------------------------------------
182  /**@name Simplifying / unsimplifying */
183  //@{
184  /// simplify SPxLP \p lp with identical primal and dual feasibility tolerance.
185  virtual Result simplify(SPxLP& lp, Real eps, Real delta) = 0;
186  /// simplify SPxLP \p lp with independent primal and dual feasibility tolerance.
187  virtual Result simplify(SPxLP& lp, Real eps, Real feastol, Real opttol, bool keepbounds = false) = 0;
188  /// reconstructs an optimal solution for the unsimplified LP.
189  virtual void unsimplify(const Vector&, const Vector&, const Vector&, const Vector&,
190  const SPxSolver::VarStatus[], const SPxSolver::VarStatus[]) {}
191  /// returns result status of the simplification
192  virtual Result result() const = 0;
193  /// specifies whether an optimal solution has already been unsimplified.
194  virtual bool isUnsimplified() const
195  {
196  return false;
197  }
198  /// returns a reference to the unsimplified primal solution.
199  virtual const Vector& unsimplifiedPrimal() = 0;
200 
201  /// returns a reference to the unsimplified dual solution.
202  virtual const Vector& unsimplifiedDual() = 0;
203 
204  /// returns a reference to the unsimplified slack values.
205  virtual const Vector& unsimplifiedSlacks() = 0;
206 
207  /// returns a reference to the unsimplified reduced costs.
208  virtual const Vector& unsimplifiedRedCost() = 0;
209 
210  /// gets basis status for a single row.
211  virtual SPxSolver::VarStatus getBasisRowStatus(int) const = 0;
212 
213  /// gets basis status for a single column.
214  virtual SPxSolver::VarStatus getBasisColStatus(int) const = 0;
215 
216  /// get optimal basis.
217  virtual void getBasis(SPxSolver::VarStatus[], SPxSolver::VarStatus[], const int rowsSize = -1, const int colsSize = -1) const = 0;
218 
219  /// get objective offset.
220  virtual Real getObjoffset() const
221  {
222  return m_objoffset;
223  }
224 
225  /// add objective offset.
226  virtual void addObjoffset(const Real val)
227  {
228  m_objoffset += val;
229  }
230 
231  /// set minimal reduction threshold to continue simplification
232  virtual void setMinReduction(const Real minRed)
233  {
234  m_minReduction = minRed;
235  }
236  //@}
237 
238  //-------------------------------------
239  /**@name Consistency check */
240  //@{
241  /// consistency check
242  virtual bool isConsistent() const
243  {
244  return true;
245  }
246  //@}
247 
248 };
249 } // namespace soplex
250 #endif // _SPXSIMPLIFIER_H_