dbscan results

This commit is contained in:
WickedJack99
2025-05-10 12:33:07 +02:00
parent a1e51fb5cb
commit db1af03d8e
4 changed files with 23 additions and 19 deletions

View File

@@ -2,17 +2,18 @@
#include <atomic>
#include <cmath>
#include <iostream>
#include <omp.h>
namespace HPC {
DBSCAN::DBSCAN(int minPts, double eps) : minPoints_(minPts), epsilon_(eps) {}
void DBSCAN::run(const std::vector<Point> &points) {
void DBSCAN::run(const std::vector<Point> &points, int threadNum) {
dataset_ = points;
const int n = dataset_.size();
initializeNeighbors();
initializeNeighbors(threadNum);
int clusterIndex = 0;
for (int i = 0; i < n; ++i) {
@@ -52,8 +53,8 @@ bool DBSCAN::expandCluster(Point &p, std::set<int> &neighbours, int clusterID) {
return true;
}
void DBSCAN::initializeNeighbors() {
#pragma omp parallel for
void DBSCAN::initializeNeighbors(int threadNum) {
#pragma omp parallel for num_threads(threadNum)
for (int i = 0; i < dataset_.size(); ++i) {
Point &pointToCheckNeighborsFor = dataset_[i];
for (int j = 0; j < dataset_.size(); ++j) {

View File

@@ -12,13 +12,13 @@ class DBSCAN {
public:
DBSCAN(int minPts, double eps);
void run(const std::vector<Point> &points);
void run(const std::vector<Point> &points, int threadNum);
const std::vector<Point> &getPoints() const { return dataset_; }
private:
std::set<int> regionQuery(const Point &point) const;
void initializeNeighbors();
void initializeNeighbors(int threadNum);
bool expandCluster(Point &point, std::set<int> &neighbours, int clusterID);
// void merge(std::vector<int>& n, const std::vector<int>& nPrime) const;

View File

@@ -10,23 +10,25 @@ int main() {
std::vector<Point> points = readPointsFromFile("data");
// Zeitmessung starten
auto start = std::chrono::high_resolution_clock::now();
DBSCAN ds(5, 0.01);
ds.run(points);
for (int i = 1; i < 13; i++) {
DBSCAN ds(5, 0.01);
// Zeitmessung starten
auto start = std::chrono::high_resolution_clock::now();
ds.run(points, i);
// Zeitmessung beenden
auto end = std::chrono::high_resolution_clock::now();
// Zeitmessung beenden
auto end = std::chrono::high_resolution_clock::now();
// Dauer berechnen in Millisekunden
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
std::cout << "Laufzeit: " << duration << " ms" << std::endl;
writePointsToFile(ds.getPoints(), "clustered");
// Dauer berechnen in Millisekunden
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
std::cout << "Laufzeit: " << duration << " ms" << std::endl;
writePointsToFile(ds.getPoints(), "clustered");
}
return 0;
}

View File

@@ -0,0 +1 @@
6807,4929,3753,3380,3148,2864,2796,2655,2702,2494,2482,2414
1 6807 4929 3753 3380 3148 2864 2796 2655 2702 2494 2482 2414