Skip to content
Extraits de code Groupes Projets
Valider 189896a5 rédigé par Louis Fourcade's avatar Louis Fourcade
Parcourir les fichiers

TP2 et clean de fichiers inutiles

parent 3eb79d81
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -18,7 +18,7 @@ clean: ...@@ -18,7 +18,7 @@ clean:
TP1: TP1.o file.o TP1: TP1.o file.o
$(CC) $(OPTIONS) -o $@ $^ $(MATH) -g $(CC) $(OPTIONS) -o $@ $^ $(MATH) -g
TP2: TP2.o struct_tp2.o TP2: TP2.o struct_tp2.o plotout.o
$(CC) $(OPTIONS) -o $@ $^ $(MATH) -g $(CC) $(OPTIONS) -o $@ $^ $(MATH) -g
TP3: TP3.o plotout.o file.o TP3: TP3.o plotout.o file.o
......
#include "./implems.c" #include "./implems.c"
#include "./struct_tp2.h" #include "./struct_tp2.h"
#include "./plotout.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.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 // g une liste d'adjacence décrivant le graphe
...@@ -204,6 +218,7 @@ int main(int argc, char **argv) { ...@@ -204,6 +218,7 @@ int main(int argc, char **argv) {
// calcul du core ordering et des core value // calcul du core ordering et des core value
printf("compiting core ordering and core decomposition...\n");
unsigned long* eta; unsigned long* eta;
int* c; int* c;
c = (int*) malloc((g->n)*sizeof(int)); c = (int*) malloc((g->n)*sizeof(int));
...@@ -221,6 +236,7 @@ int main(int argc, char **argv) { ...@@ -221,6 +236,7 @@ int main(int argc, char **argv) {
printf("core value du graphe : %i\n", max_c_val(c, g->n)); printf("core value du graphe : %i\n", max_c_val(c, g->n));
// calcul du densest prefix graph // calcul du densest prefix graph
printf("computing densest prefix graph...\n");
unsigned long indix_densest; unsigned long indix_densest;
long double densest_cop_av_deg_dens; long double densest_cop_av_deg_dens;
long double densest_cop_edge_dens; long double densest_cop_edge_dens;
...@@ -233,7 +249,20 @@ int main(int argc, char **argv) { ...@@ -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); // 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_adjlist(g);
free(deg_tabl);
free(eta); free(eta);
free(c); free(c);
return 0; return 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);
}
/*
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;
}
/*
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;
}
...@@ -3,6 +3,22 @@ ...@@ -3,6 +3,22 @@
#include "plotout.h" #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) { int plot_out_2D_ul_ul(char* filename, unsigned long size, unsigned long *x, unsigned long *y) {
FILE *ptr; FILE *ptr;
......
...@@ -3,6 +3,7 @@ ...@@ -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) // 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); int plot_out_2D_ul_ul(char* name, unsigned long size, unsigned long *x, unsigned long *y);
......
...@@ -11,6 +11,23 @@ import numpy as np ...@@ -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 # PLOT 1
########################## ##########################
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter