3 #include <boost/optional.hpp>
4 #include <boost/range/algorithm/find.hpp>
5 #include <boost/range/algorithm/find_if.hpp>
6 #include <boost/range/algorithm/for_each.hpp>
7 #include <boost/range/algorithm_ext/is_sorted.hpp>
22 template <
typename LabelSet>
24 = decltype(std::declval<LabelSet>().generators());
27 template <
typename LabelSet>
35 template <
typename LabelSet>
36 using one_t = decltype(std::declval<LabelSet>().one());
38 template <
typename LabelSet>
46 #if defined __GNUC__ && !defined __clang__
49 # pragma GCC diagnostic push
50 # pragma GCC diagnostic ignored "-Wsuggest-attribute=noreturn"
54 template <
typename LabelSet>
56 ->
typename LabelSet::value_t
58 return static_if<LabelSet::has_one()>
59 ([](
const auto& ls) {
return ls.one(); },
60 [](
const auto& ls) ->
typename LabelSet::value_t
62 raise(ls,
": does not feature a neutral");
67 #if defined __GNUC__ && !defined __clang__
68 # pragma GCC diagnostic pop
79 template <
typename LabelSet>
87 return std::make_shared<labelset_t>(
labelset_t{ls.genset()});
91 template <
typename LabelSet>
95 template <
typename LabelSet>
99 template <
typename LabelSet>
111 template <
typename Context>
117 template <
typename LabelSet,
typename WeightSet>
137 template <
typename LabelSet,
138 typename Enable =
void>
143 template <
typename LabelSet>
147 template <
typename LabelSet>
158 template <
typename Ctx>
163 template <
typename LabelSet,
typename WeightSet>
182 template <
typename LabelSet>
193 template <
typename LabelSet>
197 template <
typename LabelSet>
209 template <
typename Context>
215 template <
typename LabelSet,
typename WeightSet>
228 template <
typename Context>
234 template <
typename LabelSet,
typename WeightSet>
249 template <
typename ValueSet>
254 template <
typename LabelSet>
258 template <
typename LabelSet>
269 template <
typename Ctx>
274 template <
typename LabelSet,
typename WeightSet>
290 template <
typename LabelSet>
293 const std::vector<typename LabelSet::value_t>& letters,
294 const std::vector<typename LabelSet::value_t>& alphabet,
298 for (
auto it = std::begin(letters), letters_end = std::end(letters);
299 it != letters_end; ++it)
301 auto end = std::mismatch(it, letters_end,
302 boost::range::find(alphabet, *it),
303 alphabet.end()).first;
304 ls.print(*it, out, fmt);
306 auto width = std::distance(it, end);
314 ls.print(*it, out, fmt);
324 template <
typename LabelSet>
327 const std::vector<typename LabelSet::value_t>& letters,
331 using letters_t = std::vector<typename LabelSet::value_t>;
333 auto alphabet = letters_t{};
334 for (
auto l : ls.generators())
335 alphabet.emplace_back(ls.value(l));
343 && 2 * boost::distance(alphabet) < 3 * boost::distance(letters))
347 auto negated = letters_t{};
348 for (
auto l: alphabet)
350 negated.emplace_back(l);
361 template <
typename LabelSet>
362 typename LabelSet::letters_t
380 template <
typename LabelSet,
typename Fun>
384 using letter_t =
typename LabelSet::letter_t;
385 using letters_t =
typename LabelSet::letters_t;
389 auto alphabet = letters_t{};
390 for (
auto l : ls.generators())
398 auto prev = boost::optional<letter_t>{};
399 while (i.peek() != EOF && i.peek() !=
']')
406 ls.sname(),
": letter classes cannot begin with '-'");
408 ls.sname(),
": letter classes cannot finish with '-'");
411 letter_t l2 = ls.get_letter(i);
413 auto gens = ls.generators();
414 auto i = std::find(std::begin(gens), std::end(gens), *prev);
416 if (i != std::end(gens))
419 i != std::end(gens) && *i < l2;
432 letter_t l = ls.get_letter(i);
440 template <
typename LabelSet>
441 typename LabelSet::letters_t
444 using letter_t =
typename LabelSet::letter_t;
445 using letters_t =
typename LabelSet::letters_t;
454 template <
typename LabelSet,
455 typename RandomGenerator = std::default_random_engine>
456 typename LabelSet::value_t
458 RandomGenerator& gen = RandomGenerator())
460 require(!ls.generators().empty(),
461 "random_label: the alphabet needs at least 1 letter");
464 return ls.value(pick(ls.generators()));
context< nullableset_t< labelset_t_of< Ctx >>, weightset_t_of< Ctx >> nullableset_context_t
typename nullableset_traits< LabelSet >::type nullableset_t
The smallest nullableset that includes LabelSet.
free_context< context< LabelSet, WeightSet > > make_free_context(const context< LabelSet, WeightSet > &c)
The free context for c.
context< proper_t< letterized_t< labelset_t_of< Context >>>, weightset_t_of< Context >> free_context
context< proper_t< labelset_t_of< Context >>, weightset_t_of< Context >> proper_context
word_context_t< context< LabelSet, WeightSet > > make_word_context(const context< LabelSet, WeightSet > &ctx)
The wordset context of a context.
A traits to compute the letterized context.
An input/output format for valuesets.
proper_t< LabelSet > make_proper(const LabelSet &ls)
The corresponding proper LabelSet.
static type value(const LabelSet &ls)
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
decltype(std::declval< LabelSet >().one()) one_t
The smallest nullableset which includes LabelSet.
const weightset_ptr & weightset() const
Container set_difference(const Container &s1, const Container &s2)
The set of members of s1 that are not members of s2.
Functor to compare Values of ValueSets.
auto out(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions leaving state s.
random_selector< RandomGenerator > make_random_selector(RandomGenerator &g)
From a labelset, its non-nullable labelset.
typename law_traits< LabelSet >::type law_t
The smallest wordset that includes LabelSet.
bool_constant< letterized_traits< LabelSet >::is_letterized > is_letterized_t
auto label_one(const LabelSet &ls) -> typename LabelSet::value_t
Enjoy type inference.
std::integral_constant< bool, B > bool_constant
const labelset_ptr & labelset() const
typename letterized_traits< LabelSet >::labelset_t letterized_t
static labelset_t labelset(const labelset_t &ls)
context< letterized_t< labelset_t_of< Context >>, weightset_t_of< Context >> letterized_context
letterized_context< context< LabelSet, WeightSet > > make_letterized_context(const context< LabelSet, WeightSet > &c)
The letterized context for c.
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
context< law_t< labelset_t_of< Ctx >>, weightset_t_of< Ctx >> word_context_t
nullableset_context_t< context< LabelSet, WeightSet > > make_nullableset_context(const context< LabelSet, WeightSet > &ctx)
The nullableset context of a context.
bool none_of_equal(const Range &r, const Value &value)
LabelSet::letters_t conv_label_class_(const LabelSet &ls, std::istream &i)
Read a set of letters (hence, guaranteed in order, and unique).
expressionset< Context >::value_t random_label(const expressionset< Context > &rs, RandomGenerator &gen=RandomGenerator())
Random label from expressionset: limited to a single label.
auto make_proper_context(const context< LabelSet, WeightSet > &ctx) -> proper_context< context< LabelSet, WeightSet >>
From a context, its non-nullable context.
typename proper_traits< LabelSet >::type proper_t
The type of the corresponding proper LabelSet.
std::ostream & print_label_ranges_(const LabelSet &ls, const std::vector< typename LabelSet::value_t > &letters, const std::vector< typename LabelSet::value_t > &alphabet, std::ostream &out, format fmt)
Print a set of labels with ranges.
std::ostream & print_label_class(const LabelSet &ls, const std::vector< typename LabelSet::value_t > &letters, std::ostream &out, format fmt)
Print a set of labels (letterized) with classes.
letterized_t< LabelSet > make_letterized(const LabelSet &ls)
decltype(std::declval< LabelSet >().generators()) generators_mem_fn_t
The type of the LabelSet::generators() member function.
static constexpr bool is_letterized
law_t< LabelSet > make_wordset(const LabelSet &ls)
The wordset of a labelset.
nullableset_t< LabelSet > make_nullableset(const LabelSet &ls)
The nullableset of a labelset.