Skip to content

Commit

Permalink
removed deprecated igraph_pagerank_old()
Browse files Browse the repository at this point in the history
  • Loading branch information
ntamas committed Oct 6, 2020
1 parent d2a1c2b commit 6f43b86
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 364 deletions.
1 change: 0 additions & 1 deletion doc/structural.xxml
Expand Up @@ -85,7 +85,6 @@
<!-- doxrox-include igraph_pagerank_algo_t -->
<!-- doxrox-include igraph_pagerank_power_options_t -->
<!-- doxrox-include igraph_pagerank -->
<!-- doxrox-include igraph_pagerank_old -->
<!-- doxrox-include igraph_personalized_pagerank -->
<!-- doxrox-include igraph_personalized_pagerank_vs -->
<!-- doxrox-include igraph_constraint -->
Expand Down
61 changes: 16 additions & 45 deletions examples/simple/igraph_pagerank.c
Expand Up @@ -25,12 +25,6 @@
#include <unistd.h>
#include <libgen.h>

void warning_handler_stdout (const char *reason, const char *file,
int line, int igraph_errno) {
IGRAPH_UNUSED(igraph_errno);
printf("Warning: %s\n", reason);
}

void print_vector(igraph_vector_t *v, FILE *f) {
long int i;
for (i = 0; i < igraph_vector_size(v); i++) {
Expand All @@ -39,16 +33,15 @@ void print_vector(igraph_vector_t *v, FILE *f) {
fprintf(f, "\n");
}

igraph_warning_handler_t *oldwarn;

int main() {

igraph_t g;
igraph_vector_t v, res, reset, weights;
igraph_arpack_options_t arpack_options;
igraph_real_t value;
int ret;
igraph_pagerank_power_options_t power_options;

igraph_arpack_options_init(&arpack_options);

/* Test graphs taken from http://www.iprcom.com/papers/pagerank/ */
igraph_vector_init(&v, 10);
Expand All @@ -65,8 +58,11 @@ int main() {
igraph_create(&g, &v, 0, 1);

igraph_vector_init(&res, 0);
oldwarn = igraph_set_warning_handler(warning_handler_stdout);
igraph_pagerank_old(&g, &res, igraph_vss_all(), 1, 1000, 0.001, 0.85, 0);
igraph_pagerank(&g, IGRAPH_PAGERANK_ALGO_ARPACK, &res, 0,
igraph_vss_all(), 0, 0.85, 0, &arpack_options);
print_vector(&res, stdout);
igraph_pagerank(&g, IGRAPH_PAGERANK_ALGO_PRPACK, &res, 0,
igraph_vss_all(), 0, 0.85, 0, 0);
print_vector(&res, stdout);
igraph_vector_destroy(&res);
igraph_vector_destroy(&v);
Expand Down Expand Up @@ -105,18 +101,19 @@ int main() {
igraph_create(&g, &v, 0, 1);

igraph_vector_init(&res, 0);
igraph_pagerank_old(&g, &res, igraph_vss_all(), 1, 10000, 0.0001, 0.85, 0);
igraph_pagerank(&g, IGRAPH_PAGERANK_ALGO_ARPACK, &res, 0,
igraph_vss_all(), 0, 0.85, 0, &arpack_options);
print_vector(&res, stdout);
igraph_pagerank(&g, IGRAPH_PAGERANK_ALGO_PRPACK, &res, 0,
igraph_vss_all(), 0, 0.85, 0, 0);
print_vector(&res, stdout);
igraph_vector_destroy(&res);
igraph_vector_destroy(&v);
igraph_destroy(&g);

igraph_set_warning_handler(oldwarn);

/* New PageRank */
/* Undirected star graph */
igraph_star(&g, 11, IGRAPH_STAR_UNDIRECTED, 0);
igraph_vector_init(&res, 0);
igraph_arpack_options_init(&arpack_options);
igraph_pagerank(&g, IGRAPH_PAGERANK_ALGO_ARPACK, &res, 0,
igraph_vss_all(), 0, 0.85, 0, &arpack_options);
print_vector(&res, stdout);
Expand Down Expand Up @@ -149,35 +146,6 @@ int main() {
print_vector(&res, stdout);

/* Errors */
power_options.niter = -1;
power_options.eps = 0.0001;
igraph_set_error_handler(igraph_error_handler_ignore);
igraph_set_warning_handler(igraph_warning_handler_ignore);
ret = igraph_pagerank(&g, IGRAPH_PAGERANK_ALGO_POWER, &res,
/*value=*/ 0, igraph_vss_all(), 1, 0.85,
/*weights=*/ 0, &power_options);
if (ret != IGRAPH_EINVAL) {
return 1;
}

power_options.niter = 10000;
power_options.eps = -1;
ret = igraph_pagerank(&g, IGRAPH_PAGERANK_ALGO_POWER, &res,
/*value=*/ 0, igraph_vss_all(), 1, 0.85,
/*weights=*/ 0, &power_options);
if (ret != IGRAPH_EINVAL) {
return 2;
}

power_options.niter = 10000;
power_options.eps = 0.0001;
ret = igraph_pagerank(&g, IGRAPH_PAGERANK_ALGO_POWER, &res,
/*value=*/ 0, igraph_vss_all(), 1, 1.2,
/*weights=*/ 0, &power_options);
if (ret != IGRAPH_EINVAL) {
return 3;
}

igraph_vector_init(&reset, 2);
ret = igraph_personalized_pagerank(&g, IGRAPH_PAGERANK_ALGO_ARPACK, &res, 0,
igraph_vss_all(), 0, 0.85, &reset, 0,
Expand Down Expand Up @@ -263,5 +231,8 @@ int main() {
igraph_destroy(&g);

igraph_vector_destroy(&res);

igraph_arpack_options_destroy(&arpack_options);

return 0;
}
4 changes: 0 additions & 4 deletions examples/simple/igraph_pagerank.out
@@ -1,7 +1,3 @@
Warning: igraph_pagerank_old is deprecated from igraph 0.7, use igraph_pagerank instead
0.37 0.20 0.39 0.04
Warning: igraph_pagerank_old is deprecated from igraph 0.7, use igraph_pagerank instead
0.42 0.14 0.14 0.14 0.04 0.04 0.04 0.04
0.47 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05
0.47 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05
0.47 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05
Expand Down
28 changes: 3 additions & 25 deletions include/igraph_centrality.h
Expand Up @@ -60,18 +60,12 @@ DECLDIR int igraph_edge_betweenness(const igraph_t *graph, igraph_vector_t *resu
DECLDIR int igraph_edge_betweenness_estimate(const igraph_t *graph, igraph_vector_t *result,
igraph_bool_t directed, igraph_real_t cutoff,
const igraph_vector_t *weights);
DECLDIR int igraph_pagerank_old(const igraph_t *graph, igraph_vector_t *res,
const igraph_vs_t vids, igraph_bool_t directed,
igraph_integer_t niter, igraph_real_t eps,
igraph_real_t damping, igraph_bool_t old);

/**
* \typedef igraph_pagerank_algo_t
* \brief PageRank algorithm implementation
*
* Algorithms to calculate PageRank.
* \enumval IGRAPH_PAGERANK_ALGO_POWER Use a simple power iteration,
* as it was implemented before igraph version 0.5.
* \enumval IGRAPH_PAGERANK_ALGO_ARPACK Use the ARPACK library, this
* was the PageRank implementation in igraph from version 0.5, until
* version 0.7.
Expand All @@ -80,44 +74,28 @@ DECLDIR int igraph_pagerank_old(const igraph_t *graph, igraph_vector_t *res,
*/

typedef enum {
IGRAPH_PAGERANK_ALGO_POWER = 0,
IGRAPH_PAGERANK_ALGO_ARPACK = 1,
IGRAPH_PAGERANK_ALGO_PRPACK = 2
} igraph_pagerank_algo_t;

/**
* \struct igraph_pagerank_power_options_t
* \brief Options for the power method
*
* \member niter The number of iterations to perform, integer.
* \member eps The algorithm will consider the calculation as complete
* if the difference of values between iterations change
* less than this value for every vertex.
*/

typedef struct igraph_pagerank_power_options_t {
igraph_integer_t niter;
igraph_real_t eps;
} igraph_pagerank_power_options_t;

DECLDIR int igraph_pagerank(const igraph_t *graph, igraph_pagerank_algo_t algo,
igraph_vector_t *vector,
igraph_real_t *value, const igraph_vs_t vids,
igraph_bool_t directed, igraph_real_t damping,
const igraph_vector_t *weights, void *options);
const igraph_vector_t *weights, igraph_arpack_options_t *options);
DECLDIR int igraph_personalized_pagerank(const igraph_t *graph,
igraph_pagerank_algo_t algo, igraph_vector_t *vector,
igraph_real_t *value, const igraph_vs_t vids,
igraph_bool_t directed, igraph_real_t damping,
igraph_vector_t *reset,
const igraph_vector_t *weights, void *options);
const igraph_vector_t *weights, igraph_arpack_options_t *options);
DECLDIR int igraph_personalized_pagerank_vs(const igraph_t *graph,
igraph_pagerank_algo_t algo,
igraph_vector_t *vector,
igraph_real_t *value, const igraph_vs_t vids,
igraph_bool_t directed, igraph_real_t damping,
igraph_vs_t reset_vids,
const igraph_vector_t *weights, void *options);
const igraph_vector_t *weights, igraph_arpack_options_t *options);

DECLDIR int igraph_eigenvector_centrality(const igraph_t *graph, igraph_vector_t *vector,
igraph_real_t *value,
Expand Down
7 changes: 0 additions & 7 deletions interfaces/functions.def
Expand Up @@ -520,13 +520,6 @@ igraph_edge_betweenness_estimate:
NAME-R: estimate_edge_betweenness
IGNORE: RR

igraph_pagerank_old:
PARAMS: GRAPH graph, OUT VERTEXINDEX res, VERTEXSET vids=ALL, \
BOOLEAN directed=True, INTEGER niter=1000, REAL eps=0.001, \
REAL damping=0.85, BOOLEAN old=False
DEPS: vids ON graph, res ON graph vids
NAME-R: page_rank_old

igraph_pagerank:
PARAMS: GRAPH graph, PAGERANKALGO algo=PRPACK, \
OUT VERTEXINDEX vector, OUT REALPTR value, \
Expand Down
85 changes: 26 additions & 59 deletions src/centrality.c
Expand Up @@ -1052,16 +1052,12 @@ static int igraph_i_pagerank2(igraph_real_t *to, const igraph_real_t *from,
* \function igraph_pagerank
* \brief Calculates the Google PageRank for the specified vertices.
*
* Starting from version 0.7, igraph has three PageRank implementations,
* Starting from version 0.9, igraph has two PageRank implementations,
* and the user can choose between them. The first implementation is
* \c IGRAPH_PAGERANK_ALGO_POWER, also available as the (now
* deprecated) function \ref igraph_pagerank_old(). The second
* implementation is based on the ARPACK library, this was the default
* before igraph version 0.7: \c IGRAPH_PAGERANK_ALGO_ARPACK.
*
* The third and recommmended implementation is \c
* IGRAPH_PAGERANK_ALGO_PRPACK. This is using the the PRPACK package,
* see https://github.com/dgleich/prpack .
* \c IGRAPH_PAGERANK_ALGO_ARPACKK, based on the ARPACK library. This
* was the default before igraph version 0.7. The second and recommended
* implementation is \c IGRAPH_PAGERANK_ALGO_PRPACK. This is using the
* PRPACK package, see https://github.com/dgleich/prpack .
*
* </para><para>
* Please note that the PageRank of a given vertex depends on the PageRank
Expand All @@ -1086,8 +1082,7 @@ static int igraph_i_pagerank2(igraph_real_t *to, const igraph_real_t *from,
* <para>
* \param graph The graph object.
* \param algo The PageRank implementation to use. Possible values:
* \c IGRAPH_PAGERANK_ALGO_POWER, \c IGRAPH_PAGERANK_ALGO_ARPACK,
* \c IGRAPH_PAGERANK_ALGO_PRPACK.
* \c IGRAPH_PAGERANK_ALGO_ARPACK, \c IGRAPH_PAGERANK_ALGO_PRPACK.
* \param vector Pointer to an initialized vector, the result is
* stored here. It is resized as needed.
* \param value Pointer to a real variable, the eigenvalue
Expand All @@ -1100,15 +1095,10 @@ static int igraph_i_pagerank2(igraph_real_t *to, const igraph_real_t *from,
* \param weights Optional edge weights, it is either a null pointer,
* then the edges are not weighted, or a vector of the same length
* as the number of edges.
* \param options Options to the power method or ARPACK. For the power
* method, \c IGRAPH_PAGERANK_ALGO_POWER it must be a pointer to
* a \ref igraph_pagerank_power_options_t object.
* For \c IGRAPH_PAGERANK_ALGO_ARPACK it must be a pointer to an
* \ref igraph_arpack_options_t object. See \ref igraph_arpack_options_t
* for details. Note that the function overwrites the
* <code>n</code> (number of vertices), <code>nev</code> (1),
* <code>ncv</code> (3) and <code>which</code> (LM) parameters and
* it always starts the calculation from a non-random vector
* \param options Options for the ARPACK method. See \ref igraph_arpack_options_t
* for details. Note that the function overwrites the <code>n</code> (number
* of vertices), <code>nev</code> (1), <code>ncv</code> (3) and <code>which</code>
* (LM) parameters and it always starts the calculation from a non-random vector
* calculated based on the degree of the vertices.
* \return Error code:
* \c IGRAPH_ENOMEM, not enough memory for
Expand All @@ -1119,8 +1109,7 @@ static int igraph_i_pagerank2(igraph_real_t *to, const igraph_real_t *from,
* Time complexity: depends on the input graph, usually it is O(|E|),
* the number of edges.
*
* \sa \ref igraph_pagerank_old() for the old implementation,
* \ref igraph_personalized_pagerank() and \ref igraph_personalized_pagerank_vs()
* \sa * \ref igraph_personalized_pagerank() and \ref igraph_personalized_pagerank_vs()
* for the personalized PageRank measure, \ref igraph_arpack_rssolve() and
* \ref igraph_arpack_rnsolve() for the underlying machinery.
*
Expand All @@ -1131,7 +1120,7 @@ int igraph_pagerank(const igraph_t *graph, igraph_pagerank_algo_t algo,
igraph_vector_t *vector,
igraph_real_t *value, const igraph_vs_t vids,
igraph_bool_t directed, igraph_real_t damping,
const igraph_vector_t *weights, void *options) {
const igraph_vector_t *weights, igraph_arpack_options_t *options) {
return igraph_personalized_pagerank(graph, algo, vector, value, vids,
directed, damping, 0, weights,
options);
Expand Down Expand Up @@ -1163,8 +1152,7 @@ int igraph_pagerank(const igraph_t *graph, igraph_pagerank_algo_t algo,
* <para>
* \param graph The graph object.
* \param algo The PageRank implementation to use. Possible values:
* \c IGRAPH_PAGERANK_ALGO_POWER, \c IGRAPH_PAGERANK_ALGO_ARPACK,
* \c IGRAPH_PAGERANK_ALGO_PRPACK.
* \c IGRAPH_PAGERANK_ALGO_ARPACK, \c IGRAPH_PAGERANK_ALGO_PRPACK.
* \param vector Pointer to an initialized vector, the result is
* stored here. It is resized as needed.
* \param value Pointer to a real variable, the eigenvalue
Expand All @@ -1178,15 +1166,10 @@ int igraph_pagerank(const igraph_t *graph, igraph_pagerank_algo_t algo,
* \param weights Optional edge weights, it is either a null pointer,
* then the edges are not weighted, or a vector of the same length
* as the number of edges.
* \param options Options to the power method or ARPACK. For the power
* method, \c IGRAPH_PAGERANK_ALGO_POWER it must be a pointer to
* a \ref igraph_pagerank_power_options_t object.
* For \c IGRAPH_PAGERANK_ALGO_ARPACK it must be a pointer to an
* \ref igraph_arpack_options_t object. See \ref igraph_arpack_options_t
* for details. Note that the function overwrites the
* <code>n</code> (number of vertices), <code>nev</code> (1),
* <code>ncv</code> (3) and <code>which</code> (LM) parameters and
* it always starts the calculation from a non-random vector
* \param options Options for the ARPACK method. See \ref igraph_arpack_options_t
* for details. Note that the function overwrites the <code>n</code> (number
* of vertices), <code>nev</code> (1), <code>ncv</code> (3) and <code>which</code>
* (LM) parameters and it always starts the calculation from a non-random vector
* calculated based on the degree of the vertices.
* \return Error code:
* \c IGRAPH_ENOMEM, not enough memory for
Expand All @@ -1209,7 +1192,7 @@ int igraph_personalized_pagerank_vs(const igraph_t *graph,
igraph_bool_t directed, igraph_real_t damping,
igraph_vs_t reset_vids,
const igraph_vector_t *weights,
void *options) {
igraph_arpack_options_t *options) {
igraph_vector_t reset;
igraph_vit_t vit;

Expand Down Expand Up @@ -1254,8 +1237,7 @@ int igraph_personalized_pagerank_vs(const igraph_t *graph,
* <para>
* \param graph The graph object.
* \param algo The PageRank implementation to use. Possible values:
* \c IGRAPH_PAGERANK_ALGO_POWER, \c IGRAPH_PAGERANK_ALGO_ARPACK,
* \c IGRAPH_PAGERANK_ALGO_PRPACK.
* \c IGRAPH_PAGERANK_ALGO_ARPACK, \c IGRAPH_PAGERANK_ALGO_PRPACK.
* \param vector Pointer to an initialized vector, the result is
* stored here. It is resized as needed.
* \param value Pointer to a real variable, the eigenvalue
Expand All @@ -1272,15 +1254,10 @@ int igraph_personalized_pagerank_vs(const igraph_t *graph,
* \param weights Optional edge weights, it is either a null pointer,
* then the edges are not weighted, or a vector of the same length
* as the number of edges.
* \param options Options to the power method or ARPACK. For the power
* method, \c IGRAPH_PAGERANK_ALGO_POWER it must be a pointer to
* a \ref igraph_pagerank_power_options_t object.
* For \c IGRAPH_PAGERANK_ALGO_ARPACK it must be a pointer to an
* \ref igraph_arpack_options_t object. See \ref igraph_arpack_options_t
* for details. Note that the function overwrites the
* <code>n</code> (number of vertices), <code>nev</code> (1),
* <code>ncv</code> (3) and <code>which</code> (LM) parameters and
* it always starts the calculation from a non-random vector
* \param options Options for the ARPACK method. See \ref igraph_arpack_options_t
* for details. Note that the function overwrites the <code>n</code> (number
* of vertices), <code>nev</code> (1), <code>ncv</code> (3) and <code>which</code>
* (LM) parameters and it always starts the calculation from a non-random vector
* calculated based on the degree of the vertices.
* \return Error code:
* \c IGRAPH_ENOMEM, not enough memory for
Expand All @@ -1301,19 +1278,9 @@ int igraph_personalized_pagerank(const igraph_t *graph,
igraph_bool_t directed, igraph_real_t damping,
igraph_vector_t *reset,
const igraph_vector_t *weights,
void *options) {

if (algo == IGRAPH_PAGERANK_ALGO_POWER) {
igraph_pagerank_power_options_t *o =
(igraph_pagerank_power_options_t *) options;
if (reset) {
IGRAPH_WARNING("Cannot use weights with power method, "
"weights will be ignored");
}
return igraph_pagerank_old(graph, vector, vids, directed,
o->niter, o->eps, damping,
/*old=*/ 0);
} else if (algo == IGRAPH_PAGERANK_ALGO_ARPACK) {
igraph_arpack_options_t *options) {

if (algo == IGRAPH_PAGERANK_ALGO_ARPACK) {
igraph_arpack_options_t *o = (igraph_arpack_options_t*) options;
return igraph_personalized_pagerank_arpack(graph, vector, value, vids,
directed, damping, reset,
Expand Down

0 comments on commit 6f43b86

Please sign in to comment.