Revision 437fd680 custompackages/graph-parser/src/utility.cpp

View differences:

custompackages/graph-parser/src/utility.cpp
12 12
                "---------- " << boost::num_vertices(g) << " vertices\n"
13 13
                "---------- " << boost::num_edges(g) << " edges\n";
14 14

  
15
        std::set<std::string> verticesSet;
16
        BGL_FORALL_VERTICES_T(v, g, Graph) verticesSet.insert(g[v].id);
15
        std::vector<std::string> verticesVec;
16
        BGL_FORALL_VERTICES(v, g, Graph) verticesVec.push_back(g[v].id);
17 17

  
18 18
        std::vector<std::string> edgesVec;
19 19
        std::vector<double> costsVec;
20
        BGL_FORALL_EDGES_T(e, g, Graph) {
20
        BGL_FORALL_EDGES(e, g, Graph) {
21 21
            std::string s = "(" + g[e.m_source].id + ", " + g[e.m_target].id + ") - " + std::to_string(g[e].cost);
22 22
            edgesVec.push_back(s);
23 23
            costsVec.push_back(g[e].cost);
......
26 26
        using namespace boost::spirit::karma;
27 27
        os <<   "Vertices:\n"
28 28
                "  ";
29
        os << format("(" << auto_ % ", " << ") ", verticesSet);
29
        os << format("(" << auto_ % ", " << ") ", verticesVec);
30 30
        os << "\n";
31 31

  
32 32
        os <<   "Edges:\n";
......
36 36
        return os;
37 37
    }
38 38

  
39
    std::ostream& operator<<(std::ostream& os, std::pair<const Graph&, const VertexIndexMap&> p) {
39
    std::ostream& operator<<(std::ostream& os, std::pair<const Graph&, const VertexIndexPMap&> p) {
40 40
        // ERROR: wrong output.
41 41
        // I think it's because of copy constructor.
42 42
        // Check out shell_output/w14
43 43

  
44 44
        // Calling example:
45
        // outops::operator<<(cout, std::pair<const Graph&, const VertexIndexMap&>(g_, v_index_map_));
45
        // outops::operator<<(cout, std::pair<const Graph&, const VertexIndexPMap&>(g_, v_index_pmap_));
46 46
        Graph g = p.first;
47
        VertexIndexMap v_index_map = p.second;
47
        VertexIndexPMap v_index_map = p.second;
48 48

  
49 49
        std::list<std::string> outputs;
50 50
        BGL_FORALL_VERTICES_T(v, g, Graph) {
......
62 62
        return os;
63 63
    }
64 64

  
65
    std::ostream& operator<<(std::ostream& os, const std::map<string, int>& m) {
66
        // similar to printhelper::for_map()
67
        os << "cout << std::map\n";
68
        std::map<string, int>::const_iterator iter;
69
        for (iter = m.begin(); iter != m.end(); ++iter) {
70
            os << (*iter).first << ": " << (*iter).second << endl;
71
        }
72
        os << endl;
73

  
74
        return os;
75
    }
76

  
77 65
    std::ostream& operator<<(std::ostream& os, const vector< vector< int> >& data) {
78 66
        cout << "cout << vector<vector<int> >\n";
79 67
        int row_size = data.size();
......
113 101
        cout << format("[\n  " << (auto_ % "\n  ") << "\n]\n", outputs);
114 102
    }
115 103

  
116
    void print_v_index_map(const Graph& g, const VertexIndexMap& v_index_map) {
117
        cout << "Vertex Index Map:\n";
118

  
104
    void print_v_index_pmap(const Graph& g, const VertexIndexPMap& v_index_pmap) {
119 105
        std::list<std::string> outputs;
120 106
        BGL_FORALL_VERTICES_T(v, g, Graph) {
121
            int index = boost::get(v_index_map, v);
107
            int index = boost::get(v_index_pmap, v);
122 108
            std::string vertex_id = g[v].id;
123
            cout << v << endl;
109
            // Uncomment to print the address of vertex v
110
            // cout << v << endl;
124 111
            outputs.push_back(vertex_id + ": " + std::to_string(index));
125 112
        }
126 113

  
127 114
        using namespace boost::spirit::karma;
115
        cout << "Vertex Index Map:\n";
116
        cout << format("[\n  " << (auto_ % "\n  ") << "\n]\n", outputs);
117
    }
118

  
119
    void print_e_index_pmap(const Graph& g, const EdgeIndexPMap& e_index_pmap) {
120
        std::list<std::string> outputs;
121
        BGL_FORALL_EDGES_T(e, g, Graph) {
122
            int index = boost::get(e_index_pmap, e);
123
            std::string source_id = g[boost::source(e, g)].id;
124
            std::string target_id = g[boost::target(e, g)].id;
125
            outputs.push_back("edge (" + source_id + ", " + target_id + ")" + ": " + std::to_string(index));
126
        }
127

  
128
        using namespace boost::spirit::karma;
129
        cout << "Edge Index Map:\n";
128 130
        cout << format("[\n  " << (auto_ % "\n  ") << "\n]\n", outputs);
129 131
    }
130 132
}

Also available in: Unified diff