A triangle counting assignment for A.U.TH Parallel and distributed systems class.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- /*!
- * \file v3.cpp
- * \brief vv3 part of the exercise.
- *
- * \author
- * Christos Choutouridis AEM:8997
- * <cchoutou@ece.auth.gr>
- */
-
- #include <iostream>
- #include <random>
- #include <v3.h>
-
- namespace v3 {
-
- using index_t = typename matrix::indexType;
- using value_t = typename matrix::dataType;
-
- /*!
- * A naive triangle counting algorithm
- * \param A The adjacency matrix
- * \return The number of triangles
- */
- std::vector<value_t> triang_v(matrix& A) {
- std::vector<value_t> c(A.size());
-
- for (int i=0 ; i<A.size() ; ++i) {
- for (auto j = A.getCol(i); j.index() != j.end() ; ++j) // j list all the edges with i
- for (auto k = A.getCol(j.index()); k.index() != k.end() ; ++k) // k list all the edges with j
- for (auto ii = A.getCol(i) ; ii.index() <= k.index() ; ++ii) // search for i-k edge (this could be binary search)
- if (ii.index() == k.index()) ++c[i];
- }
- return c;
- }
-
- value_t sum (std::vector<value_t>& v) {
- value_t s =0;
- for (auto& it : v)
- s += it;
- return s;
- }
-
- value_t triang_count (matrix& A) {
- auto v = triang_v(A);
- return sum(v);
- }
-
- }
|