Vcsn  2.4
Be Rational
vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator > Class Template Reference

Class random expression generator. More...

#include <random-expression.hh>

Collaboration diagram for vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >:

Public Types

using expressionset_t = ExpressionSet
 
using expression_t = typename expressionset_t::value_t
 
using weight_t = typename expressionset_t::weight_t
 
using weightset_t = typename expressionset_t::weightset_t
 

Public Member Functions

 random_expression_impl (const expressionset_t &rs, const std::string &param, RandomGenerator &gen)
 
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 <+). More...
 
std::string random_expression_string () const
 A random expression string (not parsed, so there might be some syntactic sugar such as <+). More...
 
expression_t random_expression () const
 A random expression (parsed, so there cannot be syntactic sugar such as <+). More...
 

Private Member Functions

void parse_param_ (const std::string &param)
 FIXME: maybe use something similar to Boost.ProgramOptions or getargs. More...
 
void print_weight_ (std::ostream &out) const
 Print random weight. More...
 
void print_label_ (std::ostream &out) const
 Print label. More...
 
void print_unary_exp_ (std::ostream &out, unsigned length, const std::string &op) const
 Print expression with unary operator. More...
 
void print_binary_exp_ (std::ostream &out, unsigned length, const std::string &op) const
 Print binary expression with binary operator. More...
 
std::ostream & print_random_expression_ (std::ostream &out, unsigned length) const
 

Private Attributes

expressionset_t rs_
 
weightset_t ws_
 
unsigned length_
 
std::map< std::string, floatoperators_
 For each operator, its probability. More...
 
std::unordered_map< std::string, int > arities_
 Number of arguments of each operator. More...
 
std::vector< floatproba_op_
 Vector of weights associated with the operators, i.e., the probabilities to pick each operator. More...
 
RandomGenerator & gen_
 Random generator. More...
 
random_weight< weightset_t, RandomGenerator > random_weight_ {gen_, ws_}
 Random weights generator. More...
 
discrete_chooser< RandomGenerator > chooser_it_ {gen_}
 

Detailed Description

template<typename ExpressionSet, typename RandomGenerator = std::default_random_engine>
class vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >

Class random expression generator.

Generate a random expression from a context.

Template Parameters
ExpressionSetthe expression set type.
RandomGeneratorthe random number engine type.

Definition at line 29 of file random-expression.hh.

Member Typedef Documentation

template<typename ExpressionSet , typename RandomGenerator = std::default_random_engine>
using vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::expression_t = typename expressionset_t::value_t

Definition at line 33 of file random-expression.hh.

template<typename ExpressionSet , typename RandomGenerator = std::default_random_engine>
using vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::expressionset_t = ExpressionSet

Definition at line 32 of file random-expression.hh.

template<typename ExpressionSet , typename RandomGenerator = std::default_random_engine>
using vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::weight_t = typename expressionset_t::weight_t

Definition at line 34 of file random-expression.hh.

template<typename ExpressionSet , typename RandomGenerator = std::default_random_engine>
using vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::weightset_t = typename expressionset_t::weightset_t

Definition at line 35 of file random-expression.hh.

Constructor & Destructor Documentation

template<typename ExpressionSet , typename RandomGenerator = std::default_random_engine>
vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::random_expression_impl ( const expressionset_t rs,
const std::string &  param,
RandomGenerator &  gen 
)
inline

Definition at line 37 of file random-expression.hh.

Member Function Documentation

template<typename ExpressionSet , typename RandomGenerator = std::default_random_engine>
void vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::parse_param_ ( const std::string &  param)
inlineprivate
template<typename ExpressionSet , typename RandomGenerator = std::default_random_engine>
void vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::print_binary_exp_ ( std::ostream &  out,
unsigned  length,
const std::string &  op 
) const
inlineprivate

Print binary expression with binary operator.

It is composed of the left and right side, and the operator. The number of symbols is randomly distribued between both side.

Definition at line 149 of file random-expression.hh.

References vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::gen_, vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::print_label_(), and vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::print_random_expression_().

Referenced by vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::print_random_expression_().

Here is the call graph for this function:

template<typename ExpressionSet , typename RandomGenerator = std::default_random_engine>
void vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::print_label_ ( std::ostream &  out) const
inlineprivate
template<typename ExpressionSet , typename RandomGenerator = std::default_random_engine>
std::ostream& vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::print_random_expression ( std::ostream &  out) const
inline

Print a random expression string (not parsed, so there might be some syntactic sugar such as <+).

Definition at line 48 of file random-expression.hh.

References vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::length_, and vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::print_random_expression_().

Referenced by vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::random_expression_string().

Here is the call graph for this function:

template<typename ExpressionSet , typename RandomGenerator = std::default_random_engine>
void vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::print_unary_exp_ ( std::ostream &  out,
unsigned  length,
const std::string &  op 
) const
inlineprivate

Print expression with unary operator.

Definition at line 119 of file random-expression.hh.

References vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::print_random_expression_(), and vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::print_weight_().

Referenced by vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::print_random_expression_().

Here is the call graph for this function:

template<typename ExpressionSet , typename RandomGenerator = std::default_random_engine>
void vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::print_weight_ ( std::ostream &  out) const
inlineprivate

Print random weight.

Definition at line 105 of file random-expression.hh.

References vcsn::detail::out(), vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::random_weight_, and vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::rs_.

Referenced by vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::print_unary_exp_().

Here is the call graph for this function:

template<typename ExpressionSet , typename RandomGenerator = std::default_random_engine>
expression_t vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::random_expression ( ) const
inline

A random expression (parsed, so there cannot be syntactic sugar such as <+).

Definition at line 64 of file random-expression.hh.

References vcsn::conv(), vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::random_expression_string(), and vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::rs_.

Here is the call graph for this function:

template<typename ExpressionSet , typename RandomGenerator = std::default_random_engine>
std::string vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::random_expression_string ( ) const
inline

A random expression string (not parsed, so there might be some syntactic sugar such as <+).

Definition at line 55 of file random-expression.hh.

References vcsn::detail::out(), and vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::print_random_expression().

Referenced by vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::random_expression().

Here is the call graph for this function:

Member Data Documentation

template<typename ExpressionSet , typename RandomGenerator = std::default_random_engine>
std::unordered_map<std::string, int> vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::arities_
private
Initial value:
{
{"\\e", 0},
{"\\z", 0},
{"!", 1},
{"{c}", 1},
{"*", 1},
{"{T}", 1},
{"w.", 1},
{".w", 1},
{"&", 2},
{"&:", 2},
{":", 2},
{".", 2},
{"<+", 2},
{"%", 2},
{"+", 2},
{"{/}", 2},
{"{\\}",2},
}

Number of arguments of each operator.

Definition at line 210 of file random-expression.hh.

Referenced by vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::parse_param_(), and vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::print_random_expression_().

template<typename ExpressionSet , typename RandomGenerator = std::default_random_engine>
discrete_chooser<RandomGenerator> vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::chooser_it_ {gen_}
private
template<typename ExpressionSet , typename RandomGenerator = std::default_random_engine>
RandomGenerator& vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::gen_
private
template<typename ExpressionSet , typename RandomGenerator = std::default_random_engine>
unsigned vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::length_
private
template<typename ExpressionSet , typename RandomGenerator = std::default_random_engine>
std::map<std::string, float> vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::operators_
private
template<typename ExpressionSet , typename RandomGenerator = std::default_random_engine>
std::vector<float> vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::proba_op_
private

Vector of weights associated with the operators, i.e., the probabilities to pick each operator.

Definition at line 235 of file random-expression.hh.

Referenced by vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::parse_param_(), and vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::print_random_expression_().

template<typename ExpressionSet , typename RandomGenerator = std::default_random_engine>
random_weight<weightset_t, RandomGenerator> vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::random_weight_ {gen_, ws_}
private
template<typename ExpressionSet , typename RandomGenerator = std::default_random_engine>
weightset_t vcsn::detail::random_expression_impl< ExpressionSet, RandomGenerator >::ws_
private

Definition at line 204 of file random-expression.hh.


The documentation for this class was generated from the following file: