Skip to content

Commit

Permalink
Start implementing to_human_readable_repr functions and improve const…
Browse files Browse the repository at this point in the history
…ructors
  • Loading branch information
reiniscirpons committed Sep 18, 2024
1 parent 19600e2 commit b1f4a03
Show file tree
Hide file tree
Showing 3 changed files with 512 additions and 551 deletions.
175 changes: 171 additions & 4 deletions include/libsemigroups/sims.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2007,7 +2007,9 @@ namespace libsemigroups {
using SimsSettings<MinimalRepOrc>::stats;

//! Default constructor
MinimalRepOrc() = default;
MinimalRepOrc() : _size() {
init();
}

//! \brief Reinitialize an existing MinimalRepOrc object.
//!
Expand Down Expand Up @@ -3087,7 +3089,21 @@ namespace libsemigroups {
std::vector<word_type> _forbid;

public:
//! \brief Default constructor.
//! Default constructor.
explicit SimsRefinerFaithful() : _forbid() {}

//! \brief Reinitialize an existing SimsRefinerFaithful object.
//!
//! This function puts an object back into the same state as if it had
//! been newly default constructed.
//!
//! \returns A reference to \c *this.
SimsRefinerFaithful& init() {
_forbid.clear();
return *this;
}

//! \brief Construct from set of forbidden pairs.
//!
//! Constructs a SimsRefinerFaithful pruner with respect to the set of
//! forbidden relations in \p forbid.
Expand All @@ -3112,6 +3128,38 @@ namespace libsemigroups {
explicit SimsRefinerFaithful(std::vector<word_type> const& forbid)
: _forbid(forbid) {}

//! \brief Reinitialize an existing SimsRefinerFaithful object from a set of
//! forbidden pairs.
//!
//! This function puts an object back into the same state as if it had
//! been newly constructed from set of forbidden pairs \p forbid.
//!
//! \returns A reference to \c *this.
//!
//! \warning
//! This method does not verify if \p forbid contains trivial pairs or not.
SimsRefinerFaithful& init(std::vector<word_type> const& forbid) {
_forbid.clear();
_forbid = forbid;
return *this;
}

//! \brief Get the forbidden pairs defining the refiner.
//!
//! \anchor forbid
//! Returns a const reference to the current forbidden pairs.
//!
//! This function returns the defining forbidden pairs of a
//! SimsRefinerFaithful instance.
//!
//! \returns A const reference to `std::vector<word_type>`.
//!
//! \exceptions
//! \noexcept
[[nodiscard]] std::vector<word_type> const& forbid() const noexcept {
return _forbid;
}

//! \brief Check if a word graph can be extended to one defining a faithful
//! congruence.
//!
Expand Down Expand Up @@ -3165,7 +3213,22 @@ namespace libsemigroups {
KnuthBendix<> _knuth_bendix;

public:
//! \brief Default constructor.
//! Default constructor.
explicit SimsRefinerIdeals() : _knuth_bendix(congruence_kind::twosided) {}

//! \brief Reinitialize an existing SimsRefinerIdeals object.
//!
//! This function puts an object back into the same state as if it had
//! been newly default constructed.
//!
//! \returns A reference to \c *this.
template <typename Word>
SimsRefinerIdeals& init() {
_knuth_bendix.init(congruence_kind::twosided);
return *this;
}

//! \brief Construct from presentation.
//!
//! Constructs a SimsRefinerIdeals pruner for the semigroup or monoid
//! defined by \p p.
Expand All @@ -3174,7 +3237,8 @@ namespace libsemigroups {
//! This method assumes that KnuthBendix terminates on the input
//! presentation \p p. If this is not the case then th pruner may not
//! terminate on certain inputs.
explicit SimsRefinerIdeals(Presentation<std::string> const& p)
template <typename Word>
explicit SimsRefinerIdeals(Presentation<Word> const& p)
: _knuth_bendix(congruence_kind::twosided, p) {}

//! \brief Reinitialize an existing SimsRefinerIdeals object from a
Expand Down Expand Up @@ -3272,5 +3336,108 @@ namespace libsemigroups {
}
};

//! \ingroup congruence_group
//!
//! \brief Return a human readable representation of a SimsStats object.
//!
//! Return a human readable representation of a SimsStats object.
//!
//! \param x the SimsStats object.
//!
//! \exceptions
//! \no_libsemigroups_except
[[nodiscard]] std::string to_human_readable_repr(SimsStats const& x);

// TODO(0): Remove
// //! \ingroup congruence_group
// //!
// //! \brief Return a human readable representation of a SimsSettings object.
// //!
// //! Return a human readable representation of a SimsSettings object.
// //!
// //! \param x the SimsSettings object.
// //!
// //! \exceptions
// //! \no_libsemigroups_except
// // TODO(1) to tpp
// template <typename Subclass>
// [[nodiscard]] std::string
// target size 0 and to_human_readable_repr(SimsSettings<Subclass> const& x);

//! \ingroup congruence_group
//!
//! \brief Return a human readable representation of a Sims1 object.
//!
//! Return a human readable representation of a Sims1 object.
//!
//! \param x the Sims1 object.
//!
//! \exceptions
//! \no_libsemigroups_except
[[nodiscard]] std::string to_human_readable_repr(Sims1 const& x);

//! \ingroup congruence_group
//!
//! \brief Return a human readable representation of a Sims2 object.
//!
//! Return a human readable representation of a Sims2 object.
//!
//! \param x the Sims2 object.
//!
//! \exceptions
//! \no_libsemigroups_except
[[nodiscard]] std::string to_human_readable_repr(Sims2 const& x);

//! \ingroup congruence_group
//!
//! \brief Return a human readable representation of a RepOrc object.
//!
//! Return a human readable representation of a RepOrc object.
//!
//! \param x the RepOrc object.
//!
//! \exceptions
//! \no_libsemigroups_except
[[nodiscard]] std::string to_human_readable_repr(RepOrc const& x);

//! \ingroup congruence_group
//!
//! \brief Return a human readable representation of a MinimalRepOrc object.
//!
//! Return a human readable representation of a MinimalRepOrc object.
//!
//! \param x the MinimalRepOrc object.
//!
//! \exceptions
//! \no_libsemigroups_except
[[nodiscard]] std::string to_human_readable_repr(MinimalRepOrc const& x);

//! \ingroup congruence_group
//!
//! \brief Return a human readable representation of a SimsRefinerIdeals
//! object.
//!
//! Return a human readable representation of a SimsRefinerIdeals object.
//!
//! \param x the SimsRefinerIdeals object.
//!
//! \exceptions
//! \no_libsemigroups_except
[[nodiscard]] std::string to_human_readable_repr(SimsRefinerIdeals const& x);

//! \ingroup congruence_group
//!
//! \brief Return a human readable representation of a SimsRefinerFaithful
//! object.
//!
//! Return a human readable representation of a SimsRefinerFaithful object.
//!
//! \param x the SimsRefinerIdeals object.
//!
//! \exceptions
//! \no_libsemigroups_except
[[nodiscard]] std::string
to_human_readable_repr(SimsRefinerFaithful const& x);

} // namespace libsemigroups
#endif // LIBSEMIGROUPS_SIMS_HPP_
103 changes: 103 additions & 0 deletions src/sims.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ namespace libsemigroups {
template <typename Subclass>
SimsSettings<Subclass>::SimsSettings()
: _exclude(),
_exclude_pruner_added(false),
_idle_thread_restarts(64),
_include(),
_longs_begin(),
Expand All @@ -105,6 +106,7 @@ namespace libsemigroups {
template <typename Subclass>
Subclass& SimsSettings<Subclass>::init() {
_exclude.clear();
_exclude_pruner_added = false;
_idle_thread_restarts = 64;
_include.clear();
_num_threads = 1;
Expand Down Expand Up @@ -1438,4 +1440,105 @@ namespace libsemigroups {

} // namespace sims

[[nodiscard]] std::string to_human_readable_repr(SimsStats const& x) {
return fmt::format("<SimsStats object>");
}

namespace helper {

template <typename Subclass>
[[nodiscard]] std::string
sims_to_human_readable_repr_helper(SimsSettings<Subclass> const& x,
std::string extra_text) {
std::string result = "";
bool needs_and = false;

result += fmt::format("object over {} with",
to_human_readable_repr(x.presentation()));
std::string comma = x.pruners().empty() && extra_text.empty() ? "" : ",";
if ((x.include().size() > 0) && (x.exclude().size() > 0)) {
result += fmt::format(" {} include and {} exclude pairs{}",
x.include().size() / 2,
x.exclude().size() / 2,
comma);
needs_and = true;
} else if (x.include().size() > 0) {
result += fmt::format(" {} include pair{}{}",
x.include().size() / 2,
x.include().size() / 2 == 1 ? "" : "s",
comma);
needs_and = true;
} else if (x.exclude().size() > 0) {
result += fmt::format(" {} exclude pair{}{}",
x.exclude().size() / 2,
x.exclude().size() / 2 == 1 ? "" : "s",
comma);
needs_and = true;
}

result += extra_text;
if (extra_text.size()) {
needs_and = true;
}

if (x.pruners().size() > 0) {
result += fmt::format(" {} pruner{}",
x.pruners().size(),
x.pruners().size() == 1 ? "" : "s");
needs_and = true;
}
result += needs_and ? " and" : "";
result += fmt::format(" {} thread{}",
x.number_of_threads(),
x.number_of_threads() == 1 ? "" : "s");
return result;
}

} // namespace helper

// template <typename Subclass>
// [[nodiscard]] std::string
// to_human_readable_repr(SimsSettings<Subclass> const& x) {
// return fmt::format("<SimsSettings {}>",
// helper::sims_to_human_readable_repr_helper(x, ""));
// }

[[nodiscard]] std::string to_human_readable_repr(Sims1 const& x) {
return fmt::format("<Sims1 {}>",
helper::sims_to_human_readable_repr_helper(x, ""));
}

[[nodiscard]] std::string to_human_readable_repr(Sims2 const& x) {
return fmt::format("<Sims2 {}>",
helper::sims_to_human_readable_repr_helper(x, ""));
}

[[nodiscard]] std::string to_human_readable_repr(RepOrc const& x) {
return fmt::format("<RepOrc {}>",
helper::sims_to_human_readable_repr_helper(
x,
fmt::format(" node bounds [{}, {}), target size {}",
x.min_nodes(),
x.max_nodes(),
x.target_size())));
}

[[nodiscard]] std::string to_human_readable_repr(MinimalRepOrc const& x) {
return fmt::format("<MinimalRepOrc {}>",
helper::sims_to_human_readable_repr_helper(
x, fmt::format(" target size {}", x.target_size())));
}

[[nodiscard]] std::string to_human_readable_repr(SimsRefinerIdeals const& x) {
return fmt::format("<SimsRefinerIdeals object over presentation {}>",
to_human_readable_repr(x.presentation()));
}

[[nodiscard]] std::string
to_human_readable_repr(SimsRefinerFaithful const& x) {
return fmt::format("<SimsRefinerFaithful object with {} forbidden pair{}>",
x.forbid().size() / 2,
x.forbid().size() / 2 == 1 ? "" : "s");
}

} // namespace libsemigroups
Loading

0 comments on commit b1f4a03

Please sign in to comment.