Graph.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #include <string>
  3. #include <map>
  4. #include <set>
  5. #include <fstream>
  6. #include <vector>
  7. #include <iostream>
  8. using namespace std;
  9. class Graph_exception {};
  10. class GraphNode {
  11. typedef set<GraphNode*>::const_iterator node_iterator;
  12. private:
  13. string name;
  14. set <GraphNode*> neighbors;
  15. void add_neigbor(GraphNode* neighboor);
  16. void remove_neighbor(GraphNode* neighboor);
  17. public:
  18. GraphNode();
  19. GraphNode(const string& aname);
  20. const string get_name() const;
  21. node_iterator nb_begin() const {
  22. return neighbors.begin();
  23. };
  24. node_iterator nb_end() const {
  25. return neighbors.end();
  26. };
  27. const bool& operator == (const GraphNode& r);
  28. friend class Graph;
  29. };
  30. class Graph
  31. {
  32. typedef set<GraphNode*>::const_iterator node_iterator;
  33. private:
  34. map <string, bool> taken_names;
  35. map <string, GraphNode> saved;
  36. set<GraphNode*> nodes;
  37. void write_graph(vector <vector <node_iterator> > ind);
  38. public:
  39. Graph() {};
  40. void add_node(GraphNode* node);
  41. void remove_node(GraphNode* node);
  42. void add_edge(GraphNode* begin, GraphNode* end);
  43. void remove_edge(GraphNode* begin, GraphNode* end);
  44. static Graph read_file(const string& file_name);
  45. void find_independent_graphs();
  46. node_iterator begin() {
  47. return nodes.begin();
  48. };
  49. node_iterator end() {
  50. return nodes.end();
  51. };
  52. friend class Node;
  53. };