Showing
9 changed files
with
160 additions
and
54 deletions
... | @@ -13,7 +13,8 @@ void EdgeItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) | ... | @@ -13,7 +13,8 @@ void EdgeItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) |
13 | { | 13 | { |
14 | } | 14 | } |
15 | 15 | ||
16 | -EdgeItem::EdgeItem(double x1, double y1, double x2, double y2, QColor color, int width) | 16 | +EdgeItem::EdgeItem(double x1, double y1, double x2, double y2, QColor color, int width, |
17 | + QString from, QString to) | ||
17 | { | 18 | { |
18 | this->x1 = x1; | 19 | this->x1 = x1; |
19 | this->y1 = y1; | 20 | this->y1 = y1; |
... | @@ -22,6 +23,9 @@ EdgeItem::EdgeItem(double x1, double y1, double x2, double y2, QColor color, int | ... | @@ -22,6 +23,9 @@ EdgeItem::EdgeItem(double x1, double y1, double x2, double y2, QColor color, int |
22 | 23 | ||
23 | this->color = color; | 24 | this->color = color; |
24 | this->width = width; | 25 | this->width = width; |
26 | + | ||
27 | + this->from = from; | ||
28 | + this->to = to; | ||
25 | setZValue(0); //노드 앞 가리지 않도록 ZValue 설정 | 29 | setZValue(0); //노드 앞 가리지 않도록 ZValue 설정 |
26 | 30 | ||
27 | /*setFlags(ItemIsSelectable | ItemIsMovable); | 31 | /*setFlags(ItemIsSelectable | ItemIsMovable); | ... | ... |
... | @@ -9,6 +9,7 @@ class EdgeItem | ... | @@ -9,6 +9,7 @@ class EdgeItem |
9 | { | 9 | { |
10 | private: | 10 | private: |
11 | double x1, y1, x2, y2; | 11 | double x1, y1, x2, y2; |
12 | + QString from, to; | ||
12 | int width; | 13 | int width; |
13 | QColor color; | 14 | QColor color; |
14 | 15 | ||
... | @@ -18,7 +19,16 @@ protected: | ... | @@ -18,7 +19,16 @@ protected: |
18 | void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; | 19 | void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; |
19 | 20 | ||
20 | public: | 21 | public: |
21 | - EdgeItem(double x1, double y1, double x2, double y2, QColor color, int width); | 22 | + EdgeItem(double x1, double y1, double x2, double y2, QColor color, int width, |
23 | + QString from, QString to); | ||
24 | + | ||
25 | + //getter | ||
26 | + QString getFrom() { return from; } | ||
27 | + QString getTo() { return to; } | ||
28 | + | ||
29 | + //setter | ||
30 | + void setWidth(int w) { width = w; } | ||
31 | + void setColor(QColor color) { this->color = color; } | ||
22 | 32 | ||
23 | QRectF boundingRect() const override; | 33 | QRectF boundingRect() const override; |
24 | QPainterPath shape() const override; | 34 | QPainterPath shape() const override; | ... | ... |
... | @@ -31,6 +31,11 @@ void GraphItem::read_more() | ... | @@ -31,6 +31,11 @@ void GraphItem::read_more() |
31 | vector<pair<string, string>> edges; | 31 | vector<pair<string, string>> edges; |
32 | vector<pair<int, int>> edges_indexes; | 32 | vector<pair<int, int>> edges_indexes; |
33 | 33 | ||
34 | + //property maps | ||
35 | + auto node_position_map = boost::get(vertex_position, *graph); | ||
36 | + auto node_label_map = boost::get(vertex_name, *graph); | ||
37 | + auto node_type_map = boost::get(vertex_type, *graph); | ||
38 | + | ||
34 | int line_cnt = 0; | 39 | int line_cnt = 0; |
35 | qDebug() << "* graph reading start"; | 40 | qDebug() << "* graph reading start"; |
36 | 41 | ||
... | @@ -145,16 +150,16 @@ void GraphItem::read_more() | ... | @@ -145,16 +150,16 @@ void GraphItem::read_more() |
145 | 150 | ||
146 | switch (LAYOUT_MODE) { | 151 | switch (LAYOUT_MODE) { |
147 | case GRAPH_LAYOUT::RANDOM_LAYOUT: | 152 | case GRAPH_LAYOUT::RANDOM_LAYOUT: |
148 | - random_graph_layout(*graph, get(vertex_position, *graph), rect_top); | 153 | + random_graph_layout(*graph, node_position_map, rect_top); |
149 | break; | 154 | break; |
150 | 155 | ||
151 | case GRAPH_LAYOUT::CIRCLE_LAYOUT: | 156 | case GRAPH_LAYOUT::CIRCLE_LAYOUT: |
152 | - circle_graph_layout(*graph, get(vertex_position, *graph), SCREEN_SIZE / 2); | 157 | + circle_graph_layout(*graph, node_position_map, SCREEN_SIZE / 2); |
153 | break; | 158 | break; |
154 | 159 | ||
155 | case GRAPH_LAYOUT::FRUCHTERMAN_REINGOLD_LAYOUT: | 160 | case GRAPH_LAYOUT::FRUCHTERMAN_REINGOLD_LAYOUT: |
156 | fruchterman_reingold_force_directed_layout(*graph, | 161 | fruchterman_reingold_force_directed_layout(*graph, |
157 | - get(vertex_position, *graph), | 162 | + node_position_map, |
158 | topology, | 163 | topology, |
159 | attractive_force(square_distance_attractive_force()) | 164 | attractive_force(square_distance_attractive_force()) |
160 | .cooling(linear_cooling<double>(50)) | 165 | .cooling(linear_cooling<double>(50)) |
... | @@ -168,32 +173,30 @@ void GraphItem::read_more() | ... | @@ -168,32 +173,30 @@ void GraphItem::read_more() |
168 | nodeList.clear(); | 173 | nodeList.clear(); |
169 | edgeList.clear(); | 174 | edgeList.clear(); |
170 | 175 | ||
171 | - //add edges | 176 | + |
172 | - auto position = boost::get(vertex_position, *graph); | ||
173 | - auto label = boost::get(vertex_name, *graph); | ||
174 | - auto nodeType = boost::get(vertex_type, *graph); | ||
175 | 177 | ||
176 | //edge_iterator ei, ei_end; | 178 | //edge_iterator ei, ei_end; |
177 | vertex_descriptor u, v; | 179 | vertex_descriptor u, v; |
178 | for (boost::tie(ei, ei_end) = boost::edges(*graph); ei != ei_end; ++ei) { | 180 | for (boost::tie(ei, ei_end) = boost::edges(*graph); ei != ei_end; ++ei) { |
179 | u = source(*ei, *graph); | 181 | u = source(*ei, *graph); |
180 | v = target(*ei, *graph); | 182 | v = target(*ei, *graph); |
181 | - Point p1 = position[u]; | 183 | + Point p1 = node_position_map[u]; |
182 | - Point p2 = position[v]; | 184 | + Point p2 = node_position_map[v]; |
183 | 185 | ||
184 | //make edge item and push it to list | 186 | //make edge item and push it to list |
185 | EdgeItem *edge; | 187 | EdgeItem *edge; |
186 | 188 | ||
187 | - edge = new EdgeItem(p1[0], p1[1], p2[0], p2[1], QColor(Qt::black), 0); | 189 | + edge = new EdgeItem(p1[0], p1[1], p2[0], p2[1], QColor(Qt::black), 0, |
190 | + QString(node_label_map[u].c_str()), QString(node_label_map[v].c_str())); | ||
188 | edge->setPos(p1[0], p1[1]); | 191 | edge->setPos(p1[0], p1[1]); |
189 | edgeList << edge; | 192 | edgeList << edge; |
190 | } | 193 | } |
191 | 194 | ||
192 | //add nodes | 195 | //add nodes |
193 | for (boost::tie(vi, vi_end) = vertices(*graph); vi != vi_end; ++vi) { | 196 | for (boost::tie(vi, vi_end) = vertices(*graph); vi != vi_end; ++vi) { |
194 | - Point p = position[*vi]; | 197 | + Point p = node_position_map[*vi]; |
195 | - auto nt = nodeType[*vi]; | 198 | + auto nt = node_type_map[*vi]; |
196 | - std::string name = label[*vi]; | 199 | + std::string name = node_label_map[*vi]; |
197 | 200 | ||
198 | //make node item and push it to list | 201 | //make node item and push it to list |
199 | NodeItem *node; | 202 | NodeItem *node; |
... | @@ -244,8 +247,8 @@ void GraphItem::might_know() | ... | @@ -244,8 +247,8 @@ void GraphItem::might_know() |
244 | Graph::adjacency_iterator ai, ai_end; | 247 | Graph::adjacency_iterator ai, ai_end; |
245 | vector<string> might_know_vec; | 248 | vector<string> might_know_vec; |
246 | 249 | ||
247 | - auto label = get(vertex_name, *graph); | 250 | + auto node_label_map = get(vertex_name, *graph); |
248 | - auto nodeType = get(vertex_type, *graph); | 251 | + auto node_type_map = get(vertex_type, *graph); |
249 | 252 | ||
250 | // 회색 색칠 | 253 | // 회색 색칠 |
251 | for (auto& n : nodeList) { | 254 | for (auto& n : nodeList) { |
... | @@ -258,7 +261,7 @@ void GraphItem::might_know() | ... | @@ -258,7 +261,7 @@ void GraphItem::might_know() |
258 | 261 | ||
259 | // find target node | 262 | // find target node |
260 | for (boost::tie(vi, vi_end) = boost::vertices(*graph); vi!=vi_end; ++vi) { | 263 | for (boost::tie(vi, vi_end) = boost::vertices(*graph); vi!=vi_end; ++vi) { |
261 | - if (label[*vi] == std::string(TARGET_AUTHOR_NAME)) { | 264 | + if (node_label_map[*vi] == std::string(TARGET_AUTHOR_NAME)) { |
262 | vtarget = vi; | 265 | vtarget = vi; |
263 | break; | 266 | break; |
264 | } | 267 | } |
... | @@ -286,7 +289,7 @@ void GraphItem::might_know() | ... | @@ -286,7 +289,7 @@ void GraphItem::might_know() |
286 | for (boost::tie(ai, ai_end) = boost::adjacent_vertices(*vtarget, *graph); | 289 | for (boost::tie(ai, ai_end) = boost::adjacent_vertices(*vtarget, *graph); |
287 | ai != ai_end; | 290 | ai != ai_end; |
288 | ++ai) { | 291 | ++ai) { |
289 | - might_know_vec.push_back(label[*ai]); | 292 | + might_know_vec.push_back(node_label_map[*ai]); |
290 | } | 293 | } |
291 | 294 | ||
292 | // highlight | 295 | // highlight |
... | @@ -318,9 +321,9 @@ void GraphItem::topK_highlight_with_total() | ... | @@ -318,9 +321,9 @@ void GraphItem::topK_highlight_with_total() |
318 | vertex_iterator vi, vi_end; | 321 | vertex_iterator vi, vi_end; |
319 | Graph::adjacency_iterator ai, ai_end; | 322 | Graph::adjacency_iterator ai, ai_end; |
320 | 323 | ||
321 | - auto nodeLabel = boost::get(vertex_name, *graph); | 324 | + auto node_label_map = boost::get(vertex_name, *graph); |
322 | - auto nodeType = boost::get(vertex_type, *graph); | 325 | + auto node_type_map = boost::get(vertex_type, *graph); |
323 | - auto numOfRecords = boost::get(vertex_record, *graph); | 326 | + auto node_records_map = boost::get(vertex_record, *graph); |
324 | 327 | ||
325 | //실적 count 초기화 | 328 | //실적 count 초기화 |
326 | //for (boost::tie(vi, vi_end) = boost::vertices(*graph); vi != vi_end; ++vi) { | 329 | //for (boost::tie(vi, vi_end) = boost::vertices(*graph); vi != vi_end; ++vi) { |
... | @@ -333,20 +336,20 @@ void GraphItem::topK_highlight_with_total() | ... | @@ -333,20 +336,20 @@ void GraphItem::topK_highlight_with_total() |
333 | // <record, label> | 336 | // <record, label> |
334 | TopKHeap<pair<int, string>> heap(TOP_K); | 337 | TopKHeap<pair<int, string>> heap(TOP_K); |
335 | for (boost::tie(vi, vi_end) = boost::vertices(*graph); vi != vi_end; ++vi) { | 338 | for (boost::tie(vi, vi_end) = boost::vertices(*graph); vi != vi_end; ++vi) { |
336 | - if (nodeType[*vi] != NODE_TYPE::NODE_AUTHOR) { | 339 | + if (node_type_map[*vi] != NODE_TYPE::NODE_AUTHOR) { |
337 | continue; | 340 | continue; |
338 | } | 341 | } |
339 | 342 | ||
340 | int record_cnt = 0; | 343 | int record_cnt = 0; |
341 | for (boost::tie(ai, ai_end) = boost::adjacent_vertices(*vi, *graph); | 344 | for (boost::tie(ai, ai_end) = boost::adjacent_vertices(*vi, *graph); |
342 | ai != ai_end; ++ai) { | 345 | ai != ai_end; ++ai) { |
343 | - if (nodeType[*ai] == NODE_TYPE::NODE_PAPER) { | 346 | + if (node_type_map[*ai] == NODE_TYPE::NODE_PAPER) { |
344 | ++record_cnt; | 347 | ++record_cnt; |
345 | } | 348 | } |
346 | } | 349 | } |
347 | 350 | ||
348 | boost::put(vertex_record, *graph, *vi, record_cnt); | 351 | boost::put(vertex_record, *graph, *vi, record_cnt); |
349 | - heap.push(make_pair(record_cnt, nodeLabel[*vi])); | 352 | + heap.push(make_pair(record_cnt, node_label_map[*vi])); |
350 | 353 | ||
351 | //qDebug() << record_cnt; | 354 | //qDebug() << record_cnt; |
352 | } | 355 | } |
... | @@ -371,28 +374,53 @@ void GraphItem::topK_highlight_with_total() | ... | @@ -371,28 +374,53 @@ void GraphItem::topK_highlight_with_total() |
371 | } | 374 | } |
372 | } | 375 | } |
373 | 376 | ||
374 | -void GraphItem::test() | 377 | +void GraphItem::find_shortest_path() |
375 | { | 378 | { |
376 | qDebug("* path highlighting start"); | 379 | qDebug("* path highlighting start"); |
377 | vertex_iterator vi, vi_end; | 380 | vertex_iterator vi, vi_end; |
378 | - //find start, end node's id | 381 | + |
379 | - | 382 | + auto node_idx_map = boost::get(vertex_index, *graph); |
380 | - auto vertex_idx = boost::get(vertex_index, *graph); | 383 | + auto node_label_map = boost::get(vertex_name, *graph); |
381 | - auto nodeLabel = boost::get(vertex_name, *graph); | 384 | + |
382 | - | 385 | + string target_start, |
383 | - int start_idx=-1, end_idx=-1; | 386 | + target_end; |
384 | - for (boost::tie(vi, vi_end)=vertices(*graph); vi!=vi_end; ++vi) { | 387 | + |
385 | - //string node_name = boost::get(vertex_name, *graph, *vi); | 388 | + bool isok = false; |
386 | - const string& node_name = nodeLabel[*vi]; | 389 | + |
387 | - if (node_name == "Jung Gon Kim") { | 390 | + QInputDialog *inputDialog = new QInputDialog(); |
388 | - start_idx = vertex_idx[*vi]; | 391 | + |
389 | - } else if (node_name == "Yong-Jin Kim") { | 392 | + target_start = inputDialog->getText(nullptr, "Enter target's name", "Start node's name:", |
390 | - end_idx = vertex_idx[*vi]; | 393 | + QLineEdit::Normal, "Akira Idoue", &isok).toStdString(); |
394 | + if (!isok) { | ||
395 | + qDebug("input cancelled"); | ||
396 | + return; | ||
397 | + } | ||
398 | + qDebug() << target_start.c_str(); | ||
399 | + | ||
400 | + target_end = inputDialog->getText(nullptr, "Enter target's name", "End node's name:", | ||
401 | + QLineEdit::Normal, "Kayo Kurosaki", &isok).toStdString(); | ||
402 | + if (!isok) { | ||
403 | + qDebug("input cancelled"); | ||
404 | + return; | ||
405 | + } | ||
406 | + qDebug() << target_end.c_str(); | ||
407 | + | ||
408 | + | ||
409 | + | ||
410 | + | ||
411 | + int start_idx = -1, end_idx = -1; | ||
412 | + for (boost::tie(vi, vi_end) = vertices(*graph); vi != vi_end; ++vi) { | ||
413 | + const string& node_name = node_label_map[*vi]; | ||
414 | + if (node_name == target_start) { | ||
415 | + start_idx = node_idx_map[*vi]; | ||
416 | + } | ||
417 | + else if (node_name == target_end) { | ||
418 | + end_idx = node_idx_map[*vi]; | ||
391 | } | 419 | } |
392 | } | 420 | } |
393 | 421 | ||
394 | - | 422 | + |
395 | - if (start_idx==-1 || end_idx==-1) { | 423 | + if (start_idx == -1 || end_idx == -1) { |
396 | qDebug() << start_idx << " " << end_idx; | 424 | qDebug() << start_idx << " " << end_idx; |
397 | qDebug("no target node"); | 425 | qDebug("no target node"); |
398 | return; | 426 | return; |
... | @@ -402,14 +430,25 @@ void GraphItem::test() | ... | @@ -402,14 +430,25 @@ void GraphItem::test() |
402 | return; | 430 | return; |
403 | } | 431 | } |
404 | 432 | ||
433 | + /*QMessageBox msgBox; | ||
434 | + msgBox.setText("The document has been modified."); | ||
435 | + msgBox.setInformativeText("Do you want to save your changes?"); | ||
436 | + msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); | ||
437 | + msgBox.setDefaultButton(QMessageBox::Save); | ||
438 | + int ret = msgBox.exec(); | ||
439 | + qDebug() << "ret: " << ret; | ||
440 | + if (ret == QMessageBox::Save) { | ||
441 | + qDebug() << "save"; | ||
442 | + }*/ | ||
443 | + | ||
405 | vector<vertex_descriptor> parents(num_vertices(*graph)); | 444 | vector<vertex_descriptor> parents(num_vertices(*graph)); |
406 | vector<double> distances(num_vertices(*graph)); | 445 | vector<double> distances(num_vertices(*graph)); |
407 | vertex_descriptor start_vertex = boost::vertex(start_idx, *graph); | 446 | vertex_descriptor start_vertex = boost::vertex(start_idx, *graph); |
408 | 447 | ||
409 | //shortest path using dijkstra | 448 | //shortest path using dijkstra |
410 | boost::dijkstra_shortest_paths(*graph, start_vertex, | 449 | boost::dijkstra_shortest_paths(*graph, start_vertex, |
411 | - predecessor_map(boost::make_iterator_property_map(parents.begin(), boost::get(boost::vertex_index, *graph))). | 450 | + predecessor_map(boost::make_iterator_property_map(parents.begin(), node_idx_map)). |
412 | - distance_map(boost::make_iterator_property_map(distances.begin(), get(boost::vertex_index, *graph)))); | 451 | + distance_map(boost::make_iterator_property_map(distances.begin(), node_idx_map))); |
413 | 452 | ||
414 | //check distances | 453 | //check distances |
415 | //qDebug() << "dist: " << distances[end_idx]; | 454 | //qDebug() << "dist: " << distances[end_idx]; |
... | @@ -426,20 +465,49 @@ void GraphItem::test() | ... | @@ -426,20 +465,49 @@ void GraphItem::test() |
426 | 465 | ||
427 | //path finding | 466 | //path finding |
428 | qDebug("* path finding start"); | 467 | qDebug("* path finding start"); |
468 | + vector<string> paths; | ||
429 | vertex_descriptor current = boost::vertex(end_idx, *graph); | 469 | vertex_descriptor current = boost::vertex(end_idx, *graph); |
430 | - qDebug() << "end: " << nodeLabel[current].c_str(); | 470 | + paths.push_back(node_label_map[current]); |
471 | + qDebug() << "end: " << node_label_map[current].c_str(); | ||
431 | while (1) { | 472 | while (1) { |
432 | - current = parents[vertex_idx[current]]; | 473 | + current = parents[node_idx_map[current]]; |
433 | - qDebug() << nodeLabel[current].c_str(); | 474 | + paths.push_back(node_label_map[current]); |
475 | + | ||
476 | + qDebug() << node_label_map[current].c_str(); | ||
434 | if (current == start_vertex) break; | 477 | if (current == start_vertex) break; |
435 | } | 478 | } |
436 | qDebug("* path finding end"); | 479 | qDebug("* path finding end"); |
437 | - | 480 | + |
438 | 481 | ||
439 | qDebug("* path highlighting start"); | 482 | qDebug("* path highlighting start"); |
483 | + for (auto& n : nodeList) { | ||
484 | + if (find(paths.begin(), paths.end(), n->getLabel().toStdString()) | ||
485 | + != paths.end()) { | ||
486 | + n->setColor(QColor(Qt::blue)); | ||
487 | + } | ||
488 | + } | ||
489 | + size_t paths_sz = paths.size(); | ||
490 | + for (int i = 0; i < paths_sz - 1; ++i) { | ||
491 | + for (auto& e : edgeList) { | ||
492 | + if ((e->getFrom().toStdString() == paths[i] && e->getTo().toStdString() == paths[i + 1]) | ||
493 | + || (e->getFrom().toStdString() == paths[i + 1] && e->getTo().toStdString() == paths[i])) { | ||
494 | + e->setColor(QColor(Qt::blue)); | ||
495 | + e->setWidth(3); | ||
496 | + } | ||
497 | + } | ||
498 | + } | ||
440 | qDebug("* path highlighting end"); | 499 | qDebug("* path highlighting end"); |
441 | } | 500 | } |
442 | 501 | ||
502 | +void GraphItem::test() | ||
503 | +{ | ||
504 | + qDebug("* test action start"); | ||
505 | + | ||
506 | + | ||
507 | + | ||
508 | + qDebug("* test action end"); | ||
509 | +} | ||
510 | + | ||
443 | //event handler | 511 | //event handler |
444 | void GraphItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | 512 | void GraphItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
445 | { | 513 | { | ... | ... |
... | @@ -29,6 +29,7 @@ public: | ... | @@ -29,6 +29,7 @@ public: |
29 | void might_know(); | 29 | void might_know(); |
30 | void reset_color(); | 30 | void reset_color(); |
31 | void topK_highlight_with_total(); | 31 | void topK_highlight_with_total(); |
32 | + void find_shortest_path(); | ||
32 | 33 | ||
33 | //test | 34 | //test |
34 | void test(); | 35 | void test(); | ... | ... |
... | @@ -48,6 +48,9 @@ void MainWindow::createActions() | ... | @@ -48,6 +48,9 @@ void MainWindow::createActions() |
48 | resetColorAct = new QAction(tr("Reset colors"), this); | 48 | resetColorAct = new QAction(tr("Reset colors"), this); |
49 | resetColorAct->setStatusTip(tr("Reset all node's color")); | 49 | resetColorAct->setStatusTip(tr("Reset all node's color")); |
50 | connect(resetColorAct, &QAction::triggered, this, &MainWindow::reset_color); | 50 | connect(resetColorAct, &QAction::triggered, this, &MainWindow::reset_color); |
51 | + findShortestPathAct = new QAction(tr("Find Shortest Path"), this); | ||
52 | + findShortestPathAct->setStatusTip("Find shortest path between two node"); | ||
53 | + connect(findShortestPathAct, &QAction::triggered, this, &MainWindow::find_shortest_path); | ||
51 | 54 | ||
52 | testAct = new QAction(tr("test action"), this); | 55 | testAct = new QAction(tr("test action"), this); |
53 | testAct->setStatusTip(tr("test test")); | 56 | testAct->setStatusTip(tr("test test")); |
... | @@ -63,6 +66,7 @@ void MainWindow::createMenus() | ... | @@ -63,6 +66,7 @@ void MainWindow::createMenus() |
63 | actionMenu->addAction(mightKnowAct); | 66 | actionMenu->addAction(mightKnowAct); |
64 | actionMenu->addAction(topkAct); | 67 | actionMenu->addAction(topkAct); |
65 | actionMenu->addAction(resetColorAct); | 68 | actionMenu->addAction(resetColorAct); |
69 | + actionMenu->addAction(findShortestPathAct); | ||
66 | 70 | ||
67 | testMenu = menuBar()->addMenu(tr("&Test")); | 71 | testMenu = menuBar()->addMenu(tr("&Test")); |
68 | testMenu->addAction(testAct); | 72 | testMenu->addAction(testAct); |
... | @@ -84,7 +88,7 @@ void MainWindow::might_know() | ... | @@ -84,7 +88,7 @@ void MainWindow::might_know() |
84 | 88 | ||
85 | void MainWindow::topk() | 89 | void MainWindow::topk() |
86 | { | 90 | { |
87 | - graphWidget->topk(); | 91 | + graphWidget->topk_with_total(); |
88 | } | 92 | } |
89 | 93 | ||
90 | void MainWindow::reset_color() | 94 | void MainWindow::reset_color() |
... | @@ -92,6 +96,11 @@ void MainWindow::reset_color() | ... | @@ -92,6 +96,11 @@ void MainWindow::reset_color() |
92 | graphWidget->reset_color(); | 96 | graphWidget->reset_color(); |
93 | } | 97 | } |
94 | 98 | ||
99 | +void MainWindow::find_shortest_path() | ||
100 | +{ | ||
101 | + graphWidget->find_shortest_path(); | ||
102 | +} | ||
103 | + | ||
95 | void MainWindow::test() | 104 | void MainWindow::test() |
96 | { | 105 | { |
97 | graphWidget->test(); | 106 | graphWidget->test(); | ... | ... |
... | @@ -24,6 +24,7 @@ private: | ... | @@ -24,6 +24,7 @@ private: |
24 | QAction *mightKnowAct; | 24 | QAction *mightKnowAct; |
25 | QAction *topkAct; | 25 | QAction *topkAct; |
26 | QAction *resetColorAct; | 26 | QAction *resetColorAct; |
27 | + QAction *findShortestPathAct; | ||
27 | 28 | ||
28 | //test | 29 | //test |
29 | QMenu *testMenu; | 30 | QMenu *testMenu; |
... | @@ -38,6 +39,7 @@ private slots: | ... | @@ -38,6 +39,7 @@ private slots: |
38 | void might_know(); | 39 | void might_know(); |
39 | void topk(); | 40 | void topk(); |
40 | void reset_color(); | 41 | void reset_color(); |
42 | + void find_shortest_path(); | ||
41 | //test | 43 | //test |
42 | void test(); | 44 | void test(); |
43 | }; | 45 | }; | ... | ... |
... | @@ -56,12 +56,19 @@ void PaperGraphWidget::might_know() | ... | @@ -56,12 +56,19 @@ void PaperGraphWidget::might_know() |
56 | scene->update(); | 56 | scene->update(); |
57 | } | 57 | } |
58 | 58 | ||
59 | -void PaperGraphWidget::topk() | 59 | +void PaperGraphWidget::topk_with_total() |
60 | { | 60 | { |
61 | + //ü TopK highlight | ||
61 | graphItem->topK_highlight_with_total(); | 62 | graphItem->topK_highlight_with_total(); |
62 | scene->update(); | 63 | scene->update(); |
63 | } | 64 | } |
64 | 65 | ||
66 | +void PaperGraphWidget::find_shortest_path() | ||
67 | +{ | ||
68 | + graphItem->find_shortest_path(); | ||
69 | + scene->update(); | ||
70 | +} | ||
71 | + | ||
65 | void PaperGraphWidget::reset_color() | 72 | void PaperGraphWidget::reset_color() |
66 | { | 73 | { |
67 | graphItem->reset_color(); | 74 | graphItem->reset_color(); |
... | @@ -71,11 +78,12 @@ void PaperGraphWidget::reset_color() | ... | @@ -71,11 +78,12 @@ void PaperGraphWidget::reset_color() |
71 | void PaperGraphWidget::test() | 78 | void PaperGraphWidget::test() |
72 | { | 79 | { |
73 | //test | 80 | //test |
74 | - testCombo->addItem(to_string(rand() % 300).c_str()); | 81 | + //testCombo->addItem(to_string(rand() % 300).c_str()); |
75 | - testCombo->addItem(to_string(rand() % 300).c_str()); | 82 | + //testCombo->addItem(to_string(rand() % 300).c_str()); |
76 | - testCombo->addItem(to_string(rand() % 300).c_str()); | 83 | + //testCombo->addItem(to_string(rand() % 300).c_str()); |
77 | 84 | ||
78 | graphItem->test(); | 85 | graphItem->test(); |
86 | + scene->update(); | ||
79 | } | 87 | } |
80 | 88 | ||
81 | void PaperGraphWidget::handleSelectionChanged(int idx) | 89 | void PaperGraphWidget::handleSelectionChanged(int idx) | ... | ... |
... | @@ -16,7 +16,8 @@ public: | ... | @@ -16,7 +16,8 @@ public: |
16 | //main window slots | 16 | //main window slots |
17 | void read_more(); | 17 | void read_more(); |
18 | void might_know(); | 18 | void might_know(); |
19 | - void topk(); | 19 | + void topk_with_total(); |
20 | + void find_shortest_path(); | ||
20 | void reset_color(); | 21 | void reset_color(); |
21 | 22 | ||
22 | //test | 23 | //test | ... | ... |
... | @@ -7,6 +7,7 @@ | ... | @@ -7,6 +7,7 @@ |
7 | #include <QGraphicsScene> | 7 | #include <QGraphicsScene> |
8 | #include <QGraphicsView> | 8 | #include <QGraphicsView> |
9 | #include <QGridLayout> | 9 | #include <QGridLayout> |
10 | +#include <QInputDialog> | ||
10 | #include <QKeyEvent> | 11 | #include <QKeyEvent> |
11 | #include <QList> | 12 | #include <QList> |
12 | #include <QMainWindow> | 13 | #include <QMainWindow> |
... | @@ -100,8 +101,10 @@ namespace { | ... | @@ -100,8 +101,10 @@ namespace { |
100 | /* visualization */ | 101 | /* visualization */ |
101 | const int NODE_SIZE = 4; | 102 | const int NODE_SIZE = 4; |
102 | const int LAYOUT_MODE = GRAPH_LAYOUT::RANDOM_LAYOUT; | 103 | const int LAYOUT_MODE = GRAPH_LAYOUT::RANDOM_LAYOUT; |
104 | + //const int SCREEN_SIZE = 3000; | ||
103 | const int SCREEN_SIZE = 500; | 105 | const int SCREEN_SIZE = 500; |
104 | - const int READ_LINE_UNIT = 20; //한 번에 몇 라인을 읽을지 | 106 | + //const int READ_LINE_UNIT = 20; //한 번에 몇 라인을 읽을지 |
107 | + const int READ_LINE_UNIT = 40; | ||
105 | 108 | ||
106 | /* topK */ | 109 | /* topK */ |
107 | const int TOP_K = 5; //상위 몇 개 아이템에 대해 highlight 할 지 | 110 | const int TOP_K = 5; //상위 몇 개 아이템에 대해 highlight 할 지 | ... | ... |
-
Please register or login to post a comment