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