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/spxsolver.h" 29 30 namespace soplex 31 { 32 33 template <class R> 34 SPxBasisBase<R>::Desc::Desc(const SPxSolverBase<R>& base) 35 { 36 reSize(base.nRows(), base.nCols()); 37 38 if(base.rep() == SPxSolverBase<R>::ROW) 39 { 40 stat = &rowstat; 41 costat = &colstat; 42 } 43 else 44 { 45 assert(base.rep() == SPxSolverBase<R>::COLUMN); 46 47 stat = &colstat; 48 costat = &rowstat; 49 } 50 51 assert(Desc::isConsistent()); 52 } 53 54 template <class R> 55 SPxBasisBase<R>::Desc::Desc(const Desc& old) 56 : rowstat(old.rowstat) 57 , colstat(old.colstat) 58 { 59 if(old.stat == &old.rowstat) 60 { 61 assert(old.costat == &old.colstat); 62 63 stat = &rowstat; 64 costat = &colstat; 65 } 66 else 67 { 68 assert(old.costat == &old.rowstat); 69 70 stat = &colstat; 71 costat = &rowstat; 72 } 73 74 assert(Desc::isConsistent()); 75 } 76 77 template <class R> 78 typename SPxBasisBase<R>::Desc& SPxBasisBase<R>::Desc::operator=(const typename 79 SPxBasisBase<R>::Desc& rhs) 80 { 81 if(this != &rhs) 82 { 83 rowstat = rhs.rowstat; 84 colstat = rhs.colstat; 85 86 if(rhs.stat == &rhs.rowstat) 87 { 88 assert(rhs.costat == &rhs.colstat); 89 90 stat = &rowstat; 91 costat = &colstat; 92 } 93 else 94 { 95 assert(rhs.costat == &rhs.rowstat); 96 97 stat = &colstat; 98 costat = &rowstat; 99 } 100 101 assert(Desc::isConsistent()); 102 } 103 104 return *this; 105 } 106 107 template <class R> 108 void SPxBasisBase<R>::Desc::reSize(int rowDim, int colDim) 109 { 110 111 assert(rowDim >= 0); 112 assert(colDim >= 0); 113 114 int noldrows = rowstat.size(); 115 int noldcols = colstat.size(); 116 117 rowstat.reSize(rowDim); 118 colstat.reSize(colDim); 119 120 for(int i = rowDim - 1; i >= noldrows; i--) 121 rowstat[i] = D_UNDEFINED; 122 123 for(int i = colDim - 1; i >= noldcols; i--) 124 colstat[i] = D_UNDEFINED; 125 } 126 127 template <class R> 128 void SPxBasisBase<R>::Desc::dump() const 129 { 130 int i; 131 132 // Dump regardless of the verbosity level if this method is called. 133 134 std::cout << "DBDESC01 column status: "; 135 136 for(i = 0; i < nCols(); i++) 137 std::cout << static_cast<int>(colStatus(i)); 138 139 std::cout << std::endl; 140 141 std::cout << "DBDESC02 row status: "; 142 143 for(i = 0; i < nRows(); i++) 144 std::cout << static_cast<int>(rowStatus(i)); 145 146 std::cout << std::endl; 147 } 148 149 template <class R> 150 bool SPxBasisBase<R>::Desc::isConsistent() const 151 { 152 #ifdef ENABLE_CONSISTENCY_CHECKS 153 return rowstat.isConsistent() && colstat.isConsistent(); 154 #else 155 return true; 156 #endif 157 } 158 159 template <class R> 160 std::ostream& operator<<(std::ostream& os, const typename SPxBasisBase<R>::Desc::Status& stat) 161 { 162 char text; 163 164 switch(stat) 165 { 166 case SPxBasisBase<R>::Desc::P_ON_LOWER : 167 text = 'L'; 168 break; 169 170 case SPxBasisBase<R>::Desc::P_ON_UPPER : 171 text = 'U'; 172 break; 173 174 case SPxBasisBase<R>::Desc::P_FREE : 175 text = 'F'; 176 break; 177 178 case SPxBasisBase<R>::Desc::P_FIXED : 179 text = 'X'; 180 break; 181 182 case SPxBasisBase<R>::Desc::D_FREE : 183 text = 'f'; 184 break; 185 186 case SPxBasisBase<R>::Desc::D_ON_UPPER : 187 text = 'u'; 188 break; 189 190 case SPxBasisBase<R>::Desc::D_ON_LOWER : 191 text = 'l'; 192 break; 193 194 case SPxBasisBase<R>::Desc::D_ON_BOTH : 195 text = 'x'; 196 break; 197 198 case SPxBasisBase<R>::Desc::D_UNDEFINED : 199 text = '.'; 200 break; 201 202 default : 203 os << std::endl << "Invalid status <" << int(stat) << ">" << std::endl; 204 throw SPxInternalCodeException("XSPXDE01 This should never happen."); 205 } 206 207 os << text; 208 209 return os; 210 } 211 212 } // namespace soplex 213