Statistics
| Branch: | Revision:

root / custompackages / graph-parser / src / graph_manager.h @ d5b7a27f

History | View | Annotate | Download (2.3 KB)

1
//
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
    // CONSTRUCTOR
18
    GraphManager(bool weighted_graph=true); // constructor
19
    GraphManager(const GraphManager& other); // copy constructor
20
    GraphManager& operator=(const GraphManager& rhs); // assignment operator
21
    // check out more here: http://www.cplusplus.com/articles/y8hv0pDG/
22

    
23
    // GETTERS
24
    const VertexIndexPMap& v_index_pmap() const;
25
    const EdgeIndexPMap& e_index_pmap() const;
26
    NameToIntMap const& v_id_index_map() const;
27
    bool weighted_graph() const;
28

    
29
    // UPDATE GRAPH
30
    void AddEdge(VertexProperties vp1, VertexProperties vp2, EdgeProperties ep);
31
    void ResetVerticesAndEdgesIndexMap();
32

    
33
    // HELPERS
34
    bool vertex_existed(string s);
35
    const Vertex& get_vertex_from_id(string s);
36
    int get_index_from_id(string s);
37

    
38
    // OUTPUTTING THE RESULT
39
    // TODO: checkout utility.h, I can't overload << operator to output
40
    // the correct result. Therefore, I use print() ufnction as a replacement.
41
    void print();
42
    void print_v_index_pmap();
43
    void print_e_index_pmap();
44
    friend std::ostream& operator<<(std::ostream& os, const GraphManager& gm);
45

    
46
    // Variables
47
    Graph g_;
48
private:
49
    void reset_v_index_pmap();
50
    void reset_v_id_vertex_map();
51
    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

    
57
    // VARIABLES
58
    bool weighted_graph_;
59

    
60
    NameVertexMap v_id_vertex_map_;
61
    NameToIntMap v_id_index_map_;
62

    
63
    // VertexIndexPMap - since we use listS instead of vecS in Graph, this one maps each vertex to an id
64
    VertexIndexStdMap v_index_std_map_;
65
    VertexIndexPMap v_index_pmap_; //
66

    
67
    // EdgeIndexPMap - boost will return the component id that each edge in the graph belongs to.
68
    EdgeIndexStdMap e_index_std_map_;
69
    EdgeIndexPMap e_index_pmap_;
70
};
71

    
72
#endif //GRAPH_PARSER_GRAPH_MANAGER_H
73