Showing
3 changed files
with
28 additions
and
29 deletions
| ... | @@ -27,9 +27,9 @@ void GraphItem::read_more() | ... | @@ -27,9 +27,9 @@ void GraphItem::read_more() |
| 27 | std::string line; | 27 | std::string line; |
| 28 | vector<std::string> tokens; | 28 | vector<std::string> tokens; |
| 29 | vector<std::string> authors; | 29 | vector<std::string> authors; |
| 30 | - /*vector<pair<string, string>> edges;*/ | ||
| 31 | 30 | ||
| 32 | - //vector<simple_edge> edges_indexes; | 31 | + vector<pair<string, string>> edges; |
| 32 | + vector<pair<int, int>> edges_indexes; | ||
| 33 | 33 | ||
| 34 | int line_cnt = 0; | 34 | int line_cnt = 0; |
| 35 | qDebug() << "* graph reading start"; | 35 | qDebug() << "* graph reading start"; |
| ... | @@ -67,12 +67,9 @@ void GraphItem::read_more() | ... | @@ -67,12 +67,9 @@ void GraphItem::read_more() |
| 67 | qDebug() << "* # of nodes: " << node_cnt; | 67 | qDebug() << "* # of nodes: " << node_cnt; |
| 68 | //qDebug() << "* # of edges: " << edges.size(); | 68 | //qDebug() << "* # of edges: " << edges.size(); |
| 69 | 69 | ||
| 70 | - | ||
| 71 | - | ||
| 72 | //edge conversion | 70 | //edge conversion |
| 73 | //<string, string> to <int, int> | 71 | //<string, string> to <int, int> |
| 74 | //using boost::bimap (bidirectional map) | 72 | //using boost::bimap (bidirectional map) |
| 75 | - edges_indexes.clear(); | ||
| 76 | for (auto edge : edges) { | 73 | for (auto edge : edges) { |
| 77 | edges_indexes.push_back({ | 74 | edges_indexes.push_back({ |
| 78 | node_ids.left.find(edge.first)->get_right(), | 75 | node_ids.left.find(edge.first)->get_right(), |
| ... | @@ -80,18 +77,16 @@ void GraphItem::read_more() | ... | @@ -80,18 +77,16 @@ void GraphItem::read_more() |
| 80 | }); | 77 | }); |
| 81 | } | 78 | } |
| 82 | 79 | ||
| 83 | - //Graph graph(edges_indexes.begin(), edges_indexes.end(), node_ids.size()); | ||
| 84 | - //graph = new Graph(edges_indexes.begin(), edges_indexes.end(), node_ids.size()); | ||
| 85 | - //for (auto& e: edges_indexes) { | ||
| 86 | - // boost::add_edge(e.first, e.second, graph); | ||
| 87 | - //} | ||
| 88 | 80 | ||
| 89 | - if (graph) { | 81 | + // add new vertices |
| 90 | - delete graph; | 82 | + for (int i = 0; i < node_cnt; ++i) { |
| 91 | - graph = nullptr; | 83 | + vdes.push_back(add_vertex(static_cast<Graph&>(*graph))); |
| 92 | } | 84 | } |
| 93 | - graph = new Graph(edges_indexes.begin(), edges_indexes.end(), node_ids.size()); | ||
| 94 | 85 | ||
| 86 | + // add new edges | ||
| 87 | + for (auto e_i: edges_indexes) { | ||
| 88 | + add_edge(vdes[e_i.first], vdes[e_i.second], *graph); | ||
| 89 | + } | ||
| 95 | 90 | ||
| 96 | 91 | ||
| 97 | //set index property | 92 | //set index property |
| ... | @@ -124,15 +119,15 @@ void GraphItem::read_more() | ... | @@ -124,15 +119,15 @@ void GraphItem::read_more() |
| 124 | qDebug() << "* set vertex property end"; | 119 | qDebug() << "* set vertex property end"; |
| 125 | whole_node_cnt += node_cnt; | 120 | whole_node_cnt += node_cnt; |
| 126 | 121 | ||
| 127 | - //qDebug("* set edges weight start"); | 122 | + qDebug("* set edges weight start"); |
| 128 | - ////모든 edge의 weight를 1로 설정 | 123 | + //모든 edge의 weight를 1로 설정 |
| 129 | - //typename graph_traits<Graph>::edge_iterator ei, ei_end; | 124 | + typename graph_traits<Graph>::edge_iterator ei, ei_end; |
| 130 | - //for (boost::tie(ei, ei_end)=boost::edges(*graph); ei!=ei_end; ++ei) { | 125 | + for (boost::tie(ei, ei_end)=boost::edges(*graph); ei!=ei_end; ++ei) { |
| 131 | - // boost::put(edge_weight, *graph, *ei, 1); | 126 | + boost::put(edge_weight, *graph, *ei, 1); |
| 132 | - //} | 127 | + } |
| 133 | - //qDebug("* set edges weight end"); | 128 | + qDebug("* set edges weight end"); |
| 134 | - // | 129 | + |
| 135 | - // | 130 | + |
| 136 | //qDebug("* path highlighting start"); | 131 | //qDebug("* path highlighting start"); |
| 137 | ////find start, end node's id | 132 | ////find start, end node's id |
| 138 | //int start_idx, end_idx; | 133 | //int start_idx, end_idx; |
| ... | @@ -204,7 +199,7 @@ void GraphItem::read_more() | ... | @@ -204,7 +199,7 @@ void GraphItem::read_more() |
| 204 | auto label = boost::get(vertex_name, *graph); | 199 | auto label = boost::get(vertex_name, *graph); |
| 205 | auto nodeType = boost::get(vertex_type, *graph); | 200 | auto nodeType = boost::get(vertex_type, *graph); |
| 206 | 201 | ||
| 207 | - edge_iterator ei, ei_end; | 202 | + //edge_iterator ei, ei_end; |
| 208 | vertex_descriptor u, v; | 203 | vertex_descriptor u, v; |
| 209 | for (boost::tie(ei, ei_end) = boost::edges(*graph); ei != ei_end; ++ei) { | 204 | for (boost::tie(ei, ei_end) = boost::edges(*graph); ei != ei_end; ++ei) { |
| 210 | u = source(*ei, *graph); | 205 | u = source(*ei, *graph); | ... | ... |
| ... | @@ -38,8 +38,9 @@ protected: | ... | @@ -38,8 +38,9 @@ protected: |
| 38 | private: | 38 | private: |
| 39 | ifstream fin; | 39 | ifstream fin; |
| 40 | bm_type node_ids; | 40 | bm_type node_ids; |
| 41 | - vector<pair<string, string>> edges; | 41 | + //vector<pair<string, string>> edges; |
| 42 | - vector<simple_edge> edges_indexes; | 42 | + //vector<pair<int, int>> edges_indexes; |
| 43 | + vector<vertex_descriptor> vdes; | ||
| 43 | int whole_node_cnt = 0; | 44 | int whole_node_cnt = 0; |
| 44 | 45 | ||
| 45 | Graph *graph = nullptr; | 46 | Graph *graph = nullptr; | ... | ... |
| ... | @@ -93,9 +93,12 @@ typedef square_topology<> Topology; | ... | @@ -93,9 +93,12 @@ typedef square_topology<> Topology; |
| 93 | typedef typename Topology::point_type Point; | 93 | typedef typename Topology::point_type Point; |
| 94 | 94 | ||
| 95 | /* structs */ | 95 | /* structs */ |
| 96 | -struct simple_edge { | 96 | +//struct simple_edge { |
| 97 | - int first, second; | 97 | +// int first, second; |
| 98 | -}; | 98 | +//}; |
| 99 | +//struct simple_edge { | ||
| 100 | +// int a, b; | ||
| 101 | +//}; | ||
| 99 | 102 | ||
| 100 | /* constants */ | 103 | /* constants */ |
| 101 | namespace { | 104 | namespace { | ... | ... |
-
Please register or login to post a comment