SoPlex Doxygen Documentation
lprow.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-2012 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 lprow.h
17  * @brief (In)equality for LPs.
18  */
19 #ifndef _LPROW_H_
20 #define _LPROW_H_
21 
22 #include <assert.h>
23 
24 #include "spxdefines.h"
25 #include "dsvector.h"
26 
27 namespace soplex
28 {
29 /**@brief (In)equality for LPs.
30  @ingroup Algo
31 
32  Class LPRow provides constraints for linear programs in the form
33  \f[
34  l \le a^Tx \le r,
35  \f]
36  where \em a is a DSVector. \em l is referred to as
37  %left hand side,
38  \em r as %right hand side and \em a as \em row \em vector or
39  the constraint vector. \em l and \em r may also take values
40  \f$\pm\f$ #infinity.
41  This static member is predefined, but may be overridden to meet
42  the needs of the LP solver to be used.
43 
44  LPRows allow to specify regular inequalities of the form
45  \f[
46  a^Tx \sim \alpha,
47  \f]
48  where \f$\sim\f$ can take any value
49  of \f$\le, =, \ge\f$, by setting rhs and
50  lhs to the same value or setting one of them to \f$\infty\f$.
51 
52  Since constraints in the regular form occur often, LPRows offers methods
53  type() and value() for retreiving \f$\sim\f$ and \f$\alpha\f$ of
54  an LPRow in this form, respectively. Also, a constructor for
55  LPRows given in regular form is provided.
56 */
57 class LPRow
58 {
59 private:
60 
61  //------------------------------------
62  /**@name Data */
63  //@{
64  Real left; ///< left-hand side of the constraint
65  Real right; ///< right-hand side of the constraint
66  DSVector vec; ///< the row vector
67  //@}
68 
69 public:
70 
71  //------------------------------------
72  /**@name Types */
73  //@{
74  /// (In)Equality of an LP row.
75  /** #LPRow%s may be of one of the above Types. This datatype may be
76  * used for constructing new #LPRow%s in the regular form.
77  */
78  enum Type
79  {
80  LESS_EQUAL, ///< \f$a^Tx \le \alpha\f$.
81  EQUAL, ///< \f$a^Tx = \alpha\f$.
82  GREATER_EQUAL, ///< \f$a^Tx \ge \alpha\f$.
83  RANGE ///< \f$\lambda \le a^Tx \le \rho\f$.
84  };
85  //@}
86 
87  //------------------------------------
88  /**@name Construction / destruction */
89  //@{
90  /// Construct LPRow with a vector ready to hold \p defDim nonzeros
91  explicit LPRow(int defDim = 0)
92  : left(0), right(infinity), vec(defDim)
93  {
94  assert(isConsistent());
95  }
96 
97  /// copy constructor
98  LPRow(const LPRow& row)
99  : left(row.left), right(row.right), vec(row.vec)
100  {
101  assert(isConsistent());
102  }
103 
104  /// Construct LPRow with the given left-hand side, right-hand side
105  /// and rowVector.
106  LPRow(Real p_lhs, const SVector& p_rowVector, Real p_rhs)
107  : left(p_lhs), right(p_rhs), vec(p_rowVector)
108  {
109  assert(isConsistent());
110  }
111 
112  /// Construct LPRow from passed \p rowVector, \p type and \p value
113  LPRow(const SVector& p_rowVector, Type p_type, Real p_value);
114 
115  /// destructor
117  {}
118  //@}
119 
120  //------------------------------------
121  /**@name Access / modification */
122  //@{
123  /// get type of row.
124  Type type() const;
125 
126  /// set type of (in)equality
127  void setType(Type p_type);
128 
129  /// Right hand side value of (in)equality.
130  /** This method returns \f$\alpha\f$ for a LPRow in regular form.
131  * However, value() may only be called for LPRow%s with
132  * type() != \c RANGE.
133  */
134  Real value() const;
135 
136  /// get left-hand side value.
137  Real lhs() const
138  {
139  return left;
140  }
141 
142  /// access left-hand side value.
143  void setLhs(Real p_left)
144  {
145  left = p_left;
146  }
147 
148  /// get right-hand side value.
149  Real rhs() const
150  {
151  return right;
152  }
153 
154  /// access right-hand side value.
155  void setRhs(Real p_right)
156  {
157  right = p_right;
158  }
159 
160  /// get constraint row vector
161  const SVector& rowVector() const
162  {
163  return vec;
164  }
165 
166  /// access constraint row vector.
167  void setRowVector(const DSVector& p_vec)
168  {
169  vec = p_vec;
170  }
171  //@}
172 
173  //------------------------------------
174  /**@name Consistency check */
175  //@{
176  /// check consistency.
177  bool isConsistent() const
178  {
179 #ifdef ENABLE_CONSISTENCY_CHECKS
180  return vec.isConsistent();
181 #else
182  return true;
183 #endif
184  }
185  //@}
186 };
187 
188 } // namespace soplex
189 #endif // _LPROW_H_
190 
191 //-----------------------------------------------------------------------------
192 //Emacs Local Variables:
193 //Emacs mode:c++
194 //Emacs c-basic-offset:3
195 //Emacs tab-width:8
196 //Emacs indent-tabs-mode:nil
197 //Emacs End:
198 //-----------------------------------------------------------------------------