/* * File: undr_graph.hpp * Author: Ajith John * * Created on 10 November, 2014 */ #ifndef UNDRGRAPH_HPP #define UNDRGRAPH_HPP #include #include #include #include #include #include #include #include //#define DEBUG_UNDRGRAPH using namespace std; // Class for an undirected graph class UndrGraph { int V; // No. of vertices vector< list > adj; // Vector of adjacency lists vector< double > weight; // weights of vertices bool isCyclicUtil(int v, vector &visited, int parent, set &disabled_nodes); bool findSemiDisjointCycleUtil(int v, vector &visited, int parent, list &semi_disjoint_cycle, stack &mystack); bool edgeExists(int v, int w); // returns true if edge exists between v and w bool obtainCycleFromStack(stack &mystack, list &cycle, int end); bool cycleIsSemidisjoint(list &cycle); void findNeighbours(int v, set &neighbours); bool deleteEdge(int v, int w); void initializeWeights(double wt); // set the weights of all vertices to wt void showMySet(set &integer_set, string who_am_i); void showMyList(list &integer_list, string who_am_i); public: UndrGraph(int V); // Constructor void addEdge(int v, int w); // to add an edge to graph bool isCyclic(set &disabled_nodes); // returns true if there is a cycle bool isFVS(set &fvs); // returns true if the parameter is an fvs bool findSemiDisjointCycle(list &semi_disjoint_cycle); // finds a semi-disjoint cycle in semi_disjoint_cycle; returns false if semi-disjoint cycle does not exist void cleanup(); void showGraph(); bool empty(); void findCandidateFVS(set &candidate_fvs, stack &fvs_stack); // first loop in Bafna's algorithm to find FVS int degree(int v); void deleteVertex(int v); int size(); bool deadNodes(set &dead_nodes); // find the dead nodes i.e. nodes with no edges in the graph. returns true if all the nodes are dead; else returns false int findCentreNodeOfTree(int u, vector &visited); bool locateCentreNodeInAPathInTree(int current, int parent, int diameter, int path_end, int ¢re, stack &path_stack); void findFarthestNodeInTree(int current, int parent, int depth, int &deepest, int &maximum_depth, vector &visited); }; #endif /* UNDRGRAPH_HPP */