Commit deaf47f1 authored by Davis King's avatar Davis King

Added the graph_has_symmetric_edges() routine.

parent 4d2d6dda
......@@ -410,6 +410,37 @@ namespace dlib
return (visited.size() == g.number_of_nodes());
}
// ----------------------------------------------------------------------------------------
template <
typename T
>
bool graph_has_symmetric_edges (
const T& graph
)
{
for (unsigned long i = 0; i < graph.number_of_nodes(); ++i)
{
for (unsigned long j = 0; j < graph.node(i).number_of_children(); ++j)
{
const unsigned long jj = graph.node(i).child(j).index();
// make sure every edge from a parent to a child has an edge linking back
if (graph.has_edge(jj,i) == false)
return false;
}
for (unsigned long j = 0; j < graph.node(i).number_of_parents(); ++j)
{
const unsigned long jj = graph.node(i).parent(j).index();
// make sure every edge from a child to a parent has an edge linking back
if (graph.has_edge(i,jj) == false)
return false;
}
}
return true;
}
// ----------------------------------------------------------------------------------------
template <
......
......@@ -81,6 +81,26 @@ namespace dlib
parent node g.node(parent_idx) to child node g.node(child_idx).
!*/
// ----------------------------------------------------------------------------------------
template <
typename T
>
bool graph_has_symmetric_edges (
const T& graph
);
/*!
requires
- T is an implementation of directed_graph/directed_graph_kernel_abstract.h
ensures
- if (All nodes have either 0 edges between them or 2 edges between them.
That is, if there is an edge pointing from node A to node B then there is
also an edge from B to A) then
- returns true
- else
- returns false
!*/
// ----------------------------------------------------------------------------------------
template <
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment