Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_Graph.cpp
1#include "Teuchos_Graph.hpp"
2
3#include <iostream>
4
5#include "Teuchos_vector.hpp"
6
7namespace Teuchos {
8
9Graph make_graph_with_nnodes(int nnodes) {
10 return Graph(std::size_t(nnodes));
11}
12
13int get_nnodes(Graph const& g) {
14 return Teuchos::size(g);
15}
16
17void add_edge(Graph& g, int i, int j) {
18 at(g, i).push_back(j);
19}
20
21NodeEdges const& get_edges(Graph const& g, int i) {
22 return at(g, i);
23}
24
25NodeEdges& get_edges(Graph& g, int i) {
26 return at(g, i);
27}
28
29int count_edges(const Graph& g, int i) {
30 return Teuchos::size(at(g, i));
31}
32
33Graph make_transpose(Graph const& g) {
34 int nnodes = get_nnodes(g);
35 Graph transpose = make_graph_with_nnodes(nnodes);
36 for (int i = 0; i < nnodes; ++i) {
37 const NodeEdges& edges = get_edges(g, i);
38 for (NodeEdges::const_iterator it = edges.begin(); it != edges.end(); ++it) {
39 int j = *it;
40 add_edge(transpose, j, i);
41 }
42 }
43 return transpose;
44}
45
46int at(Graph const& g, int i, int j) {
47 return at(at(g, i), j);
48}
49
50std::ostream& operator<<(std::ostream& os, Graph const& g) {
51 for (int i = 0; i < get_nnodes(g); ++i) {
52 os << i << ":";
53 const NodeEdges& edges = get_edges(g, i);
54 for (NodeEdges::const_iterator it = edges.begin(); it != edges.end(); ++it) {
55 int j = *it;
56 os << " " << j;
57 }
58 os << '\n';
59 }
60 return os;
61}
62
63}
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...