You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

cIGraph_randomisation.c 1.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "igraph.h"
  2. #include "ruby.h"
  3. #include "cIGraph.h"
  4. /* call-seq:
  5. * g.rewire_edges(prob) -> IGraph
  6. *
  7. * Rewire the edges of a graph with constant probability This function
  8. * rewires the edges of a graph with a constant probability. More precisely
  9. * each end point of each edge is rewired to an uniformly randomly chosen
  10. * vertex with constant probability prob.
  11. *
  12. * prob: The rewiring probability a constant between zero and one (inclusive).
  13. */
  14. VALUE cIGraph_rewire_edges(VALUE self, VALUE prop){
  15. igraph_t *graph;
  16. igraph_t *copy_graph;
  17. VALUE new_graph;
  18. new_graph = cIGraph_alloc(cIGraph);
  19. Data_Get_Struct(new_graph, igraph_t, copy_graph);
  20. Data_Get_Struct(self, igraph_t, graph);
  21. igraph_copy(copy_graph,graph);
  22. igraph_rewire_edges(copy_graph,NUM2DBL(prop));
  23. return new_graph;
  24. }
  25. /* call-seq:
  26. * g.rewire(n) -> IGraph
  27. *
  28. * Randomly rewires a graph while preserving the degree distribution.
  29. *
  30. * This function generates a new graph based on the original one by randomly
  31. * rewiring edges while preserving the original graph's degree distribution.
  32. *
  33. * n: Number of rewiring trials to perform.
  34. */
  35. VALUE cIGraph_rewire(VALUE self, VALUE n){
  36. igraph_t *graph;
  37. igraph_t *copy_graph;
  38. VALUE new_graph;
  39. new_graph = cIGraph_alloc(cIGraph);
  40. Data_Get_Struct(new_graph, igraph_t, copy_graph);
  41. Data_Get_Struct(self, igraph_t, graph);
  42. igraph_copy(copy_graph,graph);
  43. igraph_rewire(copy_graph,NUM2INT(n),0);
  44. return new_graph;
  45. }

Ruby binding for the igraph library.