Vcsn  2.4
Be Rational
zmin.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 
11 namespace vcsn
12 {
13  namespace detail
14  {
15  class zmin_impl
16  : public min_plus_impl<zmin_impl, int>
17  {
18  public:
20  using self_t = zmin;
21  using value_t = typename super_t::value_t;
22 
23  static symbol sname()
24  {
25  static auto res = symbol{"zmin"};
26  return res;
27  }
28 
30  static zmin make(std::istream& is)
31  {
32  eat(is, sname());
33  return {};
34  }
35 
36  using super_t::conv;
37  static value_t
39  {
40  return v;
41  }
42 
43  static value_t
45  {
46  return v;
47  }
48 
49  static constexpr bool has_lightening_weights() { return true; }
50 
51  std::ostream&
52  print_set(std::ostream& o, format fmt = {}) const
53  {
54  switch (fmt.kind())
55  {
56  case format::latex:
57  o << "\\mathbb{Z}_{\\text{min}}";
58  break;
59  case format::sname:
60  o << sname();
61  break;
62  case format::text:
63  o << "Zmin";
64  break;
65  case format::utf8:
66  o << "ℤmin";
67  break;
68  case format::raw:
69  assert(0);
70  break;
71  }
72  return o;
73  }
74  };
75 
76  // Random generation.
77  template <typename RandomGenerator>
78  class random_weight<zmin, RandomGenerator>
79  : public random_weight_base<zmin, RandomGenerator>
80  {
81  public:
83  using value_t = typename super_t::weight_t;
84 
85  using super_t::super_t;
86 
87  private:
89  {
90  auto dis = std::uniform_int_distribution<>(super_t::min_, super_t::max_);
91  return dis(super_t::gen_);
92  }
93  };
94 
98  }
99 
100  template <>
101  struct is_tropical<zmin> : std::true_type
102  {};
103 }
std::ostream & print_set(std::ostream &o, format fmt={}) const
Definition: zmin.hh:52
Print as is. For instance, don't try to escape labels.
Definition: format.hh:24
char eat(std::istream &is, char c)
Check lookahead character and advance.
Definition: stream.cc:90
static symbol sname()
Definition: zmin.hh:23
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
return res
Definition: multiply.hh:398
VCSN_JOIN_SIMPLE(b, b)
Print for LaTeX.
Definition: format.hh:22
An input/output format for valuesets.
Definition: format.hh:13
Abstract class for random weight generation.
Definition: weightset.hh:112
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:46
static value_t conv(nmin, const nmin::value_t v)
Definition: zmin.hh:44
static constexpr bool has_lightening_weights()
Definition: zmin.hh:49
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
Definition: symbol.hh:23
Definition: a-star.hh:8
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
typename super_t::value_t value_t
Definition: zmin.hh:21
static value_t conv(self_t, value_t v)
Definition: zmin.hh:38
Print as plain (ASCII) text, escaped.
Definition: format.hh:28
static zmin make(std::istream &is)
Build from the description in is.
Definition: zmin.hh:30
weightset_mixin< detail::zmin_impl > zmin
Definition: fwd.hh:57