DynamicDirectedGraph Class Reference

Public Member Functions

 DynamicDirectedGraph (int vertices)
 
template<typename Iter >
Iter get_vertices (Iter dest)
 
int no_of_vertices ()
 
template<typename Iter >
Iter adjTo (int vertex, Iter dest)
 
void add_edge (int u, int v)
 
void delete_edge (int u, int v)
 
int in_degree (int vertex)
 
int out_degree (int vertex)
 

Detailed Description

Algorithm

  1. Export the graph object to an adjacency matrix.
  2. Find the vertices which have 0 in-degree.
  3. Add them to a queue.

Servicing a queue

  1. Deque an element off the queue
  2. Remove all the edges emnating from the element.
  3. Add the element to topological order.
  4. For every edge u-v emnating from u : delete_edge(u, v) if(in-degree(v) == 0) add v to the queue. Operations on the graph required. in-degree(v) - Read and write out-degree(v) - Read and write edge deletion adj(v)

Constructor & Destructor Documentation

DynamicDirectedGraph::DynamicDirectedGraph ( int  vertices)
69  {
70 
71  // Initialize total_vertices
72  total_vertices = vertices;
73 
74  // Initialize the adj_matrix to all zeroes
75  vector<int> zeroes(vertices);
76  fill_n(zeroes.begin(), vertices, 0);
77  for(int i = 0; i < vertices; i++)
78  adj_matrix.push_back(zeroes);
79 
80  // Initialize the indeg and outdeg vectors to all zeroes
81  fill_n(back_inserter(indeg), vertices, 0);
82  fill_n(back_inserter(outdeg), vertices, 0);
83 }

Member Function Documentation

void DynamicDirectedGraph::add_edge ( int  u,
int  v 
)
105  {
106 
107  adj_matrix[u][v] = 1;
108  outdeg[u]++;
109  indeg[v]++;
110 }
template<typename Iter >
Iter DynamicDirectedGraph::adjTo ( int  vertex,
Iter  dest 
)
97  {
98  for(int idx = 0; idx < total_vertices; idx++)
99  if(adj_matrix[vertex][idx] == 1)
100  *dest++ = idx;
101  return dest;
102 }
void DynamicDirectedGraph::delete_edge ( int  u,
int  v 
)
112  {
113  adj_matrix[u][v] = 0;
114  outdeg[u]--;
115  indeg[v]--;
116 }
template<typename Iter >
Iter DynamicDirectedGraph::get_vertices ( Iter  dest)
86  {
87  for(int i = 0; i < total_vertices; i++)
88  *dest++ = i;
89  return dest;
90 }
int DynamicDirectedGraph::in_degree ( int  vertex)
118  {
119  return indeg[u];
120 }
int DynamicDirectedGraph::no_of_vertices ( )
92  {
93  return total_vertices;
94 }
int DynamicDirectedGraph::out_degree ( int  vertex)
122  {
123  return outdeg[u];
124 }

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