A triangle counting assignment for A.U.TH Parallel and distributed systems class.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

36 Zeilen
722 B

  1. /*!
  2. * \file v12.cpp
  3. * \brief v1 and v2 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 <v12.h>
  12. namespace v12 {
  13. /*!
  14. * A naive triangle counting algorithm
  15. * \param A The adjacency matrix
  16. * \return The number of triangles
  17. */
  18. int triang_count (matrix& A) {
  19. int count =0;
  20. // We use a symmetric matrix so we iterate using the constrain i<j<k
  21. A.for_each_in(0, A.size(), [&](auto i) {
  22. A.for_each_in(i+1, A.size(), [&](auto j) {
  23. A.for_each_in(j+1, A.size(), [&](auto k){
  24. count += (A(i,j) && A(i,k) && A(j,k)) ? 1:0;
  25. });
  26. });
  27. });
  28. return count;
  29. }
  30. }