Skip to content

Commit bd87170

Browse files
committed
#381: C++ implementation of CLIQUE (compilable skeleton).
1 parent ae77281 commit bd87170

12 files changed

+448
-10
lines changed

ccore/src/ccore.vcxproj

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
<ItemGroup>
2222
<ClCompile Include="cluster\agglomerative.cpp" />
2323
<ClCompile Include="cluster\bsas.cpp" />
24+
<ClCompile Include="cluster\clique.cpp" />
25+
<ClCompile Include="cluster\clique_block.cpp" />
2426
<ClCompile Include="cluster\cluster_algorithm.cpp" />
2527
<ClCompile Include="cluster\cluster_data.cpp" />
2628
<ClCompile Include="cluster\cure.cpp" />
@@ -95,6 +97,9 @@
9597
<ClInclude Include="cluster\bsas.hpp" />
9698
<ClInclude Include="cluster\bsas_data.hpp" />
9799
<ClInclude Include="cluster\center_initializer.hpp" />
100+
<ClInclude Include="cluster\clique.hpp" />
101+
<ClInclude Include="cluster\clique_block.hpp" />
102+
<ClInclude Include="cluster\clique_data.hpp" />
98103
<ClInclude Include="cluster\cluster_algorithm.hpp" />
99104
<ClInclude Include="cluster\cluster_data.hpp" />
100105
<ClInclude Include="cluster\cure.hpp" />

ccore/src/ccore.vcxproj.filters

+15
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@
238238
<ClCompile Include="interface\elbow_interface.cpp">
239239
<Filter>Source Files\interface</Filter>
240240
</ClCompile>
241+
<ClCompile Include="cluster\clique.cpp">
242+
<Filter>Source Files\cluster</Filter>
243+
</ClCompile>
244+
<ClCompile Include="cluster\clique_block.cpp">
245+
<Filter>Source Files\cluster</Filter>
246+
</ClCompile>
241247
</ItemGroup>
242248
<ItemGroup>
243249
<ClInclude Include="cluster\agglomerative.hpp">
@@ -522,5 +528,14 @@
522528
<ClInclude Include="interface\elbow_interface.h">
523529
<Filter>Source Files\interface</Filter>
524530
</ClInclude>
531+
<ClInclude Include="cluster\clique.hpp">
532+
<Filter>Source Files\cluster</Filter>
533+
</ClInclude>
534+
<ClInclude Include="cluster\clique_block.hpp">
535+
<Filter>Source Files\cluster</Filter>
536+
</ClInclude>
537+
<ClInclude Include="cluster\clique_data.hpp">
538+
<Filter>Source Files\cluster</Filter>
539+
</ClInclude>
525540
</ItemGroup>
526541
</Project>

ccore/src/cluster/clique.cpp

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
*
3+
* @authors Andrei Novikov ([email protected])
4+
* @date 2014-2019
5+
* @copyright GNU Public License
6+
*
7+
* GNU_PUBLIC_LICENSE
8+
* pyclustering is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* pyclustering is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
#include "cluster/clique.hpp"
24+
25+
26+
namespace ccore {
27+
28+
namespace clst {
29+
30+
31+
coordinate_iterator::coordinate_iterator(const std::size_t p_dimension, const std::size_t p_edge) :
32+
m_dimension(p_dimension),
33+
m_edge(p_edge),
34+
m_coordinate(p_dimension, std::size_t(0))
35+
{ }
36+
37+
const clique_block_location & coordinate_iterator::get_coordinate(void) const {
38+
return m_coordinate;
39+
}
40+
41+
clique_block_location & coordinate_iterator::get_coordinate(void) {
42+
return m_coordinate;
43+
}
44+
45+
coordinate_iterator & coordinate_iterator::operator++() {
46+
for (std::size_t index_dimension = 0; index_dimension < m_dimension; ++index_dimension) {
47+
if (m_coordinate[index_dimension] + 1 < m_edge) {
48+
++m_coordinate[index_dimension];
49+
return *this;
50+
}
51+
else {
52+
m_coordinate[index_dimension] = 0;
53+
}
54+
}
55+
56+
m_coordinate = clique_block_location(m_dimension, 0);
57+
return *this;
58+
}
59+
60+
61+
clique::clique(const std::size_t p_intervals, const std::size_t p_threshold) :
62+
m_intervals(p_intervals),
63+
m_density_threshold(p_threshold)
64+
{ }
65+
66+
67+
void clique::process(const dataset & p_data, cluster_data & p_result) {
68+
}
69+
70+
71+
void clique::create_grid(void) {
72+
73+
}
74+
75+
76+
}
77+
78+
}

ccore/src/cluster/clique.hpp

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
*
3+
* @authors Andrei Novikov ([email protected])
4+
* @date 2014-2019
5+
* @copyright GNU Public License
6+
*
7+
* GNU_PUBLIC_LICENSE
8+
* pyclustering is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* pyclustering is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
#pragma once
24+
25+
#include "cluster/clique_data.hpp"
26+
#include "cluster/cluster_algorithm.hpp"
27+
28+
#include <unordered_map>
29+
30+
31+
namespace ccore {
32+
33+
namespace clst {
34+
35+
36+
class coordinate_iterator {
37+
private:
38+
std::size_t m_dimension = 0;
39+
std::size_t m_edge = 0;
40+
clique_block_location m_coordinate;
41+
42+
public:
43+
coordinate_iterator(const std::size_t p_dimension, const std::size_t p_edge);
44+
45+
public:
46+
const clique_block_location & get_coordinate(void) const;
47+
clique_block_location & get_coordinate(void);
48+
49+
public:
50+
coordinate_iterator & operator++();
51+
};
52+
53+
54+
class clique : public cluster_algorithm {
55+
private:
56+
using block_map = std::unordered_map<std::string, clique_block *>;
57+
58+
private:
59+
std::size_t m_intervals = 0;
60+
std::size_t m_density_threshold = 0;
61+
62+
const dataset * m_data_ptr = nullptr;
63+
clique_data * m_result_ptr = nullptr;
64+
65+
block_map m_cells_map;
66+
67+
public:
68+
clique(const std::size_t p_intervals, const std::size_t p_threshold);
69+
70+
public:
71+
virtual void process(const dataset & p_data, cluster_data & p_result) override;
72+
73+
private:
74+
void create_grid(void);
75+
};
76+
77+
}
78+
79+
}

ccore/src/cluster/clique_block.cpp

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/**
2+
*
3+
* @authors Andrei Novikov ([email protected])
4+
* @date 2014-2019
5+
* @copyright GNU Public License
6+
*
7+
* GNU_PUBLIC_LICENSE
8+
* pyclustering is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* pyclustering is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
#include "cluster/clique_block.hpp"
24+
25+
26+
namespace ccore {
27+
28+
namespace clst {
29+
30+
31+
clique_spatial_block::clique_spatial_block(const point & p_max_corner, const point & p_min_corner) :
32+
m_max_corner(p_max_corner),
33+
m_min_corner(p_min_corner)
34+
{ }
35+
36+
bool clique_spatial_block::contains(const point & p_point) const {
37+
for (std::size_t i = 0; i < p_point.size(); ++i) {
38+
if ((p_point[i] < m_min_corner[i]) || (p_point[i] > m_max_corner[i])) {
39+
return false;
40+
}
41+
}
42+
43+
return true;
44+
}
45+
46+
const point & clique_spatial_block::get_max_corner(void) const {
47+
return m_max_corner;
48+
}
49+
50+
const point & clique_spatial_block::get_min_corner(void) const {
51+
return m_min_corner;
52+
}
53+
54+
55+
56+
clique_block::clique_block(const clique_block_location & p_location, const clique_spatial_block & p_block) :
57+
m_logical_location(p_location),
58+
m_spatial_location(p_block),
59+
m_points(),
60+
m_visited(false)
61+
{ }
62+
63+
const clique_block_location & clique_block::get_logical_location() const {
64+
return m_logical_location;
65+
}
66+
67+
const clique_spatial_block & clique_block::get_spatial_block(void) const {
68+
return m_spatial_location;
69+
}
70+
71+
const clique_block::content & clique_block::get_points(void) const {
72+
return m_points;
73+
}
74+
75+
bool clique_block::is_visited(void) const {
76+
return m_visited;
77+
}
78+
79+
void clique_block::touch(void) {
80+
m_visited = true;
81+
}
82+
83+
void clique_block::capture_points(const dataset & p_data, const std::vector<bool> p_availability) {
84+
for (std::size_t index_point = 0; index_point < p_data.size(); ++index_point) {
85+
if (p_availability[index_point] && m_spatial_location.contains(p_data[index_point])) {
86+
m_points.push_back(index_point);
87+
}
88+
}
89+
}
90+
91+
void clique_block::get_location_neighbors(const std::size_t p_edge, std::vector<clique_block_location> p_neighbors) {
92+
for (std::size_t index_dimension = 0; index_dimension < m_logical_location.size(); ++index_dimension) {
93+
if (m_logical_location[index_dimension] + 1 < p_edge) {
94+
clique_block_location position = m_logical_location;
95+
++position[index_dimension];
96+
p_neighbors.push_back(position);
97+
}
98+
99+
if (m_logical_location[index_dimension] - 1 >= 0) {
100+
clique_block_location position = m_logical_location;
101+
--position[index_dimension];
102+
p_neighbors.push_back(position);
103+
}
104+
}
105+
}
106+
107+
}
108+
109+
}

0 commit comments

Comments
 (0)