5 #include <boost/algorithm/string/erase.hpp>
6 #include <boost/tokenizer.hpp>
27 template <
typename ExpressionSet,
28 typename RandomGenerator = std::default_random_engine>
36 const std::string& param, RandomGenerator& gen)
54 std::ostringstream
out;
75 using tokenizer = boost::tokenizer<boost::char_separator<char>>;
76 auto sep = boost::char_separator<char>{
","};
77 auto tok = tokenizer(param, sep);
78 for (
auto it = tok.begin(); it != tok.end(); ++it)
80 auto tok_arg = std::string{*it};
81 auto eq = tok_arg.find_first_of(
'=');
82 auto op = tok_arg.substr(0, eq);
83 boost::algorithm::erase_all(op,
" ");
85 if (eq != std::string::npos)
89 else if (op ==
"length")
92 raise(
"random_expression: invalid operator: ", op);
99 const std::string& op)
const
121 const std::string& op)
const
127 auto dis = std::uniform_int_distribution<>(1, length - 1);
128 auto num_lhs = dis(
gen_);
146 else if (length == 1)
180 template <
typename ExpressionSet,
typename RandomGenerator = std::mt19937>
183 const std::string& param,
186 return {
rs, param, gen};
198 template <
typename ExpressionSet>
203 return random_exp.random_expression_string();
208 template <
typename ExpressionSet>
209 typename ExpressionSet::value_t
213 return random_exp.random_expression();
221 template <
typename Context,
typename String,
typename Identities>
226 const auto& c = ctx->
as<Context>();
void print_binary_exp_(std::ostream &out, unsigned length, const std::string &op) const
Print binary expression with binary operator.
ExpressionSet::value_t random_expression(const ExpressionSet &rs, const std::string ¶m)
Generate a random expression.
void print_unary_exp_(std::ostream &out, unsigned length, const std::string &op) const
Print expression with unary operator.
expression_t random_expression() const
A random expression (parsed, so there cannot be syntactic sugar such as <+).
std::mt19937 & make_random_engine()
Generate a unique random device.
Class random expression generator.
Random selector on container, using discrete distribution.
auto out(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions leaving state s.
auto conv(const ValueSet &vs, const std::string &str, Args &&...args) -> decltype(vs.conv(std::declval< std::istream & >(), std::forward< Args >(args)...))
Parse str via vs.conv.
std::string random_expression_string(const ExpressionSet &rs, const std::string ¶m)
Generate a random expression string.
auto & as()
Downcast to the exact type.
std::ostream & print_random_expression(std::ostream &out) const
Print a random expression string (not parsed, so there might be some syntactic sugar such as <+)...
operator_set_t nullary_op_
std::ostream & print_random_expression_(std::ostream &out, unsigned length) const
std::string random_expression_string() const
A random expression string (not parsed, so there might be some syntactic sugar such as <+)...
ATTRIBUTE_PURE bool has(const boost::container::flat_set< Key, Compare, Allocator > &s, const Key &e)
Whether e is member of s.
Template-less root for contexts.
operator_set_t binary_op_
random_expression_impl(const expressionset_t &rs, const std::string ¶m, RandomGenerator &gen)
std::vector< float > weight_t
T lexical_cast(const std::string &str)
String to templated type T conversion.
void parse_param_(const std::string ¶m)
auto make_expressionset(const context< LabelSet, WeightSet > &ctx, rat::identities ids={}) -> expressionset< context< LabelSet, WeightSet >>
Shorthand to expressionset constructor.
std::unordered_set< std::string > operator_set_t
oneset::value_t random_label(const oneset &ls, RandomGenerator &=RandomGenerator())
Random label from oneset.
std::map< std::string, float > operator_t
random_expression_impl< ExpressionSet, RandomGenerator > make_random_expression_impl(const ExpressionSet &rs, const std::string ¶m, RandomGenerator &gen=make_random_engine())
Convenience constructor.
ExpressionSet expressionset_t
typename expressionset_t::value_t expression_t
static identities ids(const driver &d)
Get the identities of the driver.
auto transform(const Container &c, Fun &&fun)
Map a unary function on a container of values, and return the vector the results. ...
value_impl< detail::expression_tag > expression
expression random_expression(const context &ctx, const std::string ¶m, identities ids)
Bridge.