A triangle counting assignment for A.U.TH Parallel and distributed systems class.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

49 linhas
1.1 KiB

  1. /*!
  2. * \file v3.cpp
  3. * \brief vv3 part of the exercise.
  4. *
  5. * \author
  6. * Christos Choutouridis AEM:8997
  7. * <cchoutou@ece.auth.gr>
  8. */
  9. #include <iostream>
  10. #include <random>
  11. #include <v3.h>
  12. namespace v3 {
  13. using index_t = typename matrix::indexType;
  14. using value_t = typename matrix::dataType;
  15. /*!
  16. * A naive triangle counting algorithm
  17. * \param A The adjacency matrix
  18. * \return The number of triangles
  19. */
  20. std::vector<value_t> triang_v(matrix& A) {
  21. std::vector<value_t> c(A.size());
  22. for (int i=0 ; i<A.size() ; ++i) {
  23. for (auto j = A.getCol(i); j.index() != j.end() ; ++j) // j list all the edges with i
  24. for (auto k = A.getCol(j.index()); k.index() != k.end() ; ++k) // k list all the edges with j
  25. for (auto ii = A.getCol(i) ; ii.index() <= k.index() ; ++ii) // search for i-k edge (this could be binary search)
  26. if (ii.index() == k.index()) ++c[i];
  27. }
  28. return c;
  29. }
  30. value_t sum (std::vector<value_t>& v) {
  31. value_t s =0;
  32. for (auto& it : v)
  33. s += it;
  34. return s;
  35. }
  36. value_t triang_count (matrix& A) {
  37. auto v = triang_v(A);
  38. return sum(v);
  39. }
  40. }