/* Cycle detector that returns a list of
* edges involved in cycles in a digraph.
*
* Kieran Simpson 2006
*/
#include <iostream>
#include <stack>
#include <vector>
#include <cassert>
#include <cycle_detector.h>
#define VISIT_DEBUG
#define RUN_DEBUG
using namespace std;
using namespace cola;
// a global var representing time
this->V = numVertices;
// make the adjacency matrix
this->make_matrix();
}
CycleDetector::~CycleDetector() {
delete nodes;
}
}
delete nodes;
}
// we should not have an empty array
// from the edges passed, fill the adjacency matrix
// the matrix is indexed by the first vertex of the edge
// the second vertex of the edge is pushed onto another
// vector of all vertices connected to the first vertex
// with a directed edge
#ifdef ADJMAKE_DEBUG
#endif
#ifdef ADJMAKE_DEBUG
#endif
}
else {
}
// check if the destination vertex exists in the nodes map
#ifdef ADJMAKE_DEBUG
#endif
}
}
// the following block is code to print out
// the adjacency matrix.
#ifdef ADJMAKE_DEBUG
else {
}
}
#endif
}
// make a copy of the graph to ensure that we have visited all
// vertices
#ifdef SETUP_DEBUG
}
#endif
// find the cycles
// while we still have vertices to visit, visit.
// mark any vertices seen in a previous run as closed
#ifdef RUN_DEBUG
#endif
}
#ifdef VISIT_DEBUG
#endif
Time = 0;
// go go go
}
// clean up
return cyclicEdgesMapping;
}
this->V = numVertices;
// remake the adjaceny matrix
this->make_matrix();
}
unsigned cycleOpen;
// state that we have seen this vertex
#ifdef VISIT_DEBUG
#endif
}
// set up this node as being visited.
// traverse to all the vertices adjacent to this vertex.
// visit this node
#ifdef VISIT_DEBUG
#endif
}
// if we are part of a cycle get the timestamp of the ancestor
// else just get the timestamp of the node we just visited
// compare the stamp of the traversal with our stamp
// store the cycle
#ifdef OUTPUT_DEBUG
#endif
}
// this node is part of a cycle
// see if we are part of a cycle with a cyclicAncestor that possesses a lower timestamp
if (otherNode->cyclicAncestor->stamp < thisNode->cyclicAncestor->stamp) { thisNode->cyclicAncestor = otherNode->cyclicAncestor; }
}
}
}
}
// determines whether or not a vertex is a sink
// a vertex is a sink if it has no outgoing edges,
// or that the adj entry is empty
else { return false; }
}
for (unsigned i = 0; i < this->V; i++) {
}
}
return false;
}
pair< bool, vector<unsigned>::iterator > CycleDetector::find_node(std::vector<unsigned>& list, unsigned k) {
}
}