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  spxvectorst.h
26   	 * @brief Solution vector based start basis.
27   	 */
28   	#ifndef _SPXVECTORST_H_
29   	#define _SPXVECTORST_H_
30   	
31   	#include <assert.h>
32   	
33   	#include "soplex/spxweightst.h"
34   	#include "soplex/vector.h"
35   	
36   	namespace soplex
37   	{
38   	
39   	/**@brief   Solution vector based start basis.
40   	   @ingroup Algo
41   	
42   	   This version of SPxWeightST can be used to construct a starting basis for
43   	   an LP to be solved with SoPlex if an approximate solution vector or dual
44   	   vector (possibly optained by a heuristic) is available. This is done by
45   	   setting up weights for the SPxWeightST it is derived from.
46   	
47   	   The primal vector to be used is loaded by calling method #primal() while
48   	   #dual() setups for the dual vector. Methods #primal() or #dual() must be
49   	   called \em before #generate() is called by SoPlex to set up a
50   	   starting basis. If more than one call of method #primal() or #dual()
51   	   occurred only the most recent one is valid for generating the starting base.
52   	*/
53   	template <class R>
54   	class SPxVectorST : public SPxWeightST<R>
55   	{
56   	private:
57   	
58   	   //-------------------------------------
59   	   /**@name Types */
60   	   ///@{
61   	   /// specifies whether to work on the primal, the dual, or not at all.
62   	   enum { NONE, PVEC, DVEC } state;
63   	   ///@}
64   	
65   	   //-------------------------------------
66   	   /**@name Data */
67   	   ///@{
68   	   /// the current (approximate) primal or dual vector
69   	   VectorBase<R> vec;
70   	   ///@}
71   	
72   	protected:
73   	
74   	   //-------------------------------------
75   	   /**@name Protected helpers */
76   	   ///@{
77   	   /// sets up variable weights.
78   	   void setupWeights(SPxSolverBase<R>& base);
79   	   ///@}
80   	
81   	public:
82   	
83   	   //-------------------------------------
84   	   /**@name Construction / destruction */
85   	   ///@{
86   	   /// default constructor.
87   	   SPxVectorST()
88   	      : state(NONE)
89   	   {
90   	      this->m_name = "vector";
91   	   }
92   	   /// copy constructor
93   	   SPxVectorST(const SPxVectorST& old)
94   	      : SPxWeightST<R>(old)
95   	      , state(old.state)
96   	      , vec(old.vec)
97   	   {
98   	      assert(this->isConsistent());
99   	   }
100  	   /// assignment operator
101  	   SPxVectorST& operator=(const SPxVectorST& rhs)
102  	   {
103  	      if(this != &rhs)
104  	      {
105  	         SPxWeightST<R>::operator=(rhs);
106  	         state = rhs.state;
107  	         vec = rhs.vec;
108  	
109  	         assert(this->isConsistent());
110  	      }
111  	
112  	      return *this;
113  	   }
114  	   /// destructor.
115  	   virtual ~SPxVectorST()
116  	   {}
117  	   /// clone function for polymorphism
118  	   inline virtual SPxStarter<R>* clone() const
119  	   {
120  	      return new SPxVectorST(*this);
121  	   }
122  	   ///@}
123  	
124  	   //-------------------------------------
125  	   /**@name Modification */
126  	   ///@{
127  	   /// sets up primal solution vector.
128  	   void primal(const VectorBase<R>& v)
129  	   {
130  	      vec = v;
131  	      state = PVEC;
132  	   }
133  	   /// sets up primal solution vector.
134  	   void dual(const VectorBase<R>& v)
135  	   {
136  	      vec = v;
137  	      state = DVEC;
138  	   }
139  	   ///@}
140  	
141  	};
142  	
143  	} // namespace soplex
144  	
145  	// For general templated files
146  	#include "spxvectorst.hpp"
147  	#endif // _SPXVECTORST_H_
148