int main() {
  
  igraph_t graph, ring;
  igraph_vector_t order,order_out, father,dist;
  long int i;
  
  igraph_ring(&ring, 10, /*directed=*/ 0, /*mutual=*/ 0, /*circular=*/ 1);
  igraph_disjoint_union(&graph, &ring, &ring);
  igraph_destroy(&ring);
  
  igraph_vector_init(&order, 0);
  igraph_vector_init(&order_out, 0);
  igraph_vector_init(&father, 0);
  igraph_vector_init(&dist, 0);
  
  igraph_dfsd(&graph, /*root=*/0, /*neimode=*/ IGRAPH_OUT, 
       /*unreachable=*/ 1,&order,&order_out,&father,&dist, 
       /*in_callback=*/ 0,/*out_callback*/0, /*extra=*/ 0);
  
  igraph_vector_print(&order);
  igraph_vector_print(&order_out);
  igraph_vector_print(&father);
  igraph_vector_print(&dist);

  igraph_vector_destroy(&order);
  igraph_vector_destroy(&order_out);
  igraph_vector_destroy(&father);
  igraph_vector_destroy(&dist);

  /* Test the callback */

  igraph_dfsd(&graph, /*root=*/ 0,/*neimode=*/ IGRAPH_OUT, 
       /*unreachable=*/ 1,0, 0, 0, 0,&dfs_callback,0, 0);
  printf("\n");
  
  igraph_dfsd(&graph, /*root=*/ 0,/*neimode=*/ IGRAPH_OUT, 
       /*unreachable=*/ 1,0, 0, 0, 0,0,&dfs_callback, 0);
  printf("\n");
  /* Test different roots */

  igraph_dfsd(&graph, /*root=*/ 2,/*neimode=*/ IGRAPH_OUT, 
       /*unreachable=*/ 1, 0, 0, 0, 0,&dfs_callback,0, 0);
  printf("\n");

  igraph_dfsd(&graph, /*root=*/ 2,/*neimode=*/ IGRAPH_OUT, 
       /*unreachable=*/ 1, 0, 0, 0, 0,0,&dfs_callback,0);
  printf("\n");
  igraph_destroy(&graph);
  
  return 0;
}
Example #2
0
int main() {
  igraph_t graph;
  igraph_t full, tree;
  igraph_hrg_t hrg;
  igraph_t dendrogram;
  // int i, j;
  // igraph_vector_t neis;

  igraph_rng_seed(igraph_rng_default(), 42);

  // We need attributes
  igraph_i_set_attribute_table(&igraph_cattribute_table);
  
  igraph_full(&full, 10, /*directed=*/ 0, /*loops=*/ 0);
  igraph_tree(&tree, 15, /*children=*/ 2, /*type=*/ IGRAPH_TREE_UNDIRECTED);
  igraph_disjoint_union(&graph, &full, &tree);
  igraph_add_edge(&graph, 0, 10);
  
  igraph_destroy(&full);
  igraph_destroy(&tree);

  // Fit
  igraph_hrg_init(&hrg, igraph_vcount(&graph));
  igraph_hrg_fit(&graph, &hrg, /*start=*/ 0, /*steps=*/ 0);

  // Create a graph from it
  igraph_hrg_dendrogram(&dendrogram, &hrg);

  // Print the tree, with labels
  // igraph_vector_init(&neis, 0);
  // for (i=0; i<igraph_vcount(&graph)-1; i++) {
  //   printf("Vertex # %2i, ", (int) (i+igraph_vcount(&graph)));
  //   igraph_neighbors(&dendrogram, &neis, i+igraph_vcount(&graph), IGRAPH_OUT);
  //   printf("left: # %2i, right: # %2i, ", (int) VECTOR(neis)[0], 
  // 	   (int) VECTOR(neis)[1]);
  //   printf("prob: %6.2g\n", 
  // 	   VAN(&dendrogram, "probability", i+igraph_vcount(&graph)));
  // }
  // igraph_vector_destroy(&neis);

  igraph_destroy(&dendrogram);
  igraph_hrg_destroy(&hrg);
  igraph_destroy(&graph);

  return 0;
}
Example #3
0
int main() {
  
  igraph_t graph, ring;
  igraph_vector_t order, rank, father, pred, succ, dist;
  igraph_vector_t restricted;
  igraph_vector_t roots;
  long int i;
  
  igraph_ring(&ring, 10, /*directed=*/ 0, /*mutual=*/ 0, /*circular=*/ 1);
  igraph_disjoint_union(&graph, &ring, &ring);
  igraph_destroy(&ring);
  
  igraph_vector_init(&order, 0);
  igraph_vector_init(&rank, 0);
  igraph_vector_init(&father, 0);
  igraph_vector_init(&pred, 0);
  igraph_vector_init(&succ, 0);
  igraph_vector_init(&dist, 0);
  
  igraph_bfsr(&graph, /*root=*/0, /*roots=*/ 0, /*neimode=*/ IGRAPH_OUT, 
       /*unreachable=*/ 1, /*restricted=*/ 0,
       &order, &rank, &father, &pred, &succ, &dist, 
       /*callback=*/ 0, /*extra=*/ 0);
  
  igraph_vector_print(&order);
  igraph_vector_print(&rank);
  igraph_vector_print(&father);
  igraph_vector_print(&pred);
  igraph_vector_print(&succ);
  igraph_vector_print(&dist);

  igraph_vector_destroy(&order);
  igraph_vector_destroy(&rank);
  igraph_vector_destroy(&father);
  igraph_vector_destroy(&pred);
  igraph_vector_destroy(&succ);
  igraph_vector_destroy(&dist);

  /* Test the callback */

  igraph_bfsr(&graph, /*root=*/ 0, /*roots=*/ 0, /*neimode=*/ IGRAPH_OUT, 
       /*unreachable=*/ 1, /*restricted=*/ 0,
       0, 0, 0, 0, 0, 0, &bfs_callback, 0);
  printf("\n");
  
  /* Test different roots */

  igraph_bfsr(&graph, /*root=*/ 2, /*roots=*/ 0, /*neimode=*/ IGRAPH_OUT, 
       /*unreachable=*/ 1, /*restricted=*/ 0,
       0, 0, 0, 0, 0, 0, &bfs_callback, 0);
  printf("\n");

  /* Test restricted */

  igraph_vector_init(&restricted, 0);
  for (i=5; i<igraph_vcount(&graph); i++) {
    igraph_vector_push_back(&restricted, i);
  }
  igraph_bfsr(&graph, /*root=*/ 5, /*roots=*/ 0, /*neimode=*/ IGRAPH_OUT, 
       /*unreachable=*/ 1, &restricted,
       0, 0, 0, 0, 0, 0, &bfs_callback, 0);
  printf("\n");  

  /* Root not in restricted set */

  igraph_bfsr(&graph, /*root=*/ 4, /*roots=*/ 0, /*neimode=*/ IGRAPH_OUT, 
       /*unreachable=*/ 1, &restricted,
       0, 0, 0, 0, 0, 0, &bfs_callback, 0);
  printf("\n");  

  igraph_bfsr(&graph, /*root=*/ 3, /*roots=*/ 0, /*neimode=*/ IGRAPH_OUT, 
       /*unreachable=*/ 0, &restricted,
       0, 0, 0, 0, 0, 0, &bfs_callback, 0);
  printf("\n");  

  /* Multiple root vertices */

  igraph_vector_init(&roots, 3);
  VECTOR(roots)[0]=3; 
  VECTOR(roots)[1]=4;
  VECTOR(roots)[2]=6;
  igraph_bfsr(&graph, /*root=*/ -1, &roots, /*neimode=*/ IGRAPH_OUT, 
       /*unreachable=*/ 0, &restricted,
       0, 0, 0, 0, 0, 0, &bfs_callback, 0);
  printf("\n");    

  igraph_vector_destroy(&roots);
  igraph_vector_destroy(&restricted);
  igraph_destroy(&graph);
  
  return 0;
}
Example #4
0
Graph Graph::operator+(const Graph& other) const {
    std::auto_ptr<igraph_t> result(new igraph_t);
    IGRAPH_TRY(igraph_disjoint_union(result.get(), m_pGraph, other.m_pGraph));
    return Graph(result.release());
}