From 106125e049d95f2c84727383d30b833d71af062c Mon Sep 17 00:00:00 2001 From: Sam Hadow Date: Wed, 14 May 2025 17:30:41 +0200 Subject: [PATCH] change output --- src/main.c | 17 ++--------------- src/power_algorithm.c | 10 ++++++---- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/main.c b/src/main.c index 36652df..23f239f 100644 --- a/src/main.c +++ b/src/main.c @@ -12,7 +12,6 @@ void test_stationary_distribution(const char *path) { struct timeval tvstart, tvend; - // Read and prepare the matrix gettimeofday(&tvstart, NULL); SparseMatrix *matrix = read_sparse_matrix_from_mtx(path); convert_to_stochastic(matrix); @@ -22,32 +21,20 @@ void test_stationary_distribution(const char *path) { double epsilon = 1e-10; double alpha = 0.8; - // pagerank gettimeofday(&tvstart, NULL); double *pi_power = pagerank(matrix, epsilon, alpha); gettimeofday(&tvend, NULL); print_time_diff("Pagerank", &tvstart, &tvend); - // nable delta gettimeofday(&tvstart, NULL); double *pi_new = gauss_seidel_pagerank(matrix, epsilon, alpha); gettimeofday(&tvend, NULL); - print_time_diff("Gauss Seidel algorithm", &tvstart, &tvend); + print_time_diff("Gauss-Seidel:", &tvstart, &tvend); - // Compare results double diff = diff_norm_vector(pi_power, pi_new, matrix->num_nodes); - printf("Difference between power method and new algorithm: %.16f\n", diff); + printf("Difference norm Pagerank and Gauss-Seidel: %.16f\n", diff); - - for (int i = 0; i < 10; ++i) { - printf("pi_old: %.16f\n", pi_power[i]); - printf("pi_new: %.16f\n", pi_new[i]); - printf("\n"); - } - - - // Clean up free(pi_power); free(pi_new); free_sparse_matrix(matrix); diff --git a/src/power_algorithm.c b/src/power_algorithm.c index 46d6fce..c74f177 100644 --- a/src/power_algorithm.c +++ b/src/power_algorithm.c @@ -19,7 +19,6 @@ double* power_algorithm(const SparseMatrix *matrix, double epsilon) { init_vector(pi, N, 1.0/(double)N); pi2 = power_algorithm_step(matrix, pi); while (diff_norm_vector(pi, pi2, N)>epsilon) { - printf("step\n"); memcpy(pi, pi2, vecsize); pi2 = power_algorithm_step(matrix, pi); } @@ -65,12 +64,15 @@ double* pagerank(const SparseMatrix *matrix, double epsilon, double alpha) { pi = pi_new; pi_new = malloc(vec_size); - if ((++iter)%1 == 0) { - printf("Iteration %d: diff = %.16f\n", iter, diff); - } + // if ((++iter)%1 == 0) { + // printf("Iteration %d: diff = %.16f\n", iter, diff); + // } + ++iter; free(temp); } while (diff > epsilon); + printf("Pagerank: %d Iterations\n", iter); + free(pi_new); free(f); return pi;