-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.m
73 lines (56 loc) · 2.24 KB
/
main.m
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
//
// main.m
// DBScan
//
// Created by Christian Vogel on 02.03.12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "FileSourceLoader.h"
#import "SourceLoader.h"
#import "CPoint.h"
#import "DBScan.h"
#import "EuclidianDistanceFunction.h"
#import "DistanceFunction.h"
int main(int argc, const char *argv[]) {
@autoreleasepool {
NSArray *pointsEntries;
if ([[[NSProcessInfo processInfo] arguments] count] > 1) {
id <SourceLoader> loader = [FileSourceLoader new];
pointsEntries = [loader load:[[[NSProcessInfo processInfo] arguments] objectAtIndex:1]];
} else {
NSLog(@"Pass the file path with point entries as an argument to this application.");
exit(0);
}
NSMutableArray *points = [NSMutableArray arrayWithCapacity:pointsEntries.count];
for (NSString *pointEntry in pointsEntries) {
if ([pointEntry length] > 0) {
CPoint *point = [CPoint new];
NSArray *coordinates = [pointEntry componentsSeparatedByString:@","];
for (NSString *coordinate in coordinates) {
[point addCoordinate:[coordinate floatValue]];
}
[points addObject:point];
}
}
NSLog(@"number of loaded points: %i", (int)points.count);
NSDate *startTime = [NSDate date];
NSLog(@"start clustering process (%@)", startTime);
NSArray *clusters = [[[DBScan alloc] initWithPoints:points epsilon:0.2f minNumberOfPointsInCluster:2 distanceFunction:[EuclidianDistanceFunction new]] clusters];
NSDate *endTime = [NSDate date];
NSLog(@"finished clustering process (%@)", endTime);
NSTimeInterval totalProcessingTimeInSeconds = [endTime timeIntervalSinceDate:startTime];
NSLog(@"total processing time: %fs", totalProcessingTimeInSeconds);
if (clusters.count == 0) {
NSLog(@"no cluster");
return 0;
}
int index = 1;
int sumPoints = 0;
for (Cluster *c in clusters) {
NSLog(@"\nCluster %i: \n%@", index++, [c description]);
sumPoints += c.count;
}
}
return 0;
}