-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator.cpp
More file actions
81 lines (61 loc) · 2.2 KB
/
generator.cpp
File metadata and controls
81 lines (61 loc) · 2.2 KB
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
#include "generator.h"
#include "ui_generator.h"
Generator::Generator(QWidget *parent) :
QDialog(parent),
ui(new Ui::Generator)
{
ui->setupUi(this);
this->setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
scene = MainWindow::test;
}
void Generator::generateGraph(qint32 maxX,qint32 maxY)
{
qint32 verticesNb = ui->verticesNb->value();
qint32 density = ui->density->value();
qint32 arrowsNb = density*verticesNb*(verticesNb-1)/200;
qint32 vertexX,vertexY,randVertexA,randVertexB;
QVector<Sommet *>& vect_sommet = Scene::vect_sommet;
QMap<QPair<Sommet*,Sommet*>, qint64>& matrix = MainWindow::matrix;
/*
*
* Clear Matrix and Vect_sommet for new generation
*
*/
vect_sommet.clear(); matrix.clear();
Sommet::endNode = NULL;Sommet::startNode = NULL;
for(qint32 i=0;i<verticesNb;i++){
vertexX = qrand() % (maxX-120) + 30 ;
vertexY = -(qrand() % (maxY-100)) + 100;
sommet = new Sommet(vertexX,vertexY,i+1);
scene->addItem(sommet);
vect_sommet.push_back(sommet);
}
for(qint32 i=0;i<arrowsNb;i++){
randVertexA = qrand()%verticesNb;
randVertexB = qrand()%verticesNb;
if(randVertexA == randVertexB || matrix.find(QPair<Sommet*,Sommet*>(vect_sommet.at(randVertexA),vect_sommet.at(randVertexB))) != matrix.end()){
i--;
continue;
}
if(matrix.find(QPair<Sommet*,Sommet*>(vect_sommet.at(randVertexB),vect_sommet.at(randVertexA))) != matrix.end()){
i--;
continue;
}
Arrow* arrow = new Arrow(vect_sommet.at(randVertexA)->ItemX,vect_sommet.at(randVertexA)->ItemY,vect_sommet.at(randVertexB)->ItemX,vect_sommet.at(randVertexB)->ItemY);
scene->addItem(arrow);
arrow->weight = qrand()%100 + 1;
matrix.insert(QPair<Sommet*,Sommet*>(vect_sommet.at(randVertexA),vect_sommet.at(randVertexB)),arrow->weight);
}
}
qint32 Generator::getVerticesNb()
{
return ui->verticesNb->value();
}
qint32 Generator::getDensity()
{
return ui->density->value();
}
Generator::~Generator()
{
delete ui;
}