Example #1
0
int main() {

  igraph_t g;
  int ret;

  igraph_atlas(&g, 45);
  igraph_write_graph_edgelist(&g, stdout);
  printf("\n");
  igraph_destroy(&g);

  igraph_atlas(&g, 0);
  igraph_write_graph_edgelist(&g, stdout);
  printf("\n");
  igraph_destroy(&g);

  igraph_atlas(&g, 1252);
  igraph_write_graph_edgelist(&g, stdout);
  printf("\n");
  igraph_destroy(&g);

  igraph_set_error_handler(igraph_error_handler_ignore);
  ret=igraph_atlas(&g, -1);
  if (ret != IGRAPH_EINVAL) {
    return 1;
  }

  ret=igraph_atlas(&g, 1253);
  if (ret != IGRAPH_EINVAL) {
    return 2;
  }

  return 0;
}
int main() {
  
  const char *files[] = { "fullmatrix1.dl", "fullmatrix2.dl", 
			  "fullmatrix3.dl", "fullmatrix4.dl",
			  "edgelist1.dl", "edgelist2.dl", "edgelist3.dl",
			  "edgelist4.dl", "edgelist5.dl", "edgelist6.dl",
			  "nodelist1.dl", "nodelist2.dl" };
  int no_files=sizeof(files)/sizeof(const char*);
  int i, ret;
  igraph_t g;
  FILE *infile;

  for (i=0; i<no_files; i++) {
    printf("Doing %s\n", files[i]);
    infile=fopen(files[i], "r");
    if (!infile) {
      printf("Cannot open file: %s\n", files[i]);
      exit(1+i);
    }
    igraph_read_graph_dl(&g, infile, /*directed=*/ 1);
    ret=fclose(infile);
    if (ret) {
      printf("Cannot close file: %s\n", files[i]);
      exit(11+i);
    }
    igraph_write_graph_edgelist(&g, stdout);
    igraph_destroy(&g);
  }

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

  return 0;
}
Example #3
0
void dump_graph(const char* header, const igraph_t* g) {
  fputs(header, stdout);
  printf("Vertices: %li\n", (long int) igraph_vcount(g));
  printf("Edges: %li\n", (long int) igraph_ecount(g));
  printf("Directed: %i\n", (int) igraph_is_directed(g));
  igraph_write_graph_edgelist(g, stdout);
}
int main() {
  
  igraph_t g;
  
  igraph_small(&g, 0, IGRAPH_DIRECTED, 0,1, 1,2, 2,3, 3,4, 6,1, -1);
  igraph_write_graph_edgelist(&g, stdout);
  igraph_destroy(&g);
  
  return 0;
}
Example #5
0
int check_lattice(const lat_test_t *test) {
  igraph_t graph, othergraph;
  igraph_vector_t otheredges;
  igraph_vector_t dimvector;
  igraph_bool_t iso;
  int ret;  
    
  /* Create lattice */
  igraph_vector_view(&dimvector, test->dimedges, test->dim);
  igraph_lattice(&graph, &dimvector, test->nei, test->directed,
		 test->mutual, test->circular);

  /* Check its properties */
  if ((ret=check_lattice_properties(&graph, &dimvector, test->directed, 
				    test->mutual, test->circular))) {
    igraph_destroy(&graph);
    printf("Lattice properties are not satisfied\n");
    return ret;
  }
  
  /* Check that it is isomorphic to the stored graph */
  igraph_vector_view(&otheredges, test->dimedges+test->dim, test->m * 2);
  igraph_create(&othergraph, &otheredges, igraph_vector_prod(&dimvector),
		test->directed);
  igraph_isomorphic(&graph, &othergraph, &iso);
  if (!iso) {
    printf("--\n");
    igraph_write_graph_edgelist(&graph, stdout);
    printf("--\n");
    igraph_write_graph_edgelist(&othergraph, stdout);
    igraph_destroy(&graph);
    igraph_destroy(&othergraph);
    return 50;    
  }  

  igraph_destroy(&graph);
  igraph_destroy(&othergraph);
  return 0;
}
int main() {
  
  igraph_t g, tree;
  igraph_vector_t eb, edges;
  long int i;
  
  igraph_small(&g, 0, IGRAPH_UNDIRECTED, 
	       0,  1,  0,  2,  0,  3,  0,  4,  0,  5,
	       0,  6,  0,  7,  0,  8,  0, 10,  0, 11,
	       0, 12,  0, 13,  0, 17,  0, 19,  0, 21,
	       0, 31,  1,  2,  1,  3,  1,  7,  1, 13,
	       1, 17,  1, 19,  1, 21,  1, 30,  2,  3,
	       2,  7,  2,  8,  2,  9,  2, 13,  2, 27,
	       2, 28,  2, 32,  3,  7,  3, 12,  3, 13,
	       4,  6,  4, 10,  5,  6,  5, 10,  5, 16,
	       6, 16,  8, 30,  8, 32,  8, 33,  9, 33,
	       13, 33, 14, 32, 14, 33, 15, 32, 15, 33,
	       18, 32, 18, 33, 19, 33, 20, 32, 20, 33,
	       22, 32, 22, 33, 23, 25, 23, 27, 23, 29,
	       23, 32, 23, 33, 24, 25, 24, 27, 24, 31,
	       25, 31, 26, 29, 26, 33, 27, 33, 28, 31,
	       28, 33, 29, 32, 29, 33, 30, 32, 30, 33,
	       31, 32, 31, 33, 32, 33,
	       -1);
  
  igraph_vector_init(&eb, igraph_ecount(&g));
  igraph_edge_betweenness(&g, &eb, IGRAPH_UNDIRECTED, /*weights=*/ 0);
  for (i=0; i<igraph_vector_size(&eb); i++) {
    VECTOR(eb)[i] = -VECTOR(eb)[i];
  }

  igraph_minimum_spanning_tree_prim(&g, &tree, &eb);
  igraph_write_graph_edgelist(&tree, stdout);

  igraph_vector_init(&edges, 0);
  igraph_minimum_spanning_tree(&g, &edges, &eb);
  igraph_vector_print(&edges);
  igraph_vector_destroy(&edges);

  igraph_destroy(&tree);
  igraph_destroy(&g);
  igraph_vector_destroy(&eb);
  
  return 0;
}
Example #7
0
int main(int argc, char **argv) {

  igraph_t g;
  FILE *ifile;

  /* PAJEK */
  ifile=fopen("LINKS.NET", "r");
  if (ifile==0) {
    return 10;
  }
  igraph_read_graph_pajek(&g, ifile);
  fclose(ifile);
  printf("The graph:\n");
  printf("Vertices: %li\n", (long int) igraph_vcount(&g));
  printf("Edges: %li\n", (long int) igraph_ecount(&g));
  printf("Directed: %i\n", (int) igraph_is_directed(&g));
  igraph_write_graph_edgelist(&g, stdout);
  igraph_destroy(&g);
  return 0;
}
int main() {

  igraph_t g;

  /* Multiple edges */

  igraph_small(&g, 0, IGRAPH_DIRECTED, 0,1, 0,1, 0,1, 0,1, 0,1, -1);
  igraph_simplify(&g, 1, 1);
  igraph_write_graph_edgelist(&g, stdout);
  igraph_destroy(&g);
  
  igraph_small(&g, 0, IGRAPH_UNDIRECTED, 1,0, 0,1, 1,0, 0,1, 0,1, -1);
  igraph_simplify(&g, 1, 1);
  if (igraph_ecount(&g) != 1) {
    return 1;
  }
  igraph_destroy(&g);
  
  /* Loop edges*/
  
  igraph_small(&g, 0, IGRAPH_DIRECTED, 0,0,1,1,2,2, 1,2, -1);
  igraph_simplify(&g, 1, 1);
  igraph_write_graph_edgelist(&g, stdout);
  igraph_destroy(&g);

  igraph_small(&g, 0, IGRAPH_UNDIRECTED, 0,0,1,1,2,2, 1,2, -1); 
  igraph_simplify(&g, 1, 1);
  igraph_write_graph_edgelist(&g, stdout);
  igraph_destroy(&g);

  /* Loop & multiple edges */
  
  igraph_small(&g, 0, IGRAPH_DIRECTED, 0,0,0,0,0,0,0,0, 1,2, -1);
  igraph_simplify(&g, 1 /* multiple */, 0 /* loop */);
  igraph_write_graph_edgelist(&g, stdout);
  igraph_destroy(&g);

  igraph_small(&g, 0, IGRAPH_UNDIRECTED, 1,1,1,1,1,1,1,1, 2,3, -1); 
  igraph_simplify(&g, 1 /* multiple */, 0 /* loop */);
  igraph_write_graph_edgelist(&g, stdout);
  igraph_destroy(&g);

  igraph_small(&g, 0, IGRAPH_DIRECTED, 2,2,2,2,2,2, 3,2, -1);
  igraph_simplify(&g, 0 /* multiple */, 1 /* loop */);
  igraph_write_graph_edgelist(&g, stdout);
  igraph_destroy(&g);

  igraph_small(&g, 0, IGRAPH_UNDIRECTED, 3,3,3,3, 3,4, -1);
  igraph_simplify(&g, 0 /* multiple */, 1 /* loop */);
  igraph_write_graph_edgelist(&g, stdout);
  igraph_destroy(&g);  

  igraph_small(&g, 0, IGRAPH_DIRECTED, 2,2,2,2,2,2,2,2, 3,2,3,2,3,2,3,2,3,2,-1);
  igraph_simplify(&g, 1, 1);
  igraph_write_graph_edgelist(&g, stdout);
  igraph_destroy(&g);

  igraph_small(&g, 0, IGRAPH_UNDIRECTED, 
	       2,2,2,2,2,2,2,2, 3,2,2,3,3,2,3,2,3,2,-1);
  igraph_simplify(&g, 1, 1);
  if (igraph_ecount(&g) != 1) { 
    return 2;
  }
  igraph_destroy(&g);

  return 0;
}
Example #9
0
void write_edgelist(FILE* outstream, const Graph& graph) {
    IGRAPH_TRY(igraph_write_graph_edgelist(graph.c_graph(), outstream));
}