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   	#include <iostream>
26   	
27   	#include "soplex/spxdefines.h"
28   	#include "soplex/spxout.h"
29   	
30   	namespace soplex
31   	{
32   	
33   	template <class R>
34   	void SPxAutoPR<R>::load(SPxSolverBase<R>* p_solver)
35   	{
36   	   steep.load(p_solver);
37   	   devex.load(p_solver);
38   	   this->thesolver = p_solver;
39   	   setType(p_solver->type());
40   	}
41   	
42   	template <class R>
43   	void SPxAutoPR<R>::clear()
44   	{
45   	   steep.clear();
46   	   devex.clear();
47   	   this->thesolver = nullptr;
48   	}
49   	
50   	template <class R>
51   	void SPxAutoPR<R>::setPricingTolerance(R tol)
52   	{
53   	   steep.setPricingTolerance(tol);
54   	   devex.setPricingTolerance(tol);
55   	   this->thetolerance = tol;
56   	}
57   	
58   	template <class R>
59   	void SPxAutoPR<R>::setType(typename SPxSolverBase<R>::Type tp)
60   	{
61   	   activepricer->setType(tp);
62   	}
63   	
64   	template <class R>
65   	void SPxAutoPR<R>::setRep(typename SPxSolverBase<R>::Representation rep)
66   	{
67   	   steep.setRep(rep);
68   	   devex.setRep(rep);
69   	}
70   	
71   	template <class R>
72   	bool SPxAutoPR<R>::setActivePricer(typename SPxSolverBase<R>::Type type)
73   	{
74   	   // switch to steep as soon as switchIters is reached
75   	   if(activepricer == &devex && this->thesolver->iterations() >= switchIters)
76   	   {
77   	      activepricer = &steep;
78   	      activepricer->setType(type);
79   	      return true;
80   	   }
81   	
82   	
83   	   // use devex for the iterations < switchIters
84   	   else if(activepricer == &steep && this->thesolver->iterations() < switchIters)
85   	   {
86   	      activepricer = &devex;
87   	      activepricer->setType(type);
88   	      return true;
89   	   }
90   	
91   	   return false;
92   	}
93   	
94   	template <class R>
95   	int SPxAutoPR<R>::selectLeave()
96   	{
97   	   if(setActivePricer(SPxSolverBase<R>::LEAVE))
98   	      SPX_MSG_INFO1((*this->thesolver->spxout),
99   	                    (*this->thesolver->spxout) << " --- active pricer: " << activepricer->getName() << std::endl;)
100  	
101  	      return activepricer->selectLeave();
102  	}
103  	
104  	template <class R>
105  	void SPxAutoPR<R>::left4(int n, SPxId id)
106  	{
107  	   activepricer->left4(n, id);
108  	}
109  	
110  	template <class R>
111  	SPxId SPxAutoPR<R>::selectEnter()
112  	{
113  	   if(setActivePricer(SPxSolverBase<R>::ENTER))
114  	      SPX_MSG_INFO1((*this->thesolver->spxout),
115  	                    (*this->thesolver->spxout) << " --- active pricer: " << activepricer->getName() << std::endl;)
116  	
117  	      return activepricer->selectEnter();
118  	}
119  	
120  	template <class R>
121  	void SPxAutoPR<R>::entered4(SPxId id, int n)
122  	{
123  	   activepricer->entered4(id, n);
124  	}
125  	
126  	} // namespace soplex
127