1    	/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2    	/*                                                                           */
3    	/*                  This file is part of the class library                   */
4    	/*       SoPlex --- the Sequential object-oriented simPlex.                  */
5    	/*                                                                           */
6    	/*    Copyright (C) 1996-2022 Konrad-Zuse-Zentrum                            */
7    	/*                            fuer Informationstechnik Berlin                */
8    	/*                                                                           */
9    	/*  SoPlex is distributed under the terms of the ZIB Academic Licence.       */
10   	/*                                                                           */
11   	/*  You should have received a copy of the ZIB Academic License              */
12   	/*  along with SoPlex; see the file COPYING. If not email to soplex@zib.de.  */
13   	/*                                                                           */
14   	/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15   	
16   	#include <iostream>
17   	#include <assert.h>
18   	
(1) Event include_recursion: #include file "/sapmnt/home1/d029903/my_work/SCIPSoPlex_coverity/scipoptsuite-8.0.1/soplex/src/soplex/statistics.h" includes itself: statistics.h -> statistics.hpp -> statistics.h
(2) Event caretline: ^
19   	#include "soplex/statistics.h"
20   	#include "soplex/timerfactory.h"
21   	
22   	namespace soplex
23   	{
24   	/// default constructor
25   	template <class R>
26   	SoPlexBase<R>::Statistics::Statistics(Timer::TYPE ttype)
27   	{
28   	   timerType = ttype;
29   	   readingTime = TimerFactory::createTimer(timerType);
30   	   solvingTime = TimerFactory::createTimer(timerType);
31   	   preprocessingTime = TimerFactory::createTimer(timerType);
32   	   simplexTime = TimerFactory::createTimer(timerType);
33   	   syncTime = TimerFactory::createTimer(timerType);
34   	   transformTime = TimerFactory::createTimer(timerType);
35   	   rationalTime = TimerFactory::createTimer(timerType);
36   	   reconstructionTime = TimerFactory::createTimer(timerType);
37   	   clearAllData();
38   	}
39   	
40   	/// copy constructor
41   	template <class R>
42   	SoPlexBase<R>::Statistics::Statistics(const Statistics& base)
43   	{
44   	   timerType = base.timerType;
45   	   readingTime = TimerFactory::createTimer(timerType);
46   	   solvingTime = TimerFactory::createTimer(timerType);
47   	   preprocessingTime = TimerFactory::createTimer(timerType);
48   	   simplexTime = TimerFactory::createTimer(timerType);
49   	   syncTime = TimerFactory::createTimer(timerType);
50   	   transformTime = TimerFactory::createTimer(timerType);
51   	   rationalTime = TimerFactory::createTimer(timerType);
52   	   reconstructionTime = TimerFactory::createTimer(timerType);
53   	   clearAllData();
54   	}
55   	
56   	/// assignment operator
57   	template <class R>
58   	typename SoPlexBase<R>::Statistics& SoPlexBase<R>::Statistics::operator=(const Statistics& rhs)
59   	{
60   	   *readingTime = *(rhs.readingTime);
61   	   *solvingTime = *(rhs.solvingTime);
62   	   *preprocessingTime = *(rhs.preprocessingTime);
63   	   *simplexTime = *(rhs.simplexTime);
64   	   *syncTime = *(rhs.syncTime);
65   	   *transformTime = *(rhs.transformTime);
66   	   *rationalTime = *(rhs.rationalTime);
67   	   *reconstructionTime = *(rhs.reconstructionTime);
68   	   timerType = rhs.timerType;
69   	   multTimeSparse = rhs.multTimeSparse;
70   	   multTimeFull = rhs.multTimeFull;
71   	   multTimeColwise = rhs.multTimeColwise;
72   	   multTimeUnsetup = rhs.multTimeUnsetup;
73   	   multSparseCalls = rhs.multSparseCalls;
74   	   multFullCalls = rhs.multFullCalls;
75   	   multColwiseCalls = rhs.multColwiseCalls;
76   	   multUnsetupCalls = rhs.multUnsetupCalls;
77   	   luFactorizationTimeReal = rhs.luFactorizationTimeReal;
78   	   luSolveTimeReal = rhs.luSolveTimeReal;
79   	   luFactorizationTimeRational = rhs.luFactorizationTimeRational;
80   	   luSolveTimeRational = rhs.luSolveTimeRational;
81   	   iterations = rhs.iterations;
82   	   iterationsPrimal = rhs.iterationsPrimal;
83   	   iterationsFromBasis = rhs.iterationsFromBasis;
84   	   boundflips = rhs.boundflips;
85   	   luFactorizationsReal = rhs.luFactorizationsReal;
86   	   luSolvesReal = rhs.luSolvesReal;
87   	   luFactorizationsRational = rhs.luFactorizationsRational;
88   	   rationalReconstructions = rhs.rationalReconstructions;
89   	   refinements = rhs.refinements;
90   	   stallRefinements = rhs.stallRefinements;
91   	   pivotRefinements = rhs.pivotRefinements;
92   	   feasRefinements = rhs.feasRefinements;
93   	   unbdRefinements = rhs.unbdRefinements;
94   	
95   	   return *this;
96   	}
97   	
98   	/// clears all statistics
99   	template <class R>
100  	void SoPlexBase<R>::Statistics::clearAllData()
101  	{
102  	   readingTime->reset();
103  	   clearSolvingData();
104  	}
105  	
106  	/// clears statistics on solving process
107  	template <class R>
108  	void SoPlexBase<R>::Statistics::clearSolvingData()
109  	{
110  	   solvingTime->reset();
111  	   preprocessingTime->reset();
112  	   simplexTime->reset();
113  	   syncTime->reset();
114  	   transformTime->reset();
115  	   rationalTime->reset();
116  	   reconstructionTime->reset();
117  	   multTimeSparse = 0.0;
118  	   multTimeFull = 0.0;
119  	   multTimeColwise = 0.0;
120  	   multTimeUnsetup = 0.0;
121  	   multSparseCalls = 0;
122  	   multFullCalls = 0;
123  	   multColwiseCalls = 0;
124  	   multUnsetupCalls = 0;
125  	   luFactorizationTimeReal = 0.0;
126  	   luSolveTimeReal = 0.0;
127  	   luFactorizationTimeRational = 0.0;
128  	   luSolveTimeRational = 0.0;
129  	   iterations = 0;
130  	   iterationsPrimal = 0;
131  	   iterationsFromBasis = 0;
132  	   iterationsPolish = 0;
133  	   boundflips = 0;
134  	   luFactorizationsReal = 0;
135  	   luSolvesReal = 0;
136  	   luFactorizationsRational = 0;
137  	   rationalReconstructions = 0;
138  	   refinements = 0;
139  	   stallRefinements = 0;
140  	   pivotRefinements = 0;
141  	   feasRefinements = 0;
142  	   unbdRefinements = 0;
143  	
144  	   callsReducedProb = 0;
145  	   iterationsInit = 0;
146  	   iterationsRedProb = 0;
147  	   iterationsCompProb = 0;
148  	   numRedProbRows = 0;
149  	   numRedProbCols = 0;
150  	   degenPivotsPrimal = 0;
151  	   degenPivotsDual = 0;
152  	   degenPivotCandPrimal = 0;
153  	   degenPivotCandDual = 0;
154  	   sumDualDegen = 0;
155  	   sumPrimalDegen = 0;
156  	   decompBasisCondNum = 0;
157  	   totalBoundViol = 0;
158  	   totalRowViol = 0;
159  	   maxBoundViol = 0;
160  	   maxRowViol = 0;
161  	   redProbStatus = 0;
162  	   compProbStatus = 0;
163  	   finalCompObj = 0;
164  	   finalBasisCondition = 0;
165  	}
166  	
167  	/// prints statistics
168  	template <class R>
169  	void SoPlexBase<R>::Statistics::print(std::ostream& os)
170  	{
171  	   Real solTime = solvingTime->time();
172  	   Real totTime = readingTime->time() + solTime;
173  	   Real otherTime = solTime - syncTime->time() - transformTime->time() - preprocessingTime->time() -
174  	                    simplexTime->time() - rationalTime->time();
175  	
176  	   R avgPrimalDegeneracy = iterationsPrimal > 0 ? sumPrimalDegen / iterationsPrimal : 0.0;
177  	   R avgDualDegeneracy = (iterations - iterationsPrimal) > 0 ?
178  	                         (sumDualDegen / (iterations - iterationsPrimal)) : 0.0;
179  	
180  	   SPxOut::setFixed(os, 2);
181  	
182  	   os << "Total time          : " << totTime << "\n"
183  	      << "  Reading           : " << readingTime->time() << "\n"
184  	      << "  Solving           : " << solTime << "\n"
185  	      << "  Preprocessing     : " << preprocessingTime->time();
186  	
187  	   if(solTime > 0)
188  	      os << " (" << 100 * (preprocessingTime->time() / solTime) << "% of solving time)";
189  	
190  	   os << "\n  Simplex           : " << simplexTime->time();
191  	
192  	   if(solTime > 0)
193  	      os << " (" << 100 * (simplexTime->time() / solTime) << "% of solving time)";
194  	
195  	   os << "\n  Synchronization   : " << syncTime->time();
196  	
197  	   if(solTime > 0)
198  	      os << " (" << 100 * (syncTime->time() / solTime) << "% of solving time)";
199  	
200  	   os << "\n  Transformation    : " << transformTime->time();
201  	
202  	   if(solTime > 0)
203  	      os << " (" << 100 * transformTime->time() / solTime << "% of solving time)";
204  	
205  	   os << "\n  Rational          : " << rationalTime->time();
206  	
207  	   if(solTime > 0)
208  	      os << " (" << 100 * rationalTime->time() / solTime << "% of solving time)";
209  	
210  	   os << "\n  Other             : " << otherTime;
211  	
212  	   if(solTime > 0)
213  	      os << " (" << 100 * otherTime / solTime << "% of solving time)";
214  	
215  	   os << "\nRefinements         : " << refinements << "\n"
216  	      << "  Stalling          : " << stallRefinements << "\n"
217  	      << "  Pivoting          : " << pivotRefinements << "\n"
218  	      << "  Feasibility       : " << feasRefinements << "\n"
219  	      << "  Unboundedness     : " << unbdRefinements << "\n";
220  	
221  	   os << "Iterations          : " << iterations << "\n"
222  	      << "  From scratch      : " << iterations - iterationsFromBasis;
223  	
224  	   if(iterations > 0)
225  	      os << " (" << 100 * double((iterations - iterationsFromBasis)) / double(iterations) << "%)";
226  	
227  	   os << "\n  From basis        : " << iterationsFromBasis;
228  	
229  	   if(iterations > 0)
230  	      os << " (" << 100 * double(iterationsFromBasis) / double(iterations) << "%)";
231  	
232  	   os << "\n  Primal            : " << iterationsPrimal;
233  	
234  	   if(iterations > 0)
235  	      os << " (" << 100 * double(iterationsPrimal) / double(iterations) << "%)";
236  	
237  	   os << "\n  Dual              : " << iterations - iterationsPrimal - iterationsPolish;
238  	
239  	   if(iterations > 0)
240  	      os << " (" << 100 * double((iterations - iterationsPrimal)) / double(iterations) << "%)";
241  	
242  	   os << "\n  Bound flips       : " << boundflips;
243  	   os << "\n  Sol. polishing    : " << iterationsPolish;
244  	
245  	   os << "\nLU factorizations   : " << luFactorizationsReal << "\n"
246  	      << "  Factor. frequency : ";
247  	
248  	   if(luFactorizationsReal > 0)
249  	      os << double(iterations) / double(luFactorizationsReal) << " iterations per factorization\n";
250  	   else
251  	      os << "-\n";
252  	
253  	   os << "  Factor. time      : " << luFactorizationTimeReal << "\n";
254  	
255  	   os << "LU solves           : " << luSolvesReal << "\n"
256  	      << "  Solve frequency   : ";
257  	
258  	   if(iterations > 0)
259  	      os << double(luSolvesReal) / double(iterations) << " solves per iteration\n";
260  	   else
261  	      os << "-\n";
262  	
263  	   os << "  Solve time        : " << luSolveTimeReal << "\n";
264  	
265  	   os << "Matrix-Vector ops   : \n"
266  	      << "  Sparse    time    : " << multTimeSparse;
267  	
268  	   if(solTime > 0)
269  	      os << " (" << 100 * (multTimeSparse / solTime) << "% of solving time)";
270  	
271  	   os << "\n            calls   : " << multSparseCalls;
272  	   os << " (" << 100 * (multSparseCalls / (0.01 + iterations)) << "% of iterations)";
273  	   os << "\n  Full      time    : " << multTimeFull;
274  	
275  	   if(solTime > 0)
276  	      os << " (" << 100 * (multTimeFull / solTime) << "% of solving time)";
277  	
278  	   os << "\n            calls   : " << multFullCalls;
279  	   os << " (" << 100 * (multFullCalls / (0.01 + iterations)) << "% of iterations)";
280  	   os << "\n  Colwise   time    : " << multTimeColwise;
281  	
282  	   if(solTime > 0)
283  	      os << " (" << 100 * (multTimeColwise / solTime) << "% of solving time)";
284  	
285  	   os << "\n            calls   : " << multColwiseCalls;
286  	   os << " (" << 100 * (multColwiseCalls / (0.01 + iterations)) << "% of iterations)";
287  	   os << "\n  Unsetup   time    : " << multTimeUnsetup;
288  	
289  	   if(solTime > 0)
290  	      os << " (" << 100 * (multTimeUnsetup / solTime) << "% of solving time)";
291  	
292  	   os << "\n            calls   : " << multUnsetupCalls;
293  	   os << " (" << 100 * (multUnsetupCalls / (0.01 + iterations)) << "% of iterations)";
294  	   os << "\n";
295  	
296  	   os << "Rat. factorizations : " << luFactorizationsRational << "\n"
297  	      << "  Rat. factor. time : " << luFactorizationTimeRational << "\n"
298  	      << "  Rat. solve time   : " << luSolveTimeRational << "\n";
299  	
300  	   os << "Rat. reconstructions: " << rationalReconstructions << "\n"
301  	      << "  Rat. rec. time    : " << reconstructionTime->time() << "\n";
302  	
303  	   os << "Degeneracy          : \n";
304  	   os << "  Primal Pivots     : " << degenPivotsPrimal << "\n";
305  	   os << "  Dual Pivots       : " << degenPivotsDual << "\n";
306  	   os << "  Primal Candidates : " << degenPivotCandPrimal << "\n";
307  	   os << "  Dual Candidates   : " << degenPivotCandDual << "\n";
308  	   os << "  Average Primal    : " << avgPrimalDegeneracy << "\n";
309  	   os << "  Average Dual      : " << avgDualDegeneracy << "\n";
310  	
311  	   if(iterationsInit > 0)
312  	   {
313  	      os << "Algorithm Iterations: " << callsReducedProb << "\n";
314  	      os << "Decomp. Iterations  : \n";
315  	      os << "  Total             : " << iterationsInit + iterationsRedProb << "\n";
316  	      os << "  Initial           : " << iterationsInit << "\n";
317  	      os << "  Reduced Problem   : " << iterationsRedProb << "\n";
318  	      os << "  Comp. Problem     : " << iterationsCompProb << "\n";
319  	      os << "Red. Problem Size   : \n";
320  	      os << "  Rows              : " << numRedProbRows << "\n";
321  	      os << "  Columns           : " << numRedProbCols << "\n";
322  	
323  	      SPxOut::setScientific(os, 16);
324  	
325  	      os << "Decomp. Basis Cond. : " << decompBasisCondNum << "\n";
326  	      os << "Decomp Violations   : \n";
327  	      os << "  Sum Bound         : " << totalBoundViol << "\n";
328  	      os << "  Sum Row           : " << totalRowViol << "\n";
329  	      os << "  Max Bound         : " << maxBoundViol << "\n";
330  	      os << "  Max Row           : " << maxRowViol << "\n";
331  	
332  	      SPxOut::setFixed(os, 2);
333  	
334  	      os << "Red. Problem Status : " << redProbStatus << "\n";
335  	      os << "Comp. Problem Status: " << compProbStatus << "\n";
336  	
337  	      SPxOut::setScientific(os, 16);
338  	
339  	      os << "Comp. Problem Obj.  : " << finalCompObj << "\n";
340  	   }
341  	
342  	   SPxOut::setScientific(os);
343  	
344  	   os << "Numerics            :\n";
345  	   os << "  Condition Number  : " << finalBasisCondition << "\n";
346  	
347  	}
348  	} // namespace soplex
349