Showing
3 changed files
with
51 additions
and
13 deletions
| ... | @@ -310,8 +310,10 @@ void GraphItem::reset_color() | ... | @@ -310,8 +310,10 @@ void GraphItem::reset_color() |
| 310 | } | 310 | } |
| 311 | } | 311 | } |
| 312 | 312 | ||
| 313 | -void GraphItem::topK_highlight() | 313 | +void GraphItem::topK_highlight_with_total() |
| 314 | { | 314 | { |
| 315 | + // 전체 그래프 기준 topK highlight | ||
| 316 | + | ||
| 315 | // 저자 노드별 실적 계산 | 317 | // 저자 노드별 실적 계산 |
| 316 | vertex_iterator vi, vi_end; | 318 | vertex_iterator vi, vi_end; |
| 317 | Graph::adjacency_iterator ai, ai_end; | 319 | Graph::adjacency_iterator ai, ai_end; |
| ... | @@ -374,29 +376,67 @@ void GraphItem::test() | ... | @@ -374,29 +376,67 @@ void GraphItem::test() |
| 374 | qDebug("* path highlighting start"); | 376 | qDebug("* path highlighting start"); |
| 375 | vertex_iterator vi, vi_end; | 377 | vertex_iterator vi, vi_end; |
| 376 | //find start, end node's id | 378 | //find start, end node's id |
| 377 | - int start_idx, end_idx; | 379 | + |
| 380 | + auto vertex_idx = boost::get(vertex_index, *graph); | ||
| 381 | + auto nodeLabel = boost::get(vertex_name, *graph); | ||
| 382 | + | ||
| 383 | + int start_idx=-1, end_idx=-1; | ||
| 378 | for (boost::tie(vi, vi_end)=vertices(*graph); vi!=vi_end; ++vi) { | 384 | for (boost::tie(vi, vi_end)=vertices(*graph); vi!=vi_end; ++vi) { |
| 379 | - string node_name = boost::get(vertex_name, *graph, *vi); | 385 | + //string node_name = boost::get(vertex_name, *graph, *vi); |
| 380 | - if (node_name == "Seong Chul Cho") { | 386 | + const string& node_name = nodeLabel[*vi]; |
| 381 | - start_idx = boost::get(vertex_index, *graph, *vi); | 387 | + if (node_name == "Jung Gon Kim") { |
| 382 | - } else if (node_name == "Hyung Jin Kim") { | 388 | + start_idx = vertex_idx[*vi]; |
| 383 | - end_idx = boost::get(vertex_index, *graph, *vi); | 389 | + } else if (node_name == "Yong-Jin Kim") { |
| 390 | + end_idx = vertex_idx[*vi]; | ||
| 384 | } | 391 | } |
| 385 | } | 392 | } |
| 386 | 393 | ||
| 394 | + | ||
| 395 | + if (start_idx==-1 || end_idx==-1) { | ||
| 396 | + qDebug() << start_idx << " " << end_idx; | ||
| 397 | + qDebug("no target node"); | ||
| 398 | + return; | ||
| 399 | + } | ||
| 400 | + else if (start_idx == end_idx) { | ||
| 401 | + qDebug("start and end node are same!"); | ||
| 402 | + return; | ||
| 403 | + } | ||
| 404 | + | ||
| 387 | vector<vertex_descriptor> parents(num_vertices(*graph)); | 405 | vector<vertex_descriptor> parents(num_vertices(*graph)); |
| 388 | vector<double> distances(num_vertices(*graph)); | 406 | vector<double> distances(num_vertices(*graph)); |
| 389 | vertex_descriptor start_vertex = boost::vertex(start_idx, *graph); | 407 | vertex_descriptor start_vertex = boost::vertex(start_idx, *graph); |
| 408 | + | ||
| 409 | + //shortest path using dijkstra | ||
| 390 | boost::dijkstra_shortest_paths(*graph, start_vertex, | 410 | boost::dijkstra_shortest_paths(*graph, start_vertex, |
| 391 | predecessor_map(boost::make_iterator_property_map(parents.begin(), boost::get(boost::vertex_index, *graph))). | 411 | predecessor_map(boost::make_iterator_property_map(parents.begin(), boost::get(boost::vertex_index, *graph))). |
| 392 | distance_map(boost::make_iterator_property_map(distances.begin(), get(boost::vertex_index, *graph)))); | 412 | distance_map(boost::make_iterator_property_map(distances.begin(), get(boost::vertex_index, *graph)))); |
| 413 | + | ||
| 414 | + //check distances | ||
| 415 | + //qDebug() << "dist: " << distances[end_idx]; | ||
| 416 | + //qDebug(); | ||
| 417 | + //for (int i = 0; i < distances.size(); ++i) { | ||
| 418 | + // qDebug() << "dist[" << i << "]: " << distances[i]; | ||
| 419 | + //} | ||
| 420 | + //qDebug(); | ||
| 421 | + if (distances[end_idx] >= whole_node_cnt) { | ||
| 422 | + //no path (dist == 0) | ||
| 423 | + qDebug() << "no path!"; | ||
| 424 | + return; | ||
| 425 | + } | ||
| 426 | + | ||
| 393 | //path finding | 427 | //path finding |
| 394 | qDebug("* path finding start"); | 428 | qDebug("* path finding start"); |
| 395 | vertex_descriptor current = boost::vertex(end_idx, *graph); | 429 | vertex_descriptor current = boost::vertex(end_idx, *graph); |
| 396 | - while (current != boost::vertex(start_idx, *graph)) { | 430 | + qDebug() << "end: " << nodeLabel[current].c_str(); |
| 397 | - | 431 | + while (1) { |
| 432 | + current = parents[vertex_idx[current]]; | ||
| 433 | + qDebug() << nodeLabel[current].c_str(); | ||
| 434 | + if (current == start_vertex) break; | ||
| 398 | } | 435 | } |
| 399 | qDebug("* path finding end"); | 436 | qDebug("* path finding end"); |
| 437 | + | ||
| 438 | + | ||
| 439 | + qDebug("* path highlighting start"); | ||
| 400 | qDebug("* path highlighting end"); | 440 | qDebug("* path highlighting end"); |
| 401 | } | 441 | } |
| 402 | 442 | ... | ... |
| ... | @@ -28,7 +28,7 @@ public: | ... | @@ -28,7 +28,7 @@ public: |
| 28 | //methods | 28 | //methods |
| 29 | void might_know(); | 29 | void might_know(); |
| 30 | void reset_color(); | 30 | void reset_color(); |
| 31 | - void topK_highlight(); | 31 | + void topK_highlight_with_total(); |
| 32 | 32 | ||
| 33 | //test | 33 | //test |
| 34 | void test(); | 34 | void test(); |
| ... | @@ -41,8 +41,6 @@ protected: | ... | @@ -41,8 +41,6 @@ protected: |
| 41 | private: | 41 | private: |
| 42 | ifstream fin; | 42 | ifstream fin; |
| 43 | bm_type node_ids; | 43 | bm_type node_ids; |
| 44 | - //vector<pair<string, string>> edges; | ||
| 45 | - //vector<pair<int, int>> edges_indexes; | ||
| 46 | vector<vertex_descriptor> vdes; | 44 | vector<vertex_descriptor> vdes; |
| 47 | int whole_node_cnt = 0; | 45 | int whole_node_cnt = 0; |
| 48 | 46 | ... | ... |
| ... | @@ -58,7 +58,7 @@ void PaperGraphWidget::might_know() | ... | @@ -58,7 +58,7 @@ void PaperGraphWidget::might_know() |
| 58 | 58 | ||
| 59 | void PaperGraphWidget::topk() | 59 | void PaperGraphWidget::topk() |
| 60 | { | 60 | { |
| 61 | - graphItem->topK_highlight(); | 61 | + graphItem->topK_highlight_with_total(); |
| 62 | scene->update(); | 62 | scene->update(); |
| 63 | } | 63 | } |
| 64 | 64 | ... | ... |
-
Please register or login to post a comment