Scippy

SoPlex

Sequential object-oriented simPlex

spxweightst.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-2022 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 
17 /**@file spxweightst.h
18  * @brief Weighted start basis.
19  */
20 #ifndef _SPXWEIGHTST_H_
21 #define _SPXWEIGHTST_H_
22 
23 
24 #include <assert.h>
25 
26 #include "soplex/spxdefines.h"
27 #include "soplex/spxstarter.h"
28 #include "soplex/dataarray.h"
29 
30 namespace soplex
31 {
32 
33 /**@brief Weighted start basis.
34  @ingroup Algo
35 
36  Class SPxWeightST is an implementation of a SPxStarter for generating a
37  Simplex starting basis. Using method #setupWeights() it sets up arrays
38  #weight and #coWeight, or equivalently #rowWeight and #colWeight.
39  (#rowWeight and #colWeight are just pointers initialized to #weight and
40  #coWeight according to the representation of SoPlex \p base passed to
41  method #generate().)
42 
43  The weight values are then used to setup a starting basis for the LP:
44  vectors with low values are likely to become dual (i.e. basic for a column
45  basis) and such with high values are likely to become primal (i.e. nonbasic
46  for a column basis).
47 
48  However, if a variable having an upper and lower bound is to become primal,
49  there is still a choice for setting it either to its upper or lower bound.
50  Members #rowRight and #colUp are used to determine where to set a primal
51  variable. If #rowRight[i] is set to a nonzero value, the right-hand side
52  inequality is set tightly for the \p i 'th to become primal. Analogously, If
53  #colUp[j] is nonzero, the \p j 'th variable will be set to its upper bound
54  if it becomes primal.
55 */
56 template <class R>
57 class SPxWeightST : public SPxStarter<R>
58 {
59 private:
60 
61  //-----------------------------------
62  /**@name Private data */
63  ///@{
64  ///
66  ///
68  ///
70  ///@}
71 
72  //-----------------------------------
73  /**@name Private helpers */
74  ///@{
75  ///
76  void setPrimalStatus(typename SPxBasisBase<R>::Desc&, const SPxSolverBase<R>&, const SPxId&);
77  ///@}
78 
79 protected:
80 
81  //-----------------------------------
82  /**@name Protected data */
83  ///@{
84  /// weight value for LP rows.
86  /// weight value for LP columns.
88  /// set variable to rhs?.
90  /// set primal variable to upper bound.
92  ///@}
93 
94  //-----------------------------------
95  /**@name Protected helpers */
96  ///@{
97  /// sets up variable weights.
98  /** This method is called in order to setup the weights for all
99  variables. It has been declared \c virtual in order to allow for
100  derived classes to compute other weight values.
101  */
102  virtual void setupWeights(SPxSolverBase<R>& base);
103  ///@}
104 
105 public:
106 
107  //-----------------------------------
108  /**@name Construction / destruction */
109  ///@{
110  /// default constructor.
112  : SPxStarter<R>("Weight")
113  {
114  weight = 0;
115  coWeight = 0;
116  assert(isConsistent());
117  }
118  /// copy constructor
120  : SPxStarter<R>(old)
121  , forbidden(old.forbidden)
122  , rowWeight(old.rowWeight)
123  , colWeight(old.colWeight)
124  , rowRight(old.rowRight)
125  , colUp(old.colUp)
126  {
127  if(old.weight == &old.colWeight)
128  {
129  weight = &colWeight;
130  coWeight = &rowWeight;
131  }
132  else if(old.weight == &old.rowWeight)
133  {
134  weight = &rowWeight;
135  coWeight = &colWeight;
136  }
137  else // old.weight and old.coWeight are not set correctly, do nothing.
138  {
139  weight = 0;
140  coWeight = 0;
141  }
142 
143  assert(isConsistent());
144  }
145  /// assignment operator
147  {
148  if(this != &rhs)
149  {
151  forbidden = rhs.forbidden;
152  rowWeight = rhs.rowWeight;
153  colWeight = rhs.colWeight;
154  rowRight = rhs.rowRight;
155  colUp = rhs.colUp;
156 
157  if(rhs.weight == &rhs.colWeight)
158  {
159  weight = &colWeight;
160  coWeight = &rowWeight;
161  }
162  else if(rhs.weight == &rhs.rowWeight)
163  {
164  weight = &rowWeight;
165  coWeight = &colWeight;
166  }
167  else // old.weight and old.coWeight are not set correctly, do nothing.
168  {}
169 
170  assert(isConsistent());
171  }
172 
173  return *this;
174  }
175  /// destructor.
176  virtual ~SPxWeightST()
177  {
178  weight = 0;
179  coWeight = 0;
180  }
181  /// clone function for polymorphism
182  inline virtual SPxStarter<R>* clone() const
183  {
184  return new SPxWeightST(*this);
185  }
186  ///@}
187 
188  //-----------------------------------
189  /**@name Generation of a start basis */
190  ///@{
191  /// generates start basis for loaded basis.
192  void generate(SPxSolverBase<R>& base);
193  ///@}
194 
195  //-----------------------------------
196  /**@name Debugging */
197  ///@{
198  /// consistency check.
199  virtual bool isConsistent() const;
200  ///@}
201 
202 };
203 
204 } // namespace soplex
205 
206 // For general templated functions
207 #include "spxweightst.hpp"
208 
209 #endif // _SPXWEIGHTST_H_
SoPlex start basis generation base class.
Array< R > * coWeight
Definition: spxweightst.h:69
virtual ~SPxWeightST()
destructor.
Definition: spxweightst.h:176
Sequential object-oriented SimPlex.SPxSolverBase is an LP solver class using the revised Simplex algo...
Definition: spxbasis.h:49
virtual SPxStarter< R > * clone() const
clone function for polymorphism
Definition: spxweightst.h:182
SoPlex start basis generation base class.SPxStarter is the virtual base class for classes generating ...
Definition: spxsolver.h:59
SPxStarter & operator=(const SPxStarter &rhs)
assignment operator
Definition: spxstarter.h:67
Array< R > colWeight
weight value for LP columns.
Definition: spxweightst.h:87
Generic Ids for LP rows or columns.Both SPxColIds and SPxRowIds may be treated uniformly as SPxIds: ...
Definition: spxid.h:85
void setPrimalStatus(typename SPxBasisBase< R >::Desc &, const SPxSolverBase< R > &, const SPxId &)
Array< R > * weight
Definition: spxweightst.h:67
virtual void setupWeights(SPxSolverBase< R > &base)
sets up variable weights.
Basis descriptor.
Definition: spxbasis.h:106
Array< R > rowWeight
weight value for LP rows.
Definition: spxweightst.h:85
Debugging, floating point type and parameter definitions.
SPxWeightST()
default constructor.
Definition: spxweightst.h:111
Everything should be within this namespace.
SPxWeightST(const SPxWeightST &old)
copy constructor
Definition: spxweightst.h:119
Weighted start basis.Class SPxWeightST is an implementation of a SPxStarter for generating a Simplex ...
Definition: spxweightst.h:57
void generate(SPxSolverBase< R > &base)
generates start basis for loaded basis.
virtual bool isConsistent() const
consistency check.
Save arrays of data objects.
DataArray< int > forbidden
Definition: spxweightst.h:65
SPxWeightST & operator=(const SPxWeightST &rhs)
assignment operator
Definition: spxweightst.h:146
DataArray< bool > colUp
set primal variable to upper bound.
Definition: spxweightst.h:91
DataArray< bool > rowRight
set variable to rhs?.
Definition: spxweightst.h:89