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/vector.h" 29 30 namespace soplex 31 { 32 33 template <class R> 34 void SPxSumST<R>::setupWeights(SPxSolverBase<R>& base) 35 { 36 int count; 37 int i; 38 R x; 39 VectorBase<R> work, delta, rowLen; 40 41 assert(base.nRows() > 0); 42 assert(base.nCols() > 0); 43 44 rowLen.reDim(base.nRows(), true); 45 work.reDim(base.nCols(), true); 46 delta.reDim(base.nCols(), true); 47 48 R* wrk = work.get_ptr(); 49 const R* lhs = base.lhs().get_const_ptr(); 50 const R* rhs = base.rhs().get_const_ptr(); 51 const R* up = base.upper().get_const_ptr(); 52 const R* low = base.lower().get_const_ptr(); 53 54 for(i = base.nRows(); --i >= 0;) 55 { 56 rowLen[i] = base.rowVector(i).length2(); 57 58 if(lhs[i] > 0) 59 delta.multAdd(lhs[i] / rowLen[i], base.rowVector(i)); 60 else if(rhs[i] < 0) 61 delta.multAdd(rhs[i] / rowLen[i], base.rowVector(i)); 62 } 63 64 for(count = 0;; count++) 65 { 66 work += delta; 67 68 for(i = base.nCols(); --i >= 0;) 69 { 70 if(wrk[i] > up[i]) 71 wrk[i] = up[i]; 72 73 if(wrk[i] < low[i]) 74 wrk[i] = low[i]; 75 } 76 77 // std::cout << -(work * base.maxObj()) << std::endl; 78 if(count >= 12) 79 break; 80 81 delta.clear(); 82 83 for(i = base.nRows(); --i >= 0;) 84 { 85 x = base.rowVector(i) * work; 86 87 if(lhs[i] > x) 88 delta.multAdd((lhs[i] - x) / rowLen[i], base.rowVector(i)); 89 else if(rhs[i] < x) 90 delta.multAdd((rhs[i] - x) / rowLen[i], base.rowVector(i)); 91 } 92 } 93 94 this->primal(work); 95 SPxVectorST<R>::setupWeights(base); 96 } 97 } // namespace soplex 98