diff --git a/Makefile b/Makefile index 9e02649a1f4c05fb7f95b0dae1ea4ad637a337fc..492fddf376b92b93390529f5de460efabc5d356d 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = gcc -OPTIONS = -Wall -Wextra -O9 +OPTIONS = -Wall -Wextra -O3 MATH = -lm EXECUTABLE = TP1 TP2 TP3 TP4 @@ -21,15 +21,19 @@ TP1: TP1.o file.o TP2: TP2.o struct_tp2.o $(CC) $(OPTIONS) -o $@ $^ $(MATH) -g -TP3: TP3.o +TP3: TP3.o plotout.o + $(CC) $(OPTIONS) -o $@ $^ $(MATH) -g TP4: TP4.o + $(CC) $(OPTIONS) -o $@ $^ $(MATH) -g + +# TP1.o: implems.c -TP1.o: implems.c +# TP2.o: implems.c struct_tp2.h -TP2.o: implems.c struct_tp2.h +# TP3.o: implems.c plotout.h %.o: %.c $(CC) $(OPTIONS) -c $^ -g diff --git a/TP3.c b/TP3.c index 39088665cdc0017b7750447a25aee7c34d0cfb2e..7f94b4aac53952a0c2e475b568db57edb2511d30 100644 --- a/TP3.c +++ b/TP3.c @@ -1,7 +1,9 @@ #include "./implems.c" -#include "./struct_tp2.h" +#include "./plotout.h" #include <stdio.h> #include <stdlib.h> +#include <limits.h> +#include <float.h> // fonction écrivant les degrés sortant de chaque noeuds dans le tableau out_res @@ -92,19 +94,32 @@ int pagerank(edgelist *g, long double *distr_res, long double alpha, unsigned lo } // si nombre impair d'itération, copie du résultat final dans le bon tableau - if (nb_iter%2 == 1 || nb_iter == 0) { + if (nb_iter%2 == 1) { for (i = 0; i < g->n; i += 1) { distr_res[i] = prob_t[i]; } + free(prob_t); + } + else { + free(prob_t1); } - free(prob_t1); free(out_deg); return 0; } + +void debug_print_tabl(long double *tab) { + printf("\n\n---------\n"); + for (int i = 0; i < 5; i += 1) { + printf("%Le\n", tab[i]); + } + printf("\n"); +} + + // fonction déterminant, pour un vecteur de distribution donné les 5 meilleurs et les 5 pire // requires : // resmin est un tableau de 5 long double malloc @@ -112,8 +127,58 @@ int pagerank(edgelist *g, long double *distr_res, long double alpha, unsigned lo // ensures : // resmin contient les 5 pages les moins visitées du moins au plus // resmax contient les 5 pages les plus visités du plus au moins -int find_5(edgelist *g, long double *distr, long double *resmin, long double *resmax) { +int find_5(edgelist *g, long double *distr, unsigned long *resmin, unsigned long *resmax) { + unsigned long ind; + // initialise les tableaux max et min + long double *valmin = (long double*) malloc(5*sizeof(long double)); + long double *valmax = (long double*) malloc(5*sizeof(long double)); + for (int i = 0; i < 5; i += 1) { + resmin[i] = 0; + resmax[i] = 0; + valmin[i] = DBL_MAX; + valmax[i] = 0; + } + // itères sur l'ensemble des probas de distribution + // resmin trié par ordre croissant + // resmax trié par ordre décroissant + for (unsigned long i = 0; i < g->n; i += 1) { + // si la valeur est plus petite que le plus grand des plus petit + if (distr[i] <= valmin[4] && (i != 13834638 && i != 13834637 && i != 13834634 && i!= 13834633 && i != 13834632 && i != 13834631 && i != 13834630 && !(i > 13834615 && i < 13834629) && !(i>13834611 && i <13834615) && !(i>13834606 && i<13834611))) { + ind = 4; + while (ind > 0 && distr[i] <= valmin[ind - 1]) { + valmin[ind] = valmin[ind-1]; + resmin[ind] = resmin[ind-1]; + ind -= 1; + } + valmin[ind] = distr[i]; + resmin[ind] = i; + } + + // si la valeur est plus grande que le plus petit des plus grands + if (distr[i] > valmax[4]) { + ind = 4; + while (ind > 0 && distr[i] > valmax[ind - 1]) { + valmax[ind] = valmax[ind-1]; + resmax[ind] = resmax[ind-1]; + ind -= 1; + } + valmax[ind] = distr[i]; + resmax[ind] = i; + // debug_print_tabl(valmax); + } + + } + + // affiche les résultats + printf("max |min\n"); + for (ind = 0; ind < 5; ind += 1) { + printf("|%lu :: %Le |%lu :: %Le\n", resmax[ind], valmax[ind], resmin[ind], valmin[ind]); + } + + free(valmin); + free(valmax); + return 0; } @@ -149,23 +214,75 @@ int main(int argc, char **argv) { // printf("- Overall time = %I64dh%I64dm%I64ds\n",(t2-t1)/3600,((t2-t1)%3600)/60,((t2-t1)%60)); - - // fonctions du TP3 long double *p_distrib; + unsigned long *highest; + unsigned long *lowest; p_distrib = (long double*) malloc((g->n)*sizeof(long double)); + highest = (unsigned long*) malloc(5*sizeof(unsigned long)); + lowest = (unsigned long*) malloc(5*sizeof(unsigned long)); + pagerank(g, p_distrib, 0.15, 70); + + + find_5(g, p_distrib, lowest, highest); + - pagerank(g, p_distrib, 0.15, 100); - long double last = p_distrib[0]; - for(unsigned long i =0; i < g->n; i +=1) { - if (last != p_distrib[i]) { - printf("|%Le|\n", p_distrib[i]); - } - } + // TABLEAUX pour les CORRELATIONS + + long double *p_15 = p_distrib; + long double *p_1; + long double *p_2; + long double *p_5; + long double *p_9; + unsigned long *out_deg; + unsigned long *in_deg; + + p_1 = (long double*) malloc((g->n)*sizeof(long double)); + p_2 = (long double*) malloc((g->n)*sizeof(long double)); + p_5 = (long double*) malloc((g->n)*sizeof(long double)); + p_9 = (long double*) malloc((g->n)*sizeof(long double)); + out_deg = (unsigned long*) malloc((g->n)*sizeof(unsigned long)); + in_deg = (unsigned long*) malloc((g->n)*sizeof(unsigned long)); + + printf("out_deg processing...\n"); + calc_out_deg(g, out_deg); + printf("in_deg processing...\n"); + calc_in_deg(g, in_deg); + printf("pagerank 0.1 processing...\n"); + pagerank(g, p_1, 0.1, 70); + printf("pagerank 0.2 processing...\n"); + pagerank(g, p_2, 0.2, 70); + printf("pagerank 0.5 processing...\n"); + pagerank(g, p_5, 0.5, 70); + printf("pagerank 0.9 processing...\n"); + pagerank(g, p_9, 0.9, 70); + + + printf("output plots ...\n"); + plot_out_2D_ld_ul("1.csv", g->n, p_15, in_deg); + plot_out_2D_ld_ul("2.csv", g->n, p_15, out_deg); + plot_out_2D_ld_ld("3.csv", g->n, p_15, p_1); + plot_out_2D_ld_ld("4.csv", g->n, p_15, p_2); + plot_out_2D_ld_ld("5.csv", g->n, p_15, p_5); + plot_out_2D_ld_ld("6.csv", g->n, p_15, p_9); + + // long double last = p_distrib[0]; + // for(unsigned long i =0; i < g->n; i +=1) { + // if (last != p_distrib[i]) { + // printf("|%Le|\n", p_distrib[i]); + // } + // } + + free(p_1); + free(p_2); + free(p_5); + free(p_9); + free(p_15); + return 0; } \ No newline at end of file diff --git a/TP4.c b/TP4.c index 4be65d6ed3d9b79d16278d9a426748a13520a63b..1f027e76f3acfa623426dfcfe4afb9b1bc59c26e 100644 --- a/TP4.c +++ b/TP4.c @@ -60,7 +60,8 @@ int main(int argc, char **argv) { unsigned long a = 1; - printf("%I64i %I64i %I64i %i %li\n", sizeof(int), sizeof(unsigned long), sizeof(unsigned long long), RAND_MAX, a); + printf("%lu %lu %lu %i %li\n", sizeof(int), sizeof(unsigned long), sizeof(unsigned long long), RAND_MAX, a); + // printf("%I64i %I64i %I64i %i %li\n", sizeof(int), sizeof(unsigned long), sizeof(unsigned long long), RAND_MAX, a); free_adjlist(g); diff --git a/plotout.c b/plotout.c new file mode 100644 index 0000000000000000000000000000000000000000..ea76c0aad8ecf45a2654379fa5a63506c47bcf24 --- /dev/null +++ b/plotout.c @@ -0,0 +1,57 @@ +#include <stdio.h> +#include <stdlib.h> + +#include "plotout.h" + + +int plot_out_2D_ul_ul(char* filename, unsigned long size, unsigned long *x, unsigned long *y) { + FILE *ptr; + + + ptr = fopen(filename, "w"); + + fprintf(ptr, "x,y\n"); + for (unsigned long i = 0; i < size; i += 1) { + fprintf(ptr, "%lu,%lu\n", x[i], y[i]); + } + + fclose(ptr); + + return 0; +} + + +int plot_out_2D_ld_ul(char* filename, unsigned long size, long double *x, unsigned long *y) { + FILE *ptr; + + + ptr = fopen(filename, "w"); + + fprintf(ptr, "x,y\n"); + for (unsigned long i = 0; i < size; i += 1) { + fprintf(ptr, "%Le,%lu\n", x[i], y[i]); + } + + fclose(ptr); + + return 0; +} + + +int plot_out_2D_ld_ld(char* filename, unsigned long size, long double *x, long double *y) { + FILE *ptr; + + + ptr = fopen(filename, "w"); + + fprintf(ptr, "x,y\n"); + for (unsigned long i = 0; i < size; i += 1) { + fprintf(ptr, "%Le,%Le\n", x[i], y[i]); + } + + fclose(ptr); + + return 0; +} + + diff --git a/plotout.h b/plotout.h new file mode 100644 index 0000000000000000000000000000000000000000..1df89a41b32d4b1b72611ece2e71ce09ee0cf634 --- /dev/null +++ b/plotout.h @@ -0,0 +1,14 @@ +#ifndef PLOTOUT_H +#define PLOTOUT_H + +// fonctions permettant de générer un CSV dans l'optique de tracer un graphe avec un autre logiciel (exemple python) + + +int plot_out_2D_ul_ul(char* name, unsigned long size, unsigned long *x, unsigned long *y); + +int plot_out_2D_ld_ul(char* name, unsigned long size, long double *x, unsigned long *y); + +int plot_out_2D_ld_ld(char* name, unsigned long size, long double *x, long double *y); + + +#endif \ No newline at end of file diff --git a/trace_graphe.py b/trace_graphe.py new file mode 100644 index 0000000000000000000000000000000000000000..ab82dab241717d8a93a330d3cef18f5891bf82aa --- /dev/null +++ b/trace_graphe.py @@ -0,0 +1,133 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Tue Mar 2 16:55:34 2021 + +@author: louisfourcade +""" +import pandas as pd +import matplotlib.pyplot as plt +import numpy as np + + + +########################## +# PLOT 1 +########################## + + + +data = pd.read_csv("../plots/1.csv", sep=",") + + +#plot des données +plt.scatter(data['x'], data['y']) + +#plot de la régression linéaire +m, b = np.polyfit(data['x'], data['y'], 1) +plt.plot(data['x'], m*data['x']+b, color = "red") + + + +plt.xlim(0,0.0025) +plt.ylim(0,250000) + + + +plt.xscale("linear") +plt.yscale("linear") +#valeurs d'échelle : {"linear", "log", "symlog", "logit", ...} + +plt.title("degré entrant en fonction de pagerank") +plt.xlabel("pagerank (α = 0.15)") +plt.ylabel("degré entrant") + + +plt.show() + + + + +########################## +# PLOT 2 +########################## +data = pd.read_csv("../plots/2.csv", sep=",") +plt.scatter(data['x'], data['y']) + + +plt.title("degré sortant en fonction de pagerank") +plt.xlabel("pagerank (α = 0.15)") +plt.ylabel("degré sortant") +plt.xlim(0,0.0035) + + + +plt.show() + + +########################## +# PLOT 3 +########################## +data = pd.read_csv("../plots/3.csv", sep=",") +plt.scatter(data['x'], data['y']) + +plt.title("pagerank (α = 0.15) vs pagerank (α = 0.1)") +plt.xlabel("pagerank (α = 0.15)") +plt.ylabel("pagerank (α = 0.1)") +plt.xlim(0,0.0035) +plt.ylim(0,0.005) + + + +plt.show() + + +########################## +# PLOT 4 +########################## +data = pd.read_csv("../plots/4.csv", sep=",") +plt.scatter(data['x'], data['y']) + +plt.title("pagerank (α = 0.15) vs pagerank (α = 0.2)") +plt.xlabel("pagerank (α = 0.15)") +plt.ylabel("pagerank (α = 0.2)") +plt.xlim(0,0.0035) +plt.ylim(0,0.005) + + + +plt.show() + + +########################## +# PLOT 5 +########################## +data = pd.read_csv("../plots/5.csv", sep=",") +plt.scatter(data['x'], data['y']) + +plt.title("pagerank (α = 0.15) vs pagerank (α = 0.5)") +plt.xlabel("pagerank (α = 0.15)") +plt.ylabel("pagerank (α = 0.5)") +plt.xlim(0,0.0035) +plt.ylim(0,0.0025) + + + +plt.show() + + +########################## +# PLOT 6 +########################## +data = pd.read_csv("../plots/6.csv", sep=",") +plt.scatter(data['x'], data['y']) + +plt.title("pagerank (α = 0.15) vs pagerank (α = 0.9)") +plt.xlabel("pagerank (α = 0.15)") +plt.ylabel("pagerank (α = 0.9)") +plt.xlim(0,0.0035) +plt.ylim(0,0.0005) + + + +plt.show() \ No newline at end of file