-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
121 lines (99 loc) · 4.04 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->matrixView,SIGNAL(changed(QObject*)),Engine::getInstance(),SLOT(updateGraph(QObject*)));
connect(Engine::getInstance(),SIGNAL(changedGraph(QObject*)),ui->matrixView,SLOT(update(QObject*)));
connect(Engine::getInstance(),SIGNAL(changedGraph(QObject*)),ui->neLIST,SLOT(update(QObject*)));
connect(ui->neLIST,SIGNAL(changed(QObject*)),Engine::getInstance(),SLOT(updateGraph(QObject*)));
connect(ui->addConnectionView,SIGNAL(changed(QObject*)),Engine::getInstance(),SLOT(updateGraph(QObject*)));
connect(Engine::getInstance(),SIGNAL(changedGraph(QObject*)),ui->addConnectionView,SLOT(update(QObject*)));
connect(Engine::getInstance(),SIGNAL(changedGraph(QObject*)),ui->connectionMatrix,SLOT(update(QObject*)));
connect(Engine::getInstance(),SIGNAL(changedGraph(QObject*)),ui->graphView,SLOT(update(QObject*)));
connect(Engine::getInstance(),SIGNAL(changedGraph(QObject*)),this,SLOT(onGraphChanged(QObject*)));
connect(Engine::getInstance(),SIGNAL(changedGraph(QObject*)),ui->distanceMatrix,SLOT(update(QObject*)));
}
void MainWindow::onGraphChanged(QObject *sender){
qDebug()<<"weq";
std::vector < std::vector<int> > stronglyComponents=Engine::getInstance()->getGraph()->getStronglyConnectedComponents();
QString result="";
for(int i=0;i<stronglyComponents.size();i++){
for(int j=0;j<stronglyComponents.at(i).size();j++){
if(j!=0){
result+=",";
}
result+=QString::number(stronglyComponents.at(i).at(j));
}
result+="<br>";
}
ui->strongComponents->setText(result);
std::vector<std::vector<int> > cycles =Engine::getInstance()->getGraph()->getCycles();
result="";
for(int i=0;i<cycles.size();i++){
for(int j=0;j<cycles.at(i).size();j++){
if(j!=0){
result+=",";
}
result+=QString::number(cycles.at(i).at(j));
}
result+="<br>";
}
ui->cycles->setText(result);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_createNewGraphButton_clicked()
{
Engine::getInstance()->setGraph(new DirectedGraph(ui->vertsNumberSpin->value()));
}
void MainWindow::on_generate_clicked()
{
DirectedGraph * tmp=DirectedGraph::randomConsistentDiGraph(ui->vertexNumberInGenerator->value());
Engine::getInstance()->setGraph(tmp);
}
void MainWindow::on_generateFromGraphToBF_clicked()
{
Engine::getInstance()->setGraph(MaxStronglyConnectedComponent::getMaxStronglyConnectedComponent(Engine::getInstance()->getGraph()));
}
void MainWindow::on_checkDistance_clicked()
{
int vertexID=ui->BF_vertex_ID->value();
QString result="";
for(int i=0;i<Engine::getInstance()->getGraph()->getVerticesNumber();i++){
result+=QString::number(vertexID+1);
result+="=>";
result+=QString::number(i+1);
result+=" : ";
result+=QString::number(ShortestPaths::bellmanFord(Engine::getInstance()->getGraph(),vertexID,i));
result+="<br>";
}
ui->distanceLabelBF->setText(result);
}
void MainWindow::on_johnsonApply_clicked()
{
ShortestPaths::johnson(Engine::getInstance()->getGraph());
Engine::getInstance()->updateGraph(this);
}
void MainWindow::on_floydWarshall_clicked()
{
ShortestPaths::floydWarshall(Engine::getInstance()->getGraph());
Engine::getInstance()->updateGraph(this);
}
void MainWindow::on_sortTrigget_clicked()
{
//DirectedAcyclicGraph::dagCreator(Engine::getInstance()->getGraph());
Engine::getInstance()->setGraph(DirectedAcyclicGraph::dagCreator(Engine::getInstance()->getGraph()));
std::list <int> sort=TopologicalSort::getTopologicalSort(Engine::getInstance()->getGraph());
QString result="Wynik sortowania topologicznego <br>";
for(int i=0; i<sort.size();i++){
result+=" ";
result+=QString::number(sort.front());
sort.pop_front();
}
ui->sortResult->setText(result);
}