1
|
|
|
"""!
|
2
|
|
|
|
3
|
|
|
@brief Wrapper for CCORE library (part of this project).
|
4
|
|
|
|
5
|
|
|
@authors Andrei Novikov ([email protected])
|
6
|
|
|
@date 2014-2018
|
7
|
|
|
@copyright GNU Public License
|
8
|
|
|
|
9
|
|
|
@cond GNU_PUBLIC_LICENSE
|
10
|
|
|
PyClustering is free software: you can redistribute it and/or modify
|
11
|
|
|
it under the terms of the GNU General Public License as published by
|
12
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
13
|
|
|
(at your option) any later version.
|
14
|
|
|
|
15
|
|
|
PyClustering is distributed in the hope that it will be useful,
|
16
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18
|
|
|
GNU General Public License for more details.
|
19
|
|
|
|
20
|
|
|
You should have received a copy of the GNU General Public License
|
21
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
22
|
|
|
@endcond
|
23
|
|
|
|
24
|
|
|
"""
|
25
|
|
|
|
26
|
|
|
|
27
|
|
|
import os;
|
28
|
|
|
import sys;
|
29
|
|
|
|
30
|
|
|
from ctypes import *;
|
|
|
|
|
31
|
|
|
|
32
|
|
|
from pyclustering.core.definitions import *;
|
|
|
|
|
33
|
|
|
|
34
|
|
|
|
35
|
|
|
ccore_library_instance = None;
|
36
|
|
|
|
37
|
|
|
|
38
|
|
|
class ccore_library:
|
39
|
|
|
__library = None;
|
40
|
|
|
__workable = False;
|
41
|
|
|
__initialized = False;
|
42
|
|
|
|
43
|
|
|
@staticmethod
|
44
|
|
|
def get():
|
45
|
|
|
if (not ccore_library.__library):
|
46
|
|
|
ccore_library.initialize();
|
47
|
|
|
|
48
|
|
|
return ccore_library.__library;
|
49
|
|
|
|
50
|
|
|
|
51
|
|
|
@staticmethod
|
52
|
|
|
def workable():
|
53
|
|
|
if (not ccore_library.__initialized):
|
54
|
|
|
ccore_library.get();
|
55
|
|
|
|
56
|
|
|
return ccore_library.__workable;
|
57
|
|
|
|
58
|
|
|
|
59
|
|
|
@staticmethod
|
60
|
|
|
def initialize():
|
61
|
|
|
ccore_library.__initialized = True;
|
62
|
|
|
|
63
|
|
|
if (PATH_PYCLUSTERING_CCORE_LIBRARY is None):
|
64
|
|
|
print("The pyclustering core is not supported for platform '" + sys.platform + "' (" + platform.architecture()[0] + ").\n" +
|
65
|
|
|
"Please, contact to '[email protected]'.");
|
66
|
|
|
|
67
|
|
|
return None;
|
68
|
|
|
|
69
|
|
|
if (os.path.exists(PATH_PYCLUSTERING_CCORE_LIBRARY) is False):
|
70
|
|
|
print("The pyclustering core is not found (expected core location: '" + PATH_PYCLUSTERING_CCORE_LIBRARY + "').\n" +
|
71
|
|
|
"Probably library has not been successfully installed ('" + sys.platform + "', '" + platform.architecture()[0] + "').\n" +
|
72
|
|
|
"Please, contact to '[email protected]'.");
|
73
|
|
|
|
74
|
|
|
return None;
|
75
|
|
|
|
76
|
|
|
ccore_library.__library = cdll.LoadLibrary(PATH_PYCLUSTERING_CCORE_LIBRARY);
|
77
|
|
|
if (ccore_library.__check_library_integrity() is False):
|
78
|
|
|
print("Impossible to mark core as workable due to compitability troubles " +
|
79
|
|
|
"('" + sys.platform + "', '" + platform.architecture()[0] + "').\n" +
|
80
|
|
|
"Please, contact to '[email protected]'");
|
81
|
|
|
|
82
|
|
|
return None;
|
83
|
|
|
|
84
|
|
|
return ccore_library.__library;
|
85
|
|
|
|
86
|
|
|
|
87
|
|
|
@staticmethod
|
88
|
|
|
def __check_library_integrity():
|
89
|
|
|
try:
|
90
|
|
|
ccore_library.__library.get_interface_description.restype = c_char_p;
|
91
|
|
|
result = ccore_library.__library.get_interface_description();
|
92
|
|
|
|
93
|
|
|
if (len(result) > 0):
|
94
|
|
|
ccore_library.__workable = True;
|
95
|
|
|
|
96
|
|
|
return True;
|
97
|
|
|
|
98
|
|
|
except:
|
99
|
|
|
ccore_library.__workable = False;
|
100
|
|
|
|
101
|
|
|
return False;
|
102
|
|
|
|
103
|
|
|
|