-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomkCCTP.cpp
More file actions
34 lines (30 loc) · 913 Bytes
/
RandomkCCTP.cpp
File metadata and controls
34 lines (30 loc) · 913 Bytes
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
#include "RandomkCCTP.hpp"
vector<pair<double, double> > points;
Graphe initCTP(int nbNoeud, int min, int max, int seed){
mt19937 generator(seed);
Noeud* n = nullptr;
Graphe g;
std::uniform_real_distribution<double> distribution(min, max);
for(int i = 0; i < nbNoeud; i++){
n = new Noeud(i);
g.addNoeud(n);
}
for(int i = 0; i < nbNoeud; i++){
pair<double, double> p(distribution(generator), distribution(generator));
points.push_back(p);
}
for(int i = 0; i < nbNoeud; i++){
for(int j = i; j < nbNoeud; j++){
if (i != j){
double distance = sqrt(pow(points[i].first - points[j].first , 2) + pow(points[i].second - points[j].second , 2));
g.addEdge(g.getNoeud(i), g.getNoeud(j), distance);
}
}
}
return g;
}
Graphe initKCCTP(int nbNoeud, int k, int min, int max, int seed){
Graphe g = initCTP(nbNoeud, min, max, seed);
g.closeRoad(k, g.edges.size(), seed);
return g;
}