Statistics
| Branch: | Revision:

root / custompackages / graph-parser / src / graph_manager.h @ 4ca27bae

History | View | Annotate | Download (2.3 KB)

1 cb770240 Quynh PX Nguyen
//
2
// Created by quynh on 1/15/15.
3
//
4
5
#ifndef GRAPH_PARSER_GRAPH_MANAGER_H
6
#define GRAPH_PARSER_GRAPH_MANAGER_H
7
8
#include "common.h"
9
#include "utility.h"
10
11
class GraphManager {
12
public:
13
    typedef boost::vertex_bundle_type<Graph>::type VertexProperties; // aka Router in common.h
14
    typedef boost::edge_bundle_type<Graph>::type EdgeProperties; // aka Link in common.h
15
    typedef std::map<std::string, Vertex> NameVertexMap;
16
17 437fd680 Quynh PX Nguyen
    // CONSTRUCTOR
18 d5b7a27f Quynh PX Nguyen
    GraphManager(bool weighted_graph=true); // constructor
19 cb770240 Quynh PX Nguyen
    GraphManager(const GraphManager& other); // copy constructor
20 d5b7a27f Quynh PX Nguyen
    GraphManager& operator=(const GraphManager& rhs); // assignment operator
21 cb770240 Quynh PX Nguyen
    // check out more here: http://www.cplusplus.com/articles/y8hv0pDG/
22
23 437fd680 Quynh PX Nguyen
    // GETTERS
24
    const VertexIndexPMap& v_index_pmap() const;
25
    const EdgeIndexPMap& e_index_pmap() const;
26
    NameToIntMap const& v_id_index_map() const;
27 d5b7a27f Quynh PX Nguyen
    bool weighted_graph() const;
28 437fd680 Quynh PX Nguyen
29
    // UPDATE GRAPH
30 cb770240 Quynh PX Nguyen
    void AddEdge(VertexProperties vp1, VertexProperties vp2, EdgeProperties ep);
31 437fd680 Quynh PX Nguyen
    void ResetVerticesAndEdgesIndexMap();
32
33
    // HELPERS
34 cb770240 Quynh PX Nguyen
    bool vertex_existed(string s);
35
    const Vertex& get_vertex_from_id(string s);
36 437fd680 Quynh PX Nguyen
    int get_index_from_id(string s);
37 cb770240 Quynh PX Nguyen
38 437fd680 Quynh PX Nguyen
    // OUTPUTTING THE RESULT
39 cb770240 Quynh PX Nguyen
    // TODO: checkout utility.h, I can't overload << operator to output
40
    // the correct result. Therefore, I use print() ufnction as a replacement.
41 437fd680 Quynh PX Nguyen
    void print();
42
    void print_v_index_pmap();
43
    void print_e_index_pmap();
44 cb770240 Quynh PX Nguyen
    friend std::ostream& operator<<(std::ostream& os, const GraphManager& gm);
45
46 437fd680 Quynh PX Nguyen
    // Variables
47 cb770240 Quynh PX Nguyen
    Graph g_;
48
private:
49 437fd680 Quynh PX Nguyen
    void reset_v_index_pmap();
50 cb770240 Quynh PX Nguyen
    void reset_v_id_vertex_map();
51 437fd680 Quynh PX Nguyen
    void reset_v_id_index_map(); // must be called after reset_v_index_pmap()
52
53
    void reset_e_index_pmap();
54
    void update_v_index_pmap(Vertex new_vertex);
55
    void update_e_index_pmap(Edge new_edge);
56 cb770240 Quynh PX Nguyen
57 437fd680 Quynh PX Nguyen
    // VARIABLES
58 d5b7a27f Quynh PX Nguyen
    bool weighted_graph_;
59
60 cb770240 Quynh PX Nguyen
    NameVertexMap v_id_vertex_map_;
61 437fd680 Quynh PX Nguyen
    NameToIntMap v_id_index_map_;
62 cb770240 Quynh PX Nguyen
63 437fd680 Quynh PX Nguyen
    // VertexIndexPMap - since we use listS instead of vecS in Graph, this one maps each vertex to an id
64 cb770240 Quynh PX Nguyen
    VertexIndexStdMap v_index_std_map_;
65 437fd680 Quynh PX Nguyen
    VertexIndexPMap v_index_pmap_; //
66 cb770240 Quynh PX Nguyen
67 437fd680 Quynh PX Nguyen
    // EdgeIndexPMap - boost will return the component id that each edge in the graph belongs to.
68 cb770240 Quynh PX Nguyen
    EdgeIndexStdMap e_index_std_map_;
69 437fd680 Quynh PX Nguyen
    EdgeIndexPMap e_index_pmap_;
70 cb770240 Quynh PX Nguyen
};
71
72
#endif //GRAPH_PARSER_GRAPH_MANAGER_H