20 std::vector<unsigned short>::reserve(nclusters);
22 for (
size_t i = 0; i < nclusters; ++i) {
33 throw CMTException(Form(
"<<%s>> Two input clusters identical (%d)", __FUNCTION__, index1));
35 if (index1 >= this->
size() || index2 >= this->
size())
37 throw CMTException(Form(
"Input cluster index (%d and/or %d) out of range", index1, index2));
39 auto out_index1 = this->at(index1);
40 auto out_index2 = this->at(index2);
42 if (out_index1 == out_index2)
43 throw CMTException(Form(
"Cluster %d and %d already merged!", index1, index2));
45 if (out_index2 < out_index1) std::swap(out_index1, out_index2);
55 throw CMTException(Form(
"<<%s>> Two input clusters identical (%d)", __FUNCTION__, index1));
57 if (index1 >= this->
size() || index2 >= this->
size())
59 throw CMTException(Form(
"Input cluster index (%d and/or %d) out of range", index1, index2));
61 auto out_index1 = this->at(index1);
62 auto out_index2 = this->at(index2);
64 if (out_index1 == out_index2)
return true;
66 if (out_index2 < out_index1) std::swap(out_index1, out_index2);
76 throw CMTException(Form(
"<<%s>> Two input clusters identical (%d)", __FUNCTION__, index1));
78 if (index1 >= this->
size() || index2 >= this->
size())
80 throw CMTException(Form(
"Input cluster index (%d and/or %d) out of range", index1, index2));
82 auto out_index1 = this->at(index1);
83 auto out_index2 = this->at(index2);
85 if (out_index1 == out_index2)
return;
87 if (out_index2 < out_index1) std::swap(out_index1, out_index2);
92 Form(
"Clusters (%d,%d) correspond to output (%d,%d) which is prohibited to merge",
101 for (
auto& v : (*
this)) {
103 if (v == out_index1 || v == out_index2)
105 else if (v > out_index2)
113 for (
size_t index = 0; index < out_index1; ++index) {
115 size_t tmp_out_index1 = out_index1 - index;
116 size_t tmp_out_index2 = out_index2 - index;
122 for (
size_t in_index = tmp_out_index2;
142 for (
size_t in_index = 1;
146 if ((in_index + out_index1) < out_index2) {
155 _prohibit_merge.at(in_index + out_index1).at(out_index2 - (in_index + out_index1)));
171 _prohibit_merge.at(out_index2).at(in_index + 1 + out_index1 - out_index2));
178 for (
size_t index = out_index1 + 1; index < out_index2; ++index) {
179 for (
size_t in_index = (out_index2 - index);
190 for (
size_t index = out_index2;
195 for (
size_t in_index = 0; in_index <
_prohibit_merge.at(index).size(); ++in_index)
209 std::cout <<
"Merge Result:" << std::endl;
210 for (
auto const& v : *
this)
211 std::cout << v <<
" ";
212 std::cout << std::endl << std::endl;
214 std::cout <<
"Prohibit Status:" << std::endl;
217 for (
auto const& b : bs) {
220 std::cout <<
"\033[93mT\033[00m ";
222 std::cout <<
"\033[95mF\033[00m ";
224 std::cout << std::endl;
226 std::cout << std::endl;
231 if (index1 >= this->
size() || index2 >= this->
size())
232 throw CMTException(Form(
"Invalid cluster index: %d or %d", index1, index2));
234 return this->at(index1) == this->at(index2);
240 if (index1 >= this->
size())
throw CMTException(Form(
"Invalid cluster index: %d ", index1));
242 auto out_index = this->at(index1);
243 std::vector<unsigned short> result;
245 for (
size_t i = 0; i < this->
size(); ++i)
246 if (this->at(i) == out_index) result.push_back(i);
257 for (
size_t i = 0; i < this->
size(); ++i)
258 result.at(this->at(i)).push_back(i);
264 std::vector<std::vector<unsigned short>> my_result;
266 if (my_result.size() != another.size()) {
268 Form(
"Input has an incompatible size (%zu != %zu)", my_result.size(), another.size()));
273 std::vector<std::vector<unsigned short>> another_result;
275 if (another_result.size() >= my_result.size())
276 throw CMTException(Form(
"The input has equal or more number of output clusters (%zu>=%zu)",
277 another_result.size(),
281 for (
auto const& ares : another_result) {
283 if (ares.size() == 1)
continue;
286 unsigned short target = my_result.at(ares.at(0)).at(0);
288 for (
auto const& res_index : ares) {
290 for (
auto const& orig_index : my_result.at(res_index)) {
292 if (target == orig_index)
296 this->
Merge(target, orig_index);
Class def header for a class CMergeBookKeeper.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Class def header for exception classes in CMTException.
cout<< "-> Edep in the target