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 lpcolbase.h 26 * @brief LP column. 27 */ 28 #ifndef _LPCOLBASE_H_ 29 #define _LPCOLBASE_H_ 30 31 #include <assert.h> 32 33 #include "soplex/spxdefines.h" 34 #include "soplex/basevectors.h" 35 36 namespace soplex 37 { 38 /**@brief LP column. 39 * @ingroup Algo 40 * 41 * Class LPColBase provides a datatype for storing the column of an LP a the form similar to 42 * \f[ 43 * \begin{array}{rl} 44 * \hbox{max} & c^T x \\ 45 * \hbox{s.t.} & Ax \le b \\ 46 * & l \le x \le u 47 * \end{array} 48 * \f] 49 * Hence, an LPColBase consists of an objective value, a column DSVector and an upper and lower bound to the corresponding 50 * variable, which may include \f$\pm\infty\f$. However, it depends on the LP code to use, what values are actually 51 * treated as \f$\infty\f$. 52 */ 53 template < class R > 54 class LPColBase 55 { 56 template < class S > friend class LPColBase; 57 58 private: 59 60 // ------------------------------------------------------------------------------------------------------------------ 61 /**@name Data */ 62 ///@{ 63 64 R up; ///< upper bound 65 R low; ///< lower bound 66 R object; ///< objective value 67 DSVectorBase<R> vec; ///< the column vector 68 69 ///@} 70 71 public: 72 73 // ------------------------------------------------------------------------------------------------------------------ 74 /**@name Construction / destruction */ 75 ///@{ 76 77 /// Default constructor. 78 /** Construct LPColBase with a column vector ready for taking \p defDim nonzeros. 79 */ 80 explicit LPColBase(int defDim = 0) 81 : up(R(infinity)), low(0), object(0), vec(defDim) 82 { 83 assert(isConsistent()); 84 } 85 86 /// Initializing constructor. 87 /* Construct LPColBase with the given objective value \p obj, a column %vector \p vec, upper bound \p upper and 88 * lower bound \p lower. 89 */ 90 LPColBase(const R& p_obj, const SVectorBase<R>& p_vector, const R& p_upper, const R& p_lower) 91 : up(p_upper), low(p_lower), object(p_obj), vec(p_vector) 92 { 93 assert(isConsistent()); 94 } 95 96 /// Assignment operator. 97 LPColBase<R>& operator=(const LPColBase<R>& old) 98 { 99 if(this != &old) 100 { 101 up = old.up; 102 low = old.low; 103 object = old.object; 104 vec = old.vec; 105 } 106 107 assert(isConsistent()); 108 } 109 110 /// Copy constructor. 111 LPColBase(const LPColBase<R>& old) 112 : up(old.up), low(old.low), object(old.object), vec(old.vec) 113 { 114 assert(isConsistent()); 115 } 116 117 /// Copy constructor. 118 template < class S > 119 LPColBase(const LPColBase<S>& old) 120 : up(old.up), low(old.low), object(old.object), vec(old.vec) 121 { 122 assert(isConsistent()); 123 } 124 125 /// Destructor. 126 ~LPColBase() 127 {} 128 129 ///@} 130 131 // ------------------------------------------------------------------------------------------------------------------ 132 /**@name Access / modification */ 133 ///@{ 134 135 /// Gets objective value. 136 R obj() const 137 { 138 return object; 139 } 140 141 /// Sets objective value. 142 void setObj(const R& p_object) 143 { 144 object = p_object; 145 } 146 147 /// Gets upper bound. 148 R upper() const 149 { 150 return up; 151 } 152 153 /// Sets upper bound. 154 void setUpper(const R& p_up) 155 { 156 up = p_up; 157 } 158 159 /// Gets lower bound. 160 R lower() const 161 { 162 return low; 163 } 164 /// Sets lower bound. 165 void setLower(const R& p_low) 166 { 167 low = p_low; 168 } 169 170 /// Gets constraint column vector. 171 const SVectorBase<R>& colVector() const 172 { 173 return vec; 174 } 175 176 /// Sets constraint column vector. 177 void setColVector(const SVectorBase<R>& p_vec) 178 { 179 vec = p_vec; 180 } 181 182 ///@} 183 184 // ------------------------------------------------------------------------------------------------------------------ 185 /**@name Consistency check */ 186 ///@{ 187 188 /// Checks consistency. 189 bool isConsistent() const 190 { 191 #ifdef ENABLE_CONSISTENCY_CHECKS 192 return vec.isConsistent(); 193 #else 194 return true; 195 #endif 196 } 197 198 ///@} 199 }; 200 } // namespace soplex 201 #endif // _LPCOLBASE_H_ 202