diff --git a/Makefile b/Makefile index 4c47334a9289017e992095e1b082cb132ab9d70e..e2b0f80150c34fb933d22757091f87346a248965 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ clean: TP1: TP1.o file.o $(CC) $(OPTIONS) -o $@ $^ $(MATH) -g -TP2: TP2.o struct_tp2.o +TP2: TP2.o struct_tp2.o plotout.o $(CC) $(OPTIONS) -o $@ $^ $(MATH) -g TP3: TP3.o plotout.o file.o diff --git a/TP2.c b/TP2.c index 36ae093d160c3a8aad9f395f40bb97f8c545221b..54f56b0e51f3174af89d35a4a1d6386403446018 100644 --- a/TP2.c +++ b/TP2.c @@ -1,9 +1,23 @@ #include "./implems.c" #include "./struct_tp2.h" +#include "./plotout.h" #include <stdio.h> #include <stdlib.h> +// g une liste d'adjacence décrivant le graphe +// out res un tableau de taille g->n +// ensures + // out res [i] contient le degré du noeud i +void calc_deg(adjlist *g, unsigned long *out_res) { + unsigned long i; + for (i = 0; i < g->n; i += 1) { + out_res[i] = g->cd[i+1] - g->cd[i]; + } + return; +} + + // g une liste d'adjacence décrivant le graphe @@ -204,6 +218,7 @@ int main(int argc, char **argv) { // calcul du core ordering et des core value + printf("compiting core ordering and core decomposition...\n"); unsigned long* eta; int* c; c = (int*) malloc((g->n)*sizeof(int)); @@ -221,6 +236,7 @@ int main(int argc, char **argv) { printf("core value du graphe : %i\n", max_c_val(c, g->n)); // calcul du densest prefix graph + printf("computing densest prefix graph...\n"); unsigned long indix_densest; long double densest_cop_av_deg_dens; long double densest_cop_edge_dens; @@ -233,7 +249,20 @@ int main(int argc, char **argv) { // printf("densest core prefix :\n\taverage degre density : %f\n\tedge density : %f\n\tsize : %lu\n", (double) densest_cop_av_deg_dens, (double) densest_cop_edge_dens, indix_densest+1); + + + + + // EXERCICE 2 + // Calcul des degrés des noeuds pour plot + unsigned long *deg_tabl = (unsigned long*) malloc((g->n)*sizeof(unsigned long)); + calc_deg(g, deg_tabl); + + + plot_out_2D_i_ul("scholar.csv", g->n, c, deg_tabl); + free_adjlist(g); + free(deg_tabl); free(eta); free(c); return 0; diff --git a/adjarray.c b/adjarray.c deleted file mode 100755 index 683337f90eedaf00eba406c416bf9f1abe9a0ea7..0000000000000000000000000000000000000000 --- a/adjarray.c +++ /dev/null @@ -1,126 +0,0 @@ -/* -Maximilien Danisch -September 2017 -http://bit.ly/danisch -maximilien.danisch@gmail.com - -Info: -Feel free to use these lines as you wish. This program loads a graph in main memory. - -To compile: -"gcc adjlist.c -O9 -o adjlist". - -To execute: -"./adjlist edgelist.txt". -"edgelist.txt" should contain the graph: one edge on each line (two unsigned long (nodes' ID)) separated by a space. -The prograph will load the graph in main memory and then terminate. - -Note: -If the graph is directed (and weighted) with selfloops and you want to make it undirected unweighted without selfloops, use the following linux command line. -awk '{if ($1<$2) print $1" "$2;else if ($2<$1) print $2" "$1}' net.txt | sort -n -k1,2 -u > net2.txt - -Performance: -Up to 200 million edges on my laptop with 8G of RAM: takes more or less 4G of RAM and 30 seconds (I have an SSD hardrive) for 100M edges. -*/ - -#include <stdlib.h> -#include <stdio.h> -#include <time.h>//to estimate the runing time - -#define NLINKS 100000000 //maximum number of edges for memory allocation, will increase if needed - -typedef struct { - unsigned long s; - unsigned long t; -} edge; - -//edge list structure: -typedef struct { - unsigned long n;//number of nodes - unsigned long e;//number of edges - edge *edges;//list of edges - unsigned long *cd;//cumulative degree cd[0]=0 length=n+1 - unsigned long *adj;//concatenated lists of neighbors of all nodes -} adjlist; - -//compute the maximum of three unsigned long -inline unsigned long max3(unsigned long a,unsigned long b,unsigned long c){ - a=(a>b) ? a : b; - return (a>c) ? a : c; -} - -//reading the edgelist from file -adjlist* readedgelist(char* input){ - unsigned long e1=NLINKS; - FILE *file=fopen(input,"r"); - - adjlist *g=malloc(sizeof(adjlist)); - g->n=0; - g->e=0; - g->edges=malloc(e1*sizeof(edge));//allocate some RAM to store edges - - char line[1000]; - while (fgets(line, sizeof line, file)) { - // ignore les commentaires # - if (*line == '#') {continue;} - // récupère les données - if (sscanf(line, "%lu %lu", &(g->edges[g->e].s), &(g->edges[g->e].t))==2) { - g->n=max3(g->n,g->edges[g->e].s,g->edges[g->e].t); - if (++(g->e)==e1) {//increase allocated RAM if needed - e1+=NLINKS; - g->edges=realloc(g->edges,e1*sizeof(edge)); - } - } - } - - fclose(file); - - g->n++; - - g->edges=realloc(g->edges,g->e*sizeof(edge)); - - return g; -} - -//building the adjacency matrix -void mkadjlist(adjlist* g){ - unsigned long i,u,v; - unsigned long *d=calloc(g->n,sizeof(unsigned long)); - - for (i=0;i<g->e;i++) { - d[g->edges[i].s]++; - d[g->edges[i].t]++; - } - - g->cd=malloc((g->n+1)*sizeof(unsigned long)); - g->cd[0]=0; - for (i=1;i<g->n+1;i++) { - g->cd[i]=g->cd[i-1]+d[i-1]; - d[i-1]=0; - } - - g->adj=malloc(2*g->e*sizeof(unsigned long)); - - for (i=0;i<g->e;i++) { - u=g->edges[i].s; - v=g->edges[i].t; - g->adj[ g->cd[u] + d[u]++ ]=v; - g->adj[ g->cd[v] + d[v]++ ]=u; - } - - free(d); - //free(g->edges); -} - - -//freeing memory -void free_adjlist(adjlist *g){ - free(g->edges); - free(g->cd); - free(g->adj); - free(g); -} - - - - diff --git a/adjmatrix.c b/adjmatrix.c deleted file mode 100755 index 896c66b9b2c4b6211bcba9ccaf393d633bb1c536..0000000000000000000000000000000000000000 --- a/adjmatrix.c +++ /dev/null @@ -1,130 +0,0 @@ -/* -Maximilien Danisch -September 2017 -http://bit.ly/danisch -maximilien.danisch@gmail.com - -Info: -Feel free to use these lines as you wish. This program loads an unweighetd graph in main memory as an adjacency matrix. - -To compile: -"gcc adjmatrix.c -O9 -o adjmatrix". - -To execute: -"./adjmatrix edgelist.txt". -"edgelist.txt" should contain the graph: one edge on each line (two unsigned long (nodes' ID)) separated by a space. -The prograph will load the graph in main memory and then terminate. - -Note: -If the graph is directed (and weighted) with selfloops and you want to make it undirected unweighted without selfloops, use the following linux command line. -awk '{if ($1<$2) print $1" "$2;else if ($2<$1) print $2" "$1}' net.txt | sort -n -k1,2 -u > net2.txt - -Performence: -Up to 200.000 nodes on my laptop with 8G of RAM. -Takes more or less 4G of RAM and 10 seconds (I have an SSD hardrive) for 100.000 nodes. -*/ - -#include <stdlib.h> -#include <stdio.h> -#include <stdbool.h> -#include <time.h>//to estimate the runing time - -#define NLINKS 100000000 //maximum number of edges for memory allocation, will increase if needed - -typedef struct { - unsigned long s; - unsigned long t; -} edge; - -//edge list structure: -typedef struct { - unsigned long n;//number of nodes - unsigned long e;//number of edges - edge *edges;//list of edges - bool *mat;//adjacency matrix -} adjmatrix; - -//compute the maximum of three unsigned long -inline unsigned long max3(unsigned long a,unsigned long b,unsigned long c){ - a=(a>b) ? a : b; - return (a>c) ? a : c; -} - -//reading the edgelist from file -adjmatrix* readedgelist(char* input){ - unsigned long e1=NLINKS; - FILE *file=fopen(input,"r"); - - adjmatrix *g=malloc(sizeof(adjmatrix)); - g->n=0; - g->e=0; - g->edges=malloc(e1*sizeof(edge));//allocate some RAM to store edges - - - char line[1000]; - while (fgets(line, sizeof line, file)) { - // ignore les commentaires # - if (*line == '#') {continue;} - // récupère les données - if (sscanf(line, "%lu %lu", &(g->edges[g->e].s), &(g->edges[g->e].t))==2) { - g->n=max3(g->n,g->edges[g->e].s,g->edges[g->e].t); - if (++(g->e)==e1) {//increase allocated RAM if needed - e1+=NLINKS; - g->edges=realloc(g->edges,e1*sizeof(edge)); - } - } - } - - fclose(file); - - g->n++; - - g->edges=realloc(g->edges,g->e*sizeof(edge)); - - return g; -} - -//building the adjacency matrix -void mkmatrix(adjmatrix* g){ - unsigned long i,u,v; - g->mat=calloc(g->n*g->n,sizeof(bool)); - for (i=0;i<g->e;i++){ - u=g->edges[i].s; - v=g->edges[i].t; - g->mat[u+g->n*v]=1; - g->mat[v+g->n*u]=1; - } -} - - -void free_adjmatrix(adjmatrix *g){ - free(g->edges); - free(g->mat); - free(g); -} - -int main(int argc,char** argv){ - adjmatrix* g; - time_t t1,t2; - - t1=time(NULL); - - printf("Reading edgelist from file %s\n",argv[1]); - g=readedgelist(argv[1]); - - printf("Number of nodes: %lu\n",g->n); - printf("Number of edges: %lu\n",g->e); - - printf("Building the adjacency matrix\n"); - mkmatrix(g); - - free_adjmatrix(g); - - t2=time(NULL); - - printf("- Overall time = %ldh%ldm%lds\n",(t2-t1)/3600,((t2-t1)%3600)/60,((t2-t1)%60)); - - return 0; -} - - diff --git a/edgelist.c b/edgelist.c deleted file mode 100755 index 9750223a1b1df9f238d2a29ca1add5656c793a26..0000000000000000000000000000000000000000 --- a/edgelist.c +++ /dev/null @@ -1,110 +0,0 @@ -/* -Maximilien Danisch -September 2017 -http://bit.ly/danisch -maximilien.danisch@gmail.com - -Info: -Feel free to use these lines as you wish. This program loads a graph in main memory as a list of edges. - -To compile: -"gcc edgelist.c -O9 -o edgelist". - -To execute: -"./edgelist edgelist.txt". -"edgelist.txt" should contain the graph: one edge on each line (two unsigned long (nodes' ID)) separated by a space. -The prograph loads the graph in main memory and then it terminates. - -Note: -If the graph is directed (and weighted) with selfloops and you want to make it undirected unweighted without selfloops, use the following linux command line. -awk '{if ($1<$2) print $1" "$2;else if ($2<$1) print $2" "$1}' net.txt | sort -n -k1,2 -u > net2.txt - -Performance: -Up to 500 million edges on my laptop with 8G of RAM: -Takes more or less 1.6G of RAM and 25 seconds (I have an SSD hardrive) for 100M edges. -*/ - -#include <stdlib.h> -#include <stdio.h> -#include <time.h>//to estimate the runing time - -#define NLINKS 100000000 //maximum number of edges for memory allocation, will increase if needed - -typedef struct { - unsigned long s; - unsigned long t; -} edge; - -//edge list structure: -typedef struct { - unsigned long n;//number of nodes - unsigned long e;//number of edges - edge *edges;//list of edges -} edgelist; - -//compute the maximum of three unsigned long -inline unsigned long max3(unsigned long a,unsigned long b,unsigned long c){ - a=(a>b) ? a : b; - return (a>c) ? a : c; -} - -//reading the edgelist from file -edgelist* readedgelist(char* input){ - unsigned long e1=NLINKS; - FILE *file=fopen(input,"r"); - - edgelist *g=malloc(sizeof(edgelist)); - g->n=0; - g->e=0; - g->edges=malloc(e1*sizeof(edge));//allocate some RAM to store edges - - char line[1000]; - while (fgets(line, sizeof line, file)) { - // ignore les commentaires # - if (*line == '#') {continue;} - // récupère les données - if (sscanf(line, "%lu %lu", &(g->edges[g->e].s), &(g->edges[g->e].t))==2) { - g->n=max3(g->n,g->edges[g->e].s,g->edges[g->e].t); - if (++(g->e)==e1) {//increase allocated RAM if needed - e1+=NLINKS; - g->edges=realloc(g->edges,e1*sizeof(edge)); - } - } - } - - fclose(file); - - g->n++; - - g->edges=realloc(g->edges,g->e*sizeof(edge)); - - return g; -} - -void free_edgelist(edgelist *g){ - free(g->edges); - free(g); -} - -int main(int argc,char** argv){ - edgelist* g; - time_t t1,t2; - - t1=time(NULL); - - printf("Reading edgelist from file %s\n",argv[1]); - g=readedgelist(argv[1]); - - printf("Number of nodes: %lu\n",g->n); - printf("Number of edges: %lu\n",g->e); - - free_edgelist(g); - - t2=time(NULL); - - printf("- Overall time = %ldh%ldm%lds\n",(t2-t1)/3600,((t2-t1)%3600)/60,((t2-t1)%60)); - - return 0; -} - - diff --git a/plotout.c b/plotout.c index ea76c0aad8ecf45a2654379fa5a63506c47bcf24..e65898f3d9e16bdaca17e92ecceb31558f7b9f54 100644 --- a/plotout.c +++ b/plotout.c @@ -3,6 +3,22 @@ #include "plotout.h" +int plot_out_2D_i_ul(char* filename, unsigned long size, int *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, "%i,%lu\n", x[i], y[i]); + } + + fclose(ptr); + + return 0; +} + int plot_out_2D_ul_ul(char* filename, unsigned long size, unsigned long *x, unsigned long *y) { FILE *ptr; diff --git a/plotout.h b/plotout.h index 252aaea6f180ae34831b08707983da3613704404..3e0546b187222e67951203038ba7bee133882ac5 100644 --- a/plotout.h +++ b/plotout.h @@ -3,6 +3,7 @@ // 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_i_ul(char* name, unsigned long size, int *x, unsigned long *y); int plot_out_2D_ul_ul(char* name, unsigned long size, unsigned long *x, unsigned long *y); diff --git a/trace_graphe.py b/trace_graphe.py index 75f4ce7c487eb69215581f1949c339adc8960720..ab8d03fa2b0422dd1179db16a3fbf8e2524607ea 100644 --- a/trace_graphe.py +++ b/trace_graphe.py @@ -11,6 +11,23 @@ import numpy as np +########################## +# google scholar +########################## + +data = pd.read_csv("../plots/scholar.csv", sep=",") + +plt.plot(data['y'], data['x'], 'o') +plt.xscale("log") +plt.yscale("log") + +plt.show() + +######################################################################################################## +######################################################################################################## + + + ########################## # PLOT 1 ##########################