17 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_SEMIRING_TROPICAL_SEMIRING_HXX
18 # define VCSN_ALGEBRA_IMPLEMENTATION_SEMIRING_TROPICAL_SEMIRING_HXX
20 # include <vaucanson/algebra/implementation/semiring/tropical_semiring.hh>
31 template<
class TropicalKind,
typename T>
32 T identity_value(
SELECTOR(algebra::TropicalSemiring<TropicalKind>),
SELECTOR(T))
37 template<
class TropicalKind,
typename T>
38 bool show_identity_value(
SELECTOR(algebra::TropicalSemiring<TropicalKind>),
47 T zero_value(
SELECTOR(algebra::TropicalSemiring<algebra::TropicalMax>),
SELECTOR(T))
49 return misc::limits<T>::min();
54 float zero_value(
SELECTOR(algebra::TropicalSemiring<algebra::TropicalMax>),
SELECTOR(
float))
56 return -misc::limits<float>::infinity();
61 double zero_value(
SELECTOR(algebra::TropicalSemiring<algebra::TropicalMax>),
SELECTOR(
double))
63 return -misc::limits<double>::infinity();
67 T zero_value(
SELECTOR(algebra::TropicalSemiring<algebra::TropicalMin>),
SELECTOR(T))
69 return misc::limits<T>::max();
74 float zero_value(
SELECTOR(algebra::TropicalSemiring<algebra::TropicalMin>),
SELECTOR(
float))
76 return misc::limits<float>::infinity();
81 double zero_value(
SELECTOR(algebra::TropicalSemiring<algebra::TropicalMin>),
SELECTOR(
double))
83 return misc::limits<double>::infinity();
89 template<
class TropicalKind,
typename T>
90 bool op_contains(
const algebra::TropicalSemiring<TropicalKind>&, T c)
98 template<
class TropicalKind,
typename T,
typename U>
99 void op_in_mul(
const algebra::TropicalSemiring<TropicalKind>&,
102 if ((dst == zero_value(
SELECT(algebra::TropicalSemiring<TropicalKind>),
104 (arg == zero_value(
SELECT(algebra::TropicalSemiring<TropicalKind>),
106 dst = zero_value(
SELECT(algebra::TropicalSemiring<TropicalKind>),
SELECT(T));
111 template<
class TropicalKind,
typename T,
typename U>
112 T op_mul(
const algebra::TropicalSemiring<TropicalKind>&, T a, U b)
114 if ((a == zero_value(
SELECT(algebra::TropicalSemiring<TropicalKind>),
116 (b == zero_value(
SELECT(algebra::TropicalSemiring<TropicalKind>),
118 return zero_value(
SELECT(algebra::TropicalSemiring<TropicalKind>),
SELECT(T));
125 template<
typename T,
typename U>
126 void op_in_add(
const algebra::TropicalSemiring<algebra::TropicalMax>&,
129 dst = std::max(dst, arg);
132 template<
typename T,
typename U>
133 void op_in_add(
const algebra::TropicalSemiring<algebra::TropicalMin>&,
136 dst = std::min(dst, arg);
139 template<
typename T,
typename U>
140 T op_add(
const algebra::TropicalSemiring<algebra::TropicalMax>&, T a, U b)
142 return std::max(a, b);
145 template<
typename T,
typename U>
146 T op_add(
const algebra::TropicalSemiring<algebra::TropicalMin>&, T a, U b)
148 return std::min(a, b);
154 template <
typename T>
156 op_starable(
const algebra::TropicalSemiring<algebra::TropicalMin>&, T b)
165 op_in_star(
const algebra::TropicalSemiring<algebra::TropicalMin>&, T& b)
172 assertion(!
"star not defined.");
178 op_starable(
const algebra::TropicalSemiring<algebra::TropicalMin>&,
bool)
185 op_in_star(
const algebra::TropicalSemiring<algebra::TropicalMin>&,
bool& b)
191 template <
typename T>
193 op_starable(
const algebra::TropicalSemiring<algebra::TropicalMax>&, T b)
202 op_in_star(
const algebra::TropicalSemiring<algebra::TropicalMax>&, T& b)
209 assertion(!
"star not defined.");
212 template <
class TropicalKind,
class T>
213 Element<algebra::TropicalSemiring<TropicalKind>, T>
214 op_choose(
const algebra::TropicalSemiring<TropicalKind>&
set,
SELECTOR(T))
216 return Element<algebra::TropicalSemiring<TropicalKind>, T>
217 (
set, misc::random::generate<T>());
220 template <
class TropicalKind,
typename T>
228 template <
class TropicalKind,
class T>
229 Element<algebra::TropicalSemiring<TropicalKind>, T>
235 r = op_choose(
set,
SELECT(T));
236 while (!op_starable(
set, r));
240 template <
class TropicalKind,
class T>
241 Element<algebra::TropicalSemiring<TropicalKind>, T>
247 r = op_choose(
set,
SELECT(T));
248 while (!op_starable(
set, r));
255 template<
typename St,
typename T>
256 St&
op_rout(
const algebra::TropicalSemiring<algebra::TropicalMax>&, St& st,
const T& v)
258 if (v == zero_value(
SELECT(algebra::TropicalSemiring<algebra::TropicalMax>),
SELECT(T)))
265 template<
typename St,
typename T>
266 St&
op_rout(
const algebra::TropicalSemiring<algebra::TropicalMin>&, St& st,
const T& v)
268 if (v == zero_value(
SELECT(algebra::TropicalSemiring<algebra::TropicalMin>),
SELECT(T)))
279 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SEMIRING_TROPICAL_SEMIRING_HXX