Scippy

SoPlex

Sequential object-oriented simPlex

spxboundflippingrt.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-2025 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/**@file spxboundflippingrt.h
26 * @brief Bound flipping ratio test (long step dual) for SoPlex.
27 * @author Matthias Miltenberger
28 * @author Eva Ramlow
29 */
30#ifndef _SPXBOUNDFLIPPINGRT_H_
31#define _SPXBOUNDFLIPPINGRT_H_
32
33
34#include <assert.h>
35#include "soplex/spxdefines.h"
37#include "soplex/spxfastrt.h"
38
39namespace soplex
40{
41
42/**@brief Bound flipping ratio test ("long step dual") for SoPlex.
43 @ingroup Algo
44
45 Class SPxBoundFlippingRT provides an implementation of the bound flipping
46 ratio test as a derived class of SPxRatioTester. Dual step length is
47 increased beyond some breakpoints and corresponding primal nonbasic
48 variables are set to their other bound to handle the resulting dual infeasibility.
49
50 The implementation mostly follows the papers
51 - I. Maros, "A generalized dual phase-2 simplex algorithm",
52 European Journal of Operational Research Vol 149, Issue 1, pp. 1-16, 2003
53 - A. Koberstein, "Progress in the dual simplex algorithm for solving large scale LP problems:
54 techniques for a fast and stable implementation",
55 Computational Optimization and Applications Vol 41, Nr 2, pp. 185-204, 2008
56
57 See SPxRatioTester for a class documentation.
58*/
59template <class R>
61{
62private:
63 /**@name substructures */
64 ///@{
65 /** enumerator to remember which vector we have been searching to find a breakpoint
66 */
68 {
69 FVEC = -1,
70 PVEC = 0,
71 COPVEC = 1
72 };
73
74 /** breakpoint structure
75 */
77 {
78 R val; /**< breakpoint value (step length) */
79 int idx; /**< index of corresponding row/column */
80 BreakpointSource src; /**< origin of breakpoint, i.e. vector which was searched */
81 };
82
83 /** Compare class for breakpoints
84 */
86 {
87 public:
88 /** constructor
89 */
91 : entry(nullptr)
92 {
93 }
94
96
98 Breakpoint i,
100 ) const
101 {
102 // the first case is needed to handle exceptional inf values
103 return (i.val == j.val) ? 0 : i.val - j.val;
104 }
105 };
106 ///@}
107
108 /**@name Data
109 */
110 ///@{
111 bool enableBoundFlips; /**< enable or disable long steps in BoundFlippingRT */
112 bool enableRowBoundFlips;/**< enable bound flips also for row representation */
113 R
114 flipPotential; /**< tracks bound flip history and decides which ratio test to use */
115 int relax_count; /**< count rounds of ratio test */
116 Array<Breakpoint> breakpoints; /**< array of breakpoints */
118 updPrimRhs; /**< right hand side vector of additional system to be solved after the ratio test */
120 updPrimVec; /**< allocation of memory for additional solution vector */
121 ///@}
122
123 /** store all available pivots/breakpoints in an array (positive pivot search direction) */
125 int& nBp, /**< number of found breakpoints so far */
126 int& minIdx, /**< index to current minimal breakpoint */
127 const int* idx, /**< pointer to indices of current vector */
128 int nnz, /**< number of nonzeros in current vector */
129 const R* upd, /**< pointer to update values of current vector */
130 const R* vec, /**< pointer to values of current vector */
131 const R* upp, /**< pointer to upper bound/rhs of current vector */
132 const R* low, /**< pointer to lower bound/lhs of current vector */
133 BreakpointSource src /**< type of vector (pVec or coPvec)*/
134 );
135
136 /** store all available pivots/breakpoints in an array (negative pivot search direction) */
138 int& nBp, /**< number of found breakpoints so far */
139 int& minIdx, /**< index to current minimal breakpoint */
140 const int* idx, /**< pointer to indices of current vector */
141 int nnz, /**< number of nonzeros in current vector */
142 const R* upd, /**< pointer to update values of current vector */
143 const R* vec, /**< pointer to values of current vector */
144 const R* upp, /**< pointer to upper bound/rhs of current vector */
145 const R* low, /**< pointer to lower bound/lhs of current vector */
146 BreakpointSource src /**< type of vector (pVec or coPvec)*/
147 );
148
149 /** get values for entering index and perform shifts if necessary */
151 R& val,
152 SPxId& enterId,
153 int idx,
154 R stab,
155 R degeneps,
156 const R* upd,
157 const R* vec,
158 const R* low,
159 const R* upp,
161 R max
162 );
163
164 /** get values for leaving index and perform shifts if necessary */
166 R& val,
167 int& leaveIdx,
168 int idx,
169 R stab,
170 R degeneps,
171 const R* upd,
172 const R* vec,
173 const R* low,
174 const R* upp,
176 R max
177 );
178
179 /** perform necessary bound flips to restore dual feasibility */
181 int& usedBp /**< number of bounds that should be flipped */
182 );
183
184 /** comparison method for breakpoints */
185 static bool isSmaller(
186 Breakpoint x,
187 Breakpoint y
188 )
189 {
190 return (spxAbs(x.val) < spxAbs(y.val));
191 };
192
193public:
194
195 //-------------------------------------
196 /**@name Construction / destruction */
197 ///@{
198 /// default constructor
200 : SPxFastRT<R>("Bound Flipping")
201 , enableBoundFlips(true)
202 , enableRowBoundFlips(false)
203 , flipPotential(1)
204 , relax_count(0)
205 , breakpoints(10)
206 , updPrimRhs(0)
207 , updPrimVec(0)
208 {}
209 /// copy constructor
211 : SPxFastRT<R>(old)
214 , flipPotential(1)
215 , relax_count(0)
216 , breakpoints(10)
217 , updPrimRhs(0)
218 , updPrimVec(0)
219 {}
220 /// assignment operator
222 {
223 if(this != &rhs)
224 {
226 }
227
231
232 return *this;
233 }
234 /// destructor
236 {}
237 /// clone function for polymorphism
238 inline virtual SPxRatioTester<R>* clone() const
239 {
240 return new SPxBoundFlippingRT(*this);
241 }
242 ///@}
243
244 //-------------------------------------
245 /**@name Select enter/leave */
246 ///@{
247 ///
248 virtual int selectLeave(
249 R& val,
250 R enterTest,
251 bool polish = false
252 );
253 ///
255 R& val,
256 int leaveIdx,
257 bool polish = false
258 );
259
260 void useBoundFlips(bool bf)
261 {
262 enableBoundFlips = bf;
263 }
264
265 void useBoundFlipsRow(bool bf)
266 {
268 }
269
270 /// set tolerances
271 void setTolerances(std::shared_ptr<Tolerances> tolerances)
272 {
273 this->_tolerances = tolerances;
274 this->updPrimRhs.setTolerances(tolerances);
275 this->updPrimVec.setTolerances(tolerances);
276 }
277 ///@}
278};
279
280} // namespace soplex
281
282#include "spxboundflippingrt.hpp"
283
284#endif // _SPXBOUNDFLIPPINGRT_H_
Safe arrays of arbitrary types.
Definition: array.h:73
Bound flipping ratio test ("long step dual") for SoPlex.
void collectBreakpointsMax(int &nBp, int &minIdx, const int *idx, int nnz, const R *upd, const R *vec, const R *upp, const R *low, BreakpointSource src)
virtual SPxRatioTester< R > * clone() const
clone function for polymorphism
void collectBreakpointsMin(int &nBp, int &minIdx, const int *idx, int nnz, const R *upd, const R *vec, const R *upp, const R *low, BreakpointSource src)
SPxBoundFlippingRT & operator=(const SPxBoundFlippingRT &rhs)
assignment operator
Array< Breakpoint > breakpoints
SPxBoundFlippingRT()
default constructor
virtual int selectLeave(R &val, R enterTest, bool polish=false)
void setTolerances(std::shared_ptr< Tolerances > tolerances)
set tolerances
void flipAndUpdate(int &usedBp)
virtual ~SPxBoundFlippingRT()
destructor
bool getData(R &val, SPxId &enterId, int idx, R stab, R degeneps, const R *upd, const R *vec, const R *low, const R *upp, BreakpointSource src, R max)
virtual SPxId selectEnter(R &val, int leaveIdx, bool polish=false)
static bool isSmaller(Breakpoint x, Breakpoint y)
SPxBoundFlippingRT(const SPxBoundFlippingRT &old)
copy constructor
bool getData(R &val, int &leaveIdx, int idx, R stab, R degeneps, const R *upd, const R *vec, const R *low, const R *upp, BreakpointSource src, R max)
Fast shifting ratio test.
Definition: spxfastrt.h:54
SPxFastRT & operator=(const SPxFastRT &rhs)
assignment operator
Definition: spxfastrt.h:205
Generic Ids for LP rows or columns.
Definition: spxid.h:95
Abstract ratio test base class.
const std::shared_ptr< Tolerances > tolerances() const
get the _tolerances member variable
std::shared_ptr< Tolerances > _tolerances
tolerances used by the solver
Semi sparse vector.
Definition: ssvectorbase.h:57
Everything should be within this namespace.
R spxAbs(R a)
Definition: spxdefines.h:392
Debugging, floating point type and parameter definitions.
Fast shifting ratio test.
Abstract ratio test base class.
R operator()(Breakpoint i, Breakpoint j) const