1 /** \file
2  * \brief Declaration of basic page rank.
3  *
4  * \author Martin Gronemann
5  *
6  * \par License:
7  * This file is part of the Open Graph Drawing Framework (OGDF).
8  *
9  * \par
10  * Copyright (C)<br>
11  * See README.md in the OGDF root directory for details.
12  *
13  * \par
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * Version 2 or 3 as published by the Free Software Foundation;
17  * see the file LICENSE.txt included in the packaging of this file
18  * for details.
19  *
20  * \par
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * \par
27  * You should have received a copy of the GNU General Public
28  * License along with this program; if not, see
29  * http://www.gnu.org/copyleft/gpl.html
30  */
31 
32 #pragma once
33 
34 #include <ogdf/basic/NodeArray.h>
35 #include <ogdf/basic/EdgeArray.h>
36 
37 namespace ogdf {
38 
39 //! Basic page rank calculation.
40 /**
41  * @ingroup graph-algs
42  */
43 class BasicPageRank
44 {
45 public:
BasicPageRank()46 	BasicPageRank()
47 	{
48 		initDefaultOptions();
49 	}
50 
51 	//! main algorithm call
52 	void call(
53 		const Graph& graph,
54 		const EdgeArray<double>& edgeWeight,
55 		NodeArray<double>& pageRankResult);
56 
57 	//! sets the default options.
initDefaultOptions()58 	void initDefaultOptions()
59 	{
60 		m_dampingFactor		= 0.85;
61 		m_maxNumIterations	= 1000;
62 		m_threshold			= 0.0;
63 	}
64 
65 	//! returns the damping factor for each iteration (default is 0.85)
dampingFactor()66 	double dampingFactor() const
67 	{
68 		return m_dampingFactor;
69 	}
70 
71 	//! sets the damping factor for each iteration (default is 0.85)
setDampingFactor(double dampingFactor)72 	void setDampingFactor(double dampingFactor)
73 	{
74 		m_dampingFactor = dampingFactor;
75 	}
76 
77 	//! the maximum number of iterations (default is 1000)
maxNumIterations()78 	int maxNumIterations() const
79 	{
80 		return m_maxNumIterations;
81 	}
82 
83 	//! sets the maximum number of iterations (default is 1000)
setMaxNumIterations(int maxNumIterations)84 	void setMaxNumIterations(int maxNumIterations)
85 	{
86 		m_maxNumIterations = maxNumIterations;
87 	}
88 
89 	/*! returns the threshold/epsilon. After each iteration the result is compared to
90 	 * to the old one and in case all changes are smaller than threshold the algorithm
91 	 * stops. Note that the default value is 0.0 resulting in maxNumIterations usually.
92 	 */
threshold()93 	double threshold() const
94 	{
95 		return m_threshold;
96 	}
97 
98 
99 	//! sets the threshold to t. See threshold for more information
setThreshold(double t)100 	void setThreshold(double t)
101 	{
102 		m_threshold = t;
103 	}
104 
105 private:
106 	//! the damping factor
107 	double m_dampingFactor;
108 
109 	//! maximum number of iterations
110 	int m_maxNumIterations;
111 
112 	//! the threshold
113 	double m_threshold;
114 };
115 
116 }
117