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 <assert.h>
26   	#include <iostream>
27   	
28   	#include "soplex/spxdefines.h"
29   	
30   	namespace soplex
31   	{
32   	
33   	template <class R>
34   	void SPxVectorST<R>::setupWeights(SPxSolverBase<R>& base)
35   	{
36   	   if(state == PVEC)
37   	   {
38   	      if(vec.dim() != base.nCols())
39   	      {
40   	         SPxWeightST<R>::setupWeights(base);
41   	         return;
42   	      }
43   	
44   	      const VectorBase<R>& obj = base.maxObj();
45   	      R eps = base.epsilon();
46   	      R bias = 10000 * eps;
47   	      R x, y;
48   	      int i;
49   	
50   	      SPxOut::debug(this, "DVECST01 colWeight[]: ");
51   	
52   	      for(i = base.nCols(); i--;)
53   	      {
54   	         x = vec[i] - base.SPxLPBase<R>::lower(i);
55   	         y = base.SPxLPBase<R>::upper(i) - vec[i];
56   	
57   	         if(x < y)
58   	         {
59   	            this->colWeight[i] = -x - bias * obj[i];
60   	            this->colUp[i] = 0;
61   	         }
62   	         else
63   	         {
64   	            this->colWeight[i] = -y + bias * obj[i];
65   	            this->colUp[i] = 1;
66   	         }
67   	
68   	         SPxOut::debug(this, "{} ", this->colWeight[i]);
69   	      }
70   	
71   	      SPxOut::debug(this, "\n \n");
72   	
73   	      SPxOut::debug(this, "DVECST02 rowWeight[]: ");
74   	
75   	      for(i = base.nRows(); i--;)
76   	      {
77   	         const SVectorBase<R>& row = base.rowVector(i);
78   	         y = vec * row;
79   	         x = (y - base.lhs(i));
80   	         y = (base.rhs(i) - y);
81   	
82   	         if(x < y)
83   	         {
84   	            this->rowWeight[i] = -x - eps * row.size() - bias * (obj * row);
85   	            this->rowRight[i] = 0;
86   	         }
87   	         else
88   	         {
89   	            this->rowWeight[i] = -y - eps * row.size() + bias * (obj * row);
90   	            this->rowRight[i] = 1;
91   	         }
92   	
93   	         SPxOut::debug(this, "{} ", this->rowWeight[i]);
94   	      }
95   	
96   	      SPxOut::debug(this, "\n");
97   	   }
98   	
99   	   else if(state == DVEC)
100  	   {
101  	      if(vec.dim() != base.nRows())
102  	      {
103  	         SPxWeightST<R>::setupWeights(base);
104  	         return;
105  	      }
106  	
107  	      R x, y, len;
108  	      int i, j;
109  	
110  	      for(i = base.nRows(); i--;)
111  	         this->rowWeight[i] += spxAbs(vec[i]);
112  	
113  	      for(i = base.nCols(); i--;)
114  	      {
115  	         const SVectorBase<R>& col = base.colVector(i);
116  	
117  	         for(y = len = 0, j = col.size(); j--;)
118  	         {
119  	            x = col.value(j);
120  	            y += vec[col.index(j)] * x;
121  	            len += x * x;
122  	         }
123  	
124  	         if(len > 0)
125  	            this->colWeight[i] += spxAbs(y / len - base.maxObj(i));
126  	      }
127  	   }
128  	   else
129  	      SPxWeightST<R>::setupWeights(base);
130  	}
131  	} // namespace soplex
132