Graph
Public Member Functions | Friends | List of all members
graph Class Reference

#include <graph.h>

Public Member Functions

 graph (const std::string &file_name)
 Reads edges for graph from file. More...
 
 graph (graph const &org)=default
 
graphoperator= (graph const &rhs)=default
 
std::vector< std::vector< unsigned int > > get_node2nodes () const
 
size_t Nedges () const
 
size_t Nvertices () const
 

Friends

std::ostream & operator<< (std::ostream &s, graph const &rhs)
 

Detailed Description

A simple graph class that requires a consecutive numbering of the vertices starting from 0.

Definition at line 12 of file graph.h.

Constructor & Destructor Documentation

graph::graph ( const std::string &  file_name)

Reads edges for graph from file.

If the file file_name does not exist then the code stops with an appropriate message.

A consecutive numbering of the vertices is required.

Parameters
[in]file_namename of the ASCII-file
graph::graph ( graph const &  org)
default

Member Function Documentation

vector< vector< unsigned int > > graph::get_node2nodes ( ) const

Determines the neighboring vertices for each node from the edge definition. The node itself is not contained in the neighboring vertices.

Returns
vector[nn][*] with all neighboring vertices for each node

Definition at line 42 of file graph.cpp.

43 {
44  size_t nnode=Nvertices();
45 
46  // Determine the neighborhood for each vertex
47  vector<vector<unsigned int>> n2n(nnode);
48  for (size_t k=0; k<_edges.size(); ++k)
49  {
50  const int v0 = _edges[k][0];
51  const int v1 = _edges[k][1];
52  n2n.at(v0).push_back(v1); // add v1 to neighborhood of v0
53  n2n.at(v1).push_back(v0); // and vice versa
54  }
55  // ascending sort of entries per node
56  for (size_t k=0; k<n2n.size(); ++k)
57  {
58  sort(n2n[k].begin(),n2n[k].end());
59  }
60 
61 
62  return n2n;
63 }
size_t Nvertices() const
Definition: graph.h:46
size_t graph::Nedges ( ) const
inline
Returns
number of edges

Definition at line 38 of file graph.h.

39  {
40  return _edges.size();
41  }
size_t graph::Nvertices ( ) const
inline
Returns
number of vertices

Definition at line 46 of file graph.h.

47  {
48  return _nvert;
49  }
graph& graph::operator= ( graph const &  rhs)
default

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  s,
graph const &  rhs 
)
friend

The documentation for this class was generated from the following files: