// // libsemigroups - C++ library for semigroups and monoids // Copyright (C) 2021 James D. Mitchell // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. //
// This file contains the implementation of the Bipartition and Blocks classes.
#include"libsemigroups/bipart.hpp"
#include <limits> // for numeric_limits #include <numeric> // for iota #include <thread> // for get_id #include <thread> // for thread
#include"libsemigroups/constants.hpp"// for UNDEFINED, operator==, operator!= #include"libsemigroups/exception.hpp"// for LIBSEMIGROUPS_EXCEPTION #include"libsemigroups/report.hpp"// for THREAD_ID_MANAGER, ThreadIdManager
std::vector<uint32_t>
blocks_to_list(std::vector<std::vector<int32_t>> const& blocks) {
int32_t m = 0; for (std::vector<int32_t> const& b : blocks) {
m = std::max(std::abs(*std::max_element(b.cbegin(), b.cend())), m);
}
std::vector<uint32_t> out
= std::vector<uint32_t>(2 * m, std::numeric_limits<uint32_t>::max());
for (uint32_t i = 0; i < blocks.size(); ++i) { for (int32_t x : blocks[i]) { if (x < 0) {
out[static_cast<uint32_t>(m - x - 1)] = i;
} else {
out[static_cast<uint32_t>(x - 1)] = i;
}
}
}
LIBSEMIGROUPS_ASSERT(std::find(out.begin(),
out.end(),
std::numeric_limits<uint32_t>::max())
== out.end()); return out;
}
// TODO(later) check other things like _nr_blocks is correct etc... void validate(Bipartition const& x) {
size_t const n = static_cast<size_t>(std::distance(x.cbegin(), x.cend())); if (2 * x.degree() != n) {
LIBSEMIGROUPS_EXCEPTION( "the degree of a bipartition must be even, found %llu", uint64_t(n));
}
size_t next = 0; for (size_t i = 0; i < n; ++i) { if (x[i] == next) {
++next;
} elseif (x[i] > next) {
LIBSEMIGROUPS_EXCEPTION( "expected %llu but found %llu, in position %llu",
uint64_t(next),
uint64_t(x[i]),
uint64_t(i));
}
}
}
// TODO(later) Should be defined for all of the new element types
Bipartition operator*(Bipartition const& x, Bipartition const& y) {
Bipartition xy(x.degree());
xy.product_inplace(x, y); return xy;
}
// multiply x and y into this void Bipartition::product_inplace(Bipartition const& x,
Bipartition const& y,
size_t thread_id) {
LIBSEMIGROUPS_ASSERT(x.degree() == y.degree());
LIBSEMIGROUPS_ASSERT(x.degree() == degree());
LIBSEMIGROUPS_ASSERT(&x != this && &y != this);
uint32_t n = degree();
autoconst& xx = static_cast<Bipartition const&>(x); autoconst& yy = static_cast<Bipartition const&>(y);
Blocks* Bipartition::left_blocks() {
Blocks* result = new Blocks(cbegin_left_blocks(), cend_left_blocks());
size_t const n = degree(); for (size_t i = 0; i < n; ++i) {
result->set_is_transverse_block((*this)[i],
is_transverse_block((*this)[i]));
} return result;
}
Blocks* Bipartition::right_blocks() {
Blocks* result = new Blocks(cbegin_right_blocks(), cend_right_blocks());
size_t const n = degree(); for (size_t i = n; i < 2 * n; ++i) {
result->set_is_transverse_block((*result)[i - n],
is_transverse_block((*this)[i]));
} return result;
}
} // namespace libsemigroups
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.