operations.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "io.h"
  2. #include "operations.h"
  3. #include "graph.h"
  4. void graph_union(graph_t *result, igraph_vector_ptr_t *glist) {
  5. igraph_union_many(result->graph, glist);
  6. result->initialised = 1;
  7. }
  8. void graph_intersection(graph_t *result, igraph_vector_ptr_t *glist) {
  9. igraph_intersection_many(result->graph, glist);
  10. result->initialised = 1;
  11. }
  12. void graph_xor(graph_t *result, igraph_vector_ptr_t *glist) {
  13. if(igraph_vector_ptr_size(glist) < 2) return;
  14. igraph_t prev, res_left, res_right, res_union;
  15. igraph_copy(&prev, igraph_vector_ptr_e(glist, 0));
  16. long int n;
  17. for(n = 1; n < igraph_vector_ptr_size(glist); ++n) {
  18. igraph_difference(&res_left, &prev, igraph_vector_ptr_e(glist, n));
  19. igraph_difference(&res_right, igraph_vector_ptr_e(glist, n), &prev);
  20. igraph_union(&res_union, &res_left, &res_right);
  21. igraph_destroy(&prev);
  22. igraph_copy(&prev, &res_union);
  23. igraph_destroy(&res_left);
  24. igraph_destroy(&res_right);
  25. igraph_destroy(&res_union);
  26. }
  27. result->initialised = 1;
  28. igraph_copy(result->graph, &prev);
  29. igraph_destroy(&prev);
  30. }
  31. void graph_noop(graph_t *result, igraph_vector_ptr_t *glist) {
  32. // Dummy function in case we just want to convert an input graph to a different format.
  33. }
  34. void graph_operation_error(graph_t *result, igraph_vector_ptr_t *glist) {
  35. fprintf(ost, "Unknown graph operation specified.\n");
  36. }