Ejemplo 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;
}
int main() {
  igraph_t g;
  igraph_matrix_t mat;
  int m[4][4] = { { 0, 1, 2, 0 }, { 2, 0, 0, 1 }, { 0, 0, 1, 0 }, { 0, 1, 0, 0 } };
  long int i, j;

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

  /* [ 0 1 2 0 ]
     [ 2 0 0 1 ]
     [ 0 0 1 0 ]
     [ 0 1 0 0 ] */
  igraph_weighted_adjacency(&g, &mat, IGRAPH_ADJ_DIRECTED, 0);
  print(&g);
  igraph_destroy(&g);

  /* [ 0 1 2 0 ]
     [ - 0 0 1 ]
     [ - - 1 0 ]
     [ - - - 0 ] */
  igraph_weighted_adjacency(&g, &mat, IGRAPH_ADJ_UPPER, 0);
  print(&g);
  igraph_destroy(&g);

  /* [ 0 - - - ]
     [ 2 0 - - ]
     [ 0 0 1 - ]
     [ 0 1 0 0 ] */
  igraph_weighted_adjacency(&g, &mat, IGRAPH_ADJ_LOWER, 0);
  print(&g);
  igraph_destroy(&g);

  /* [ 0 1 0 0 ]
     [ 1 0 0 1 ]
     [ 0 0 1 0 ]
     [ 0 1 0 0 ] */
  igraph_weighted_adjacency(&g, &mat, IGRAPH_ADJ_MIN, 0);
  print(&g);
  igraph_destroy(&g);

  /* [ 0 2 2 0 ]
     [ 2 0 0 1 ]
     [ 2 0 1 0 ]
     [ 0 1 0 0 ] */
  igraph_weighted_adjacency(&g, &mat, IGRAPH_ADJ_MAX, 0);
  print(&g);
  igraph_destroy(&g);

  /* [ 0 3 2 0 ]
     [ 3 0 0 2 ]
     [ 2 0 1 0 ]
     [ 0 2 0 0 ] */
  igraph_weighted_adjacency(&g, &mat, IGRAPH_ADJ_PLUS, 0);
  print(&g);
  igraph_destroy(&g);

  igraph_matrix_destroy(&mat);

  if (IGRAPH_FINALLY_STACK_SIZE() != 0) return 1;

  return 0;
}