1    	/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2    	/*                                                                           */
3    	/*                  This file is part of the class library                   */
4    	/*       SoPlex --- the Sequential object-oriented simPlex.                  */
5    	/*                                                                           */
6    	/*  Copyright (c) 1996-2023 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  spxautopr.h
26   	 * @brief Auto pricer.
27   	 */
28   	#ifndef _SPXAUTOPR_H_
29   	#define _SPXAUTOPR_H_
30   	
31   	#include <assert.h>
32   	
33   	#include "soplex/spxpricer.h"
34   	#include "soplex/spxdevexpr.h"
35   	#include "soplex/spxsteeppr.h"
36   	#include "soplex/spxsteepexpr.h"
37   	
38   	
39   	namespace soplex
40   	{
41   	
42   	/**@brief   Auto pricer.
43   	   @ingroup Algo
44   	
45   	   This pricer switches between Devex and Steepest edge pricer based on the difficulty of the problem
46   	   which is determined by the number of iterations.
47   	
48   	   See SPxPricer for a class documentation.
49   	*/
50   	template <class R>
51   	class SPxAutoPR : public SPxPricer<R>
52   	{
53   	private:
54   	
55   	   int            switchIters;   ///< number of iterations before switching pricers
56   	   SPxPricer<R>*     activepricer;  ///< pointer to currently selected pricer
57   	   SPxDevexPR<R>     devex;         ///< internal Devex pricer
58   	   SPxSteepExPR<R>     steep;         ///< internal Steepest edge pricer
59   	
60   	   bool setActivePricer(typename SPxSolverBase<R>::Type
61   	                        type);          ///< switches active pricing method
62   	
63   	public:
64   	
65   	   //-------------------------------------
66   	   /**@name Constructors / destructors */
67   	   ///@{
68   	   /// default constructor
69   	   SPxAutoPR()
70   	      : SPxPricer<R>("Auto")
71   	      , switchIters(10000)
72   	      , activepricer(&devex)
73   	      , devex()
74   	      , steep()
75   	   {}
76   	   /// copy constructor
77   	   SPxAutoPR(const SPxAutoPR& old)
78   	      : SPxPricer<R>(old)
79   	      , switchIters(old.switchIters)
80   	      , devex(old.devex)
81   	      , steep(old.steep)
82   	   {
83   	      assert(old.activepricer == &old.devex || old.activepricer == &old.steep);
84   	
85   	      if(old.activepricer == &old.devex)
86   	         activepricer = &devex;
87   	      else
88   	         activepricer = &steep;
89   	   }
90   	   /// assignment operator
91   	   SPxAutoPR& operator=(const SPxAutoPR& rhs)
92   	   {
93   	      if(this != &rhs)
94   	      {
95   	         SPxPricer<R>::operator=(rhs);
96   	         switchIters = rhs.switchIters;
97   	         devex = rhs.devex;
98   	         steep = rhs.steep;
99   	
100  	         assert(rhs.activepricer == &rhs.devex || rhs.activepricer == &rhs.steep);
101  	
102  	         if(rhs.activepricer == &rhs.devex)
103  	            activepricer = &devex;
104  	         else
105  	            activepricer = &steep;
106  	      }
107  	
108  	      return *this;
109  	   }
110  	   /// destructor
111  	   virtual ~SPxAutoPR()
112  	   {}
113  	   /// clone function for polymorphism
114  	   inline virtual SPxPricer<R>* clone() const
115  	   {
116  	      return new SPxAutoPR(*this);
117  	   }
118  	   ///@}
119  	
120  	   //-------------------------------------
121  	   /**@name Access / modification */
122  	   ///@{
123  	   /// set max number of iterations before switching pricers
124  	   void setSwitchIters(int iters);
125  	   /// clear the data
126  	   void clear();
127  	   /// set tolerances of internal pricers
128  	   void setPricingTolerance(R tol);
129  	   /// set the solver
130  	   virtual void load(SPxSolverBase<R>* base);
131  	   /// set entering/leaving algorithm
132  	   virtual void setType(typename SPxSolverBase<R>::Type);
133  	   /// set row/column representation
134  	   virtual void setRep(typename SPxSolverBase<R>::Representation);
135  	   ///
136  	   virtual int selectLeave();
137  	   ///
138  	   virtual SPxId selectEnter();
139  	   ///
140  	   virtual void left4(int n, SPxId id);
141  	   ///
142  	   virtual void entered4(SPxId id, int n);
143  	   ///@}
144  	};
145  	} // namespace soplex
146  	
147  	// For general templated functions
148  	#include "spxautopr.hpp"
149  	
150  	#endif // _SPXAUTOPR_H_
151