Vcsn  2.3a
Be Rational
rmin.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vcsn/core/join.hh>
4 #include <vcsn/misc/raise.hh>
5 #include <vcsn/misc/stream.hh> // eat
6 #include <vcsn/weightset/fwd.hh>
8 #include <vcsn/weightset/nmin.hh>
10 #include <vcsn/weightset/zmin.hh>
11 
12 namespace vcsn
13 {
14  namespace detail
15  {
16  class rmin_impl
17  : public min_plus_impl<rmin_impl, double>
18  {
19  public:
21  using self_t = rmin;
22  using value_t = typename super_t::value_t;
23 
24  static symbol sname()
25  {
26  static auto res = symbol{"rmin"};
27  return res;
28  }
29 
31  static rmin make(std::istream& is)
32  {
33  eat(is, sname());
34  return {};
35  }
36 
37  using super_t::conv;
38  static value_t
40  {
41  return v;
42  }
43 
44  static value_t
46  {
47  return v;
48  }
49 
50  static value_t
52  {
53  return v;
54  }
55 
56  static constexpr bool has_lightening_weights() { return true; }
57 
58  std::ostream&
59  print_set(std::ostream& o, format fmt = {}) const
60  {
61  switch (fmt.kind())
62  {
63  case format::latex:
64  o << "\\mathbb{R}_{\\text{min}}";
65  break;
66  case format::sname:
67  o << sname();
68  break;
69  case format::text:
70  o << "Rmin";
71  break;
72  case format::utf8:
73  o << "ℝmin";
74  break;
75  case format::raw:
76  assert(0);
77  break;
78  }
79  return o;
80  }
81  };
82 
83  // Random generation.
84  template <typename RandomGenerator>
85  class random_weight<rmin, RandomGenerator>
86  : public random_weight_base<rmin, RandomGenerator>
87  {
88  public:
90  using value_t = typename super_t::weight_t;
91 
92  using super_t::super_t;
93 
94  private:
96  {
97  auto dis =
98  std::uniform_real_distribution<rmin::value_t>(super_t::min_, super_t::max_);
99  return dis(super_t::gen_);
100  }
101  };
102 
107  }
108 
109  template <>
110  struct is_tropical<rmin> : std::true_type
111  {};
112 }
Print as is. For instance, don't try to escape labels.
Definition: format.hh:24
Print as a parsable type string.
Definition: format.hh:26
Generic declaration of the class which is specialized in each weightset.
Definition: weightset.hh:205
Print for LaTeX.
Definition: format.hh:22
typename super_t::value_t value_t
Definition: rmin.hh:22
Definition: a-star.hh:8
return res
Definition: multiply.hh:398
static constexpr bool has_lightening_weights()
Definition: rmin.hh:56
std::ostream & print_set(std::ostream &o, format fmt={}) const
Definition: rmin.hh:59
An input/output format for valuesets.
Definition: format.hh:13
Abstract class for random weight generation.
Definition: weightset.hh:112
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
Definition: symbol.hh:23
static value_t conv(self_t, value_t v)
Definition: rmin.hh:39
Print as rich UTF-8 text, escaped.
Definition: format.hh:30
static value_t conv(b, b::value_t v)
Definition: min-plus.hh:139
Print as plain (ASCII) text, escaped.
Definition: format.hh:28
weightset_mixin< detail::rmin_impl > rmin
Definition: fwd.hh:55
static symbol sname()
Definition: rmin.hh:24
VCSN_JOIN_SIMPLE(b, b)
char eat(std::istream &is, char c)
Check lookahead character and advance.
Definition: stream.cc:90
static value_t conv(zmin, const zmin::value_t v)
Definition: rmin.hh:51
static rmin make(std::istream &is)
Build from the description in is.
Definition: rmin.hh:31
static value_t conv(nmin, const nmin::value_t v)
Definition: rmin.hh:45
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:46