|
1
|
|
|
''' |
|
2
|
|
|
Created on Jul 1, 2016 |
|
3
|
|
|
|
|
4
|
|
|
@author: alex |
|
5
|
|
|
''' |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
from pyclustering.core.wrapper import *; |
|
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
import types; |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
class c_antcolony_clustering_parameters(Structure): |
|
14
|
|
|
""" |
|
15
|
|
|
double ro; |
|
16
|
|
|
double pheramone_init; |
|
17
|
|
|
unsigned int iterations; |
|
18
|
|
|
unsigned int count_ants; |
|
19
|
|
|
|
|
20
|
|
|
""" |
|
21
|
|
|
_fields_ = [("ro" , c_double), |
|
22
|
|
|
("pheramone_init" , c_double), |
|
23
|
|
|
("iterations" , c_uint), |
|
24
|
|
|
("count_ants" , c_uint) ]; |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
def ant_mean_clustering_process(params, count_clusters, samples): |
|
29
|
|
|
ccore = cdll.LoadLibrary(PATH_DLL_CCORE_64); |
|
30
|
|
|
|
|
31
|
|
|
algorithm_params = c_antcolony_clustering_parameters(); |
|
32
|
|
|
algorithm_params.ro = c_double(params.ro); |
|
33
|
|
|
algorithm_params.pheramone_init = c_double(params.pheramone_init); |
|
34
|
|
|
algorithm_params.iterations = c_uint(params.iterations); |
|
35
|
|
|
algorithm_params.count_ants = c_uint(params.count_ants); |
|
36
|
|
|
|
|
37
|
|
|
algorithm_params = pointer(algorithm_params); |
|
38
|
|
|
|
|
39
|
|
|
p_samples = create_pointer_data(samples) |
|
40
|
|
|
|
|
41
|
|
|
""" |
|
42
|
|
|
Run algorithm |
|
43
|
|
|
""" |
|
|
|
|
|
|
44
|
|
|
res = ccore.ant_mean_clustering(p_samples, algorithm_params, count_clusters) |
|
45
|
|
|
res = cast(res, POINTER(clustering_result)); |
|
46
|
|
|
|
|
47
|
|
|
""" |
|
48
|
|
|
Cast result to python view |
|
49
|
|
|
""" |
|
|
|
|
|
|
50
|
|
|
pointer_data = cast(res[0].pointer_clusters, POINTER(cluster_representation)) |
|
51
|
|
|
num_clusters = res[0].number_clusters |
|
52
|
|
|
|
|
53
|
|
|
pyResult = [[] for i in range(num_clusters)] |
|
54
|
|
|
|
|
55
|
|
|
for i in range(num_clusters): |
|
56
|
|
|
for j in range(pointer_data[i].number_objects): |
|
57
|
|
|
pyResult[i].append(pointer_data[i].pointer_objects[j]) |
|
58
|
|
|
|
|
59
|
|
|
return pyResult |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
#res = ant_mean_clustering_process(ant_mean_clustering(), 2, [[ 0,0 ],[ 1,1 ],[ 10,10 ],[ 11,11 ],[ -2, -2 ],[ 0.55, -1.26 ],[ 13.25, 12.12 ]]) |
|
63
|
|
|
#print(res) |
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
|