Exemplo n.º 1
0
int initIgraph(int *m){

	igraph_t g;
	igraph_matrix_t mat;
	long int i, j;

	igraph_matrix_init(&mat, numNodos, numNodos);
	for (i=0; i<numNodos; i++) for (j=0; j<numNodos; j++) MATRIX(mat, i, j) = m[i+numNodos*j];
	igraph_i_set_attribute_table(&igraph_cattribute_table);


	igraph_weighted_adjacency(&g, &mat, IGRAPH_ADJ_UPPER, 0, /*loops=*/ 1);
	//print(&g);

	FILE *stp;
	stp = fopen("/home/john/git/primAlgorithm/grafo2.gml", "w");
	if (stp==0) {
		printf("Problema abriendo archivo de grafo\n");
		return EXIT_FAILURE;
	}

	igraph_write_graph_gml(&g, stp, 0, "gml Test");
	fclose(stp);

	igraph_destroy(&g);
	return EXIT_SUCCESS;
}
Exemplo n.º 2
0
int main() {
  
  igraph_t g;
  igraph_vector_t y;  

  /* turn on attribute handling */
  igraph_i_set_attribute_table(&igraph_cattribute_table);

  /* Create a graph, add some attributes and save it as a GraphML file */
  igraph_famous(&g, "Petersen");
  SETGAS(&g, "name", "Petersen's graph");
  SETGAN(&g, "vertices", igraph_vcount(&g));
  SETGAN(&g, "edges", igraph_ecount(&g));

  igraph_vector_init_seq(&y, 1, igraph_vcount(&g));
  SETVANV(&g, "id", &y);
  igraph_vector_destroy(&y);

  SETVAS(&g, "name", 0, "foo");
  SETVAS(&g, "name", 1, "foobar");
  
  igraph_vector_init_seq(&y, 1, igraph_ecount(&g));
  SETEANV(&g, "id", &y);
  igraph_vector_destroy(&y);

  SETEAS(&g, "name", 0, "FOO");
  SETEAS(&g, "name", 1, "FOOBAR");

  igraph_write_graph_gml(&g, stdout, 0, "");
  igraph_write_graph_graphml(&g, stdout);
   
  igraph_destroy(&g);
  
  return 0;
}
Exemplo n.º 3
0
int writeGraphToFile(igraph_t *g, char *fileName){

	FILE *stp;
	stp = fopen(fileName, "w");
	if (stp==0) {
		printf("Problema abriendo archivo de grafo writeGraphToFile\n");
		return EXIT_FAILURE;
	}

	igraph_write_graph_gml(g, stp, 0, "gml Test");
	fclose(stp);

	return EXIT_SUCCESS;

}
Exemplo n.º 4
0
int main() {
  
  igraph_t graph ;
  igraph_vector_t dist,order;
   long int i,j,n,c,x,p,y,a,b,d[10];
   printf("Enter total number of nodes.");
   scanf("%li",&n);
   printf("Enter number of children per node.");
   scanf("%li",&c);
  igraph_vector_init(&order, 0);
  igraph_vector_init(&dist, 0);   

  igraph_tree(&graph, (igraph_integer_t)n, (igraph_integer_t)c,IGRAPH_TREE_OUT);
  FILE *fp=fopen("abc.gml","w");
  igraph_write_graph_gml(&graph,fp,0,0);
 long int mat[n][n];
for(i=0;i<n;i++)
{
igraph_bfsr(&graph, /*root=*/(igraph_integer_t)i, /*roots=*/ 0, /*neimode=*/ IGRAPH_ALL, 
       /*unreachable=*/ 1, /*restricted=*/ 0,
       0, 0, 0, 0, 0, &dist, 
       /*callback=*/ 0, /*extra=*/ 0);
for(j=0;j<n;j++)
mat[i][j]=(long int)VECTOR(dist)[j];
}

  flag=1;
  /* Test the callback */
printf("The distance matrix: \n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf("%li ",mat[i][j]);
printf("\n");
}
printf("\nEnter the node for which average is to be computed: ");
scanf("%li",&x);
printf("The order for every call is :\n"); 
y=0;
  for(i=0;i<10;i++)
{
 igraph_bfsr(&graph, /*root=*/0, /*roots=*/ 0, /*neimode=*/ IGRAPH_ALL, 
       /*unreachable=*/ 1, /*restricted=*/ 0,
       &order, 0, 0, 0, 0, 0, 
       /*callback=*/ 0, /*extra=*/ 0);
j=0;p=0;
igraph_vector_print(&order);
while(j<n && (long int)VECTOR(order)[j]!=x)
{
p=p+(mat[(long int)VECTOR(order)[j]][(long int)VECTOR(order)[j+1]]);
j++;
}
d[i]=p;
y=y+p;
}
y=y/10;

printf("The distances for every call are :\n");
for(i=0;i<10;i++)
printf("%li ",d[i]);
printf("\nThe average path length is: %li\n",y);

   igraph_vector_destroy(&dist);
   igraph_destroy(&graph);
  
  return 0;
}