Vcsn  2.4
Be Rational
random-weight.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <random> // std::mt19937
4 
5 #include <vcsn/ctx/traits.hh>
6 #include <vcsn/dyn/context.hh>
7 #include <vcsn/dyn/value.hh>
8 #include <vcsn/weightset/weightset.hh> // detail::random_weight.
9 
10 namespace vcsn
11 {
13  template <typename WeightSet>
14  typename WeightSet::value_t
15  random_weight(const WeightSet& ws, const std::string& param = {})
16  {
17  auto random_w
19  std::mt19937>{make_random_engine(), ws};
20  random_w.parse_param(param);
21  return random_w.generate_random_weight();
22  }
23 
24  namespace dyn
25  {
26  namespace detail
27  {
29  template <typename Context, typename String>
30  weight
31  random_weight(const context& ctx, const std::string& param)
32  {
33  const auto& c = ctx->as<Context>();
34  const auto& ws = *c.weightset();
35  return {ws, random_weight(ws, param)};
36  }
37  }
38  }
39 }
value_impl< detail::weight_tag > weight
Definition: fwd.hh:28
weight random_weight(const context &ctx, const std::string &param)
Bridge.
WeightSet::value_t random_weight(const WeightSet &ws, const std::string &param={})
Generate a random weight.
std::mt19937 & make_random_engine()
Generate a unique random device.
Definition: random.cc:6
auto & as()
Downcast to the exact type.
Definition: context.hh:36
Definition: a-star.hh:8
Template-less root for contexts.
Definition: context.hh:16