Version: 1.0
drag_statistics.h
Go to the documentation of this file.
1 // Copyright (c) 2020, the GRAPHGEN contributors, as
2 // shown by the AUTHORS file. All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
6 
7 #ifndef GRAPHGEN_DRAG_STATISTICS_H_
8 #define GRAPHGEN_DRAG_STATISTICS_H_
9 
10 #include <iostream>
11 #include <set>
12 
13 #include "conact_tree.h"
14 
23  std::set<const BinaryDrag<conact>::node*> visited_nodes;
24  std::set<const BinaryDrag<conact>::node*> visited_leaves;
25 
26  void PerformStatistics(const BinaryDrag<conact>::node *n) {
27  if (n->isleaf()) {
28  visited_leaves.insert(n);
29  return;
30  }
31 
32  if (visited_nodes.insert(n).second) {
33  PerformStatistics(n->left);
34  PerformStatistics(n->right);
35  }
36  }
37 
38 public:
44  for (const auto& t : bd.roots_) {
45  PerformStatistics(t);
46  }
47  }
48 
53  auto Nodes() const { return visited_nodes.size(); }
54 
59  auto Leaves() const { return visited_leaves.size(); }
60 
67  void PrintLeaves(std::ostream& os = std::cout) {
68  for (const auto& l : visited_leaves) {
69  if (l->isleaf()) {
70  for (const auto& a : l->data.actions()) {
71  os << a << " ";
72  }
73  os << "- " << l->data.next << "\n";
74  }
75  }
76  os << "----------------------------------\n";
77  }
78 };
79 
85 void PrintStats(const BinaryDrag<conact>& bd, std::ostream& os = std::cout);
86 
87 #endif // !GRAPHGEN_DRAG_STATISTICS_H_
A BinaryDrag is the GRAPHGEN implementation of a Binary Directed Rooted Acyclic Graph (DRAG in short)
Definition: drag.h:28
std::vector< node * > roots_
Definition: drag.h:58
Calculates the statistics of a binary drag with one or multiple roots.
auto Nodes() const
Returns the number of unique nodes inside the DRAG.
void PrintLeaves(std::ostream &os=std::cout)
Reverse into the specified output stream the unique leaves of a BinaryDrag.
BinaryDragStatistics(const BinaryDrag< conact > &bd)
The constructor creates the object and directly calculates the statistics.
auto Leaves() const
Returns the number of unique leaves inside the DRAG.
void PrintStats(const BinaryDrag< conact > &bd, std::ostream &os=std::cout)
Displays on the specified output stream the statistics of a DRAG (number of unique nodes an unique le...