From 730a6c0bb666a394027ba7863e94699d96005afe Mon Sep 17 00:00:00 2001 From: graehl Date: Sat, 21 Aug 2010 02:50:10 +0000 Subject: semiring git-svn-id: https://ws10smt.googlecode.com/svn/trunk@609 ec762483-ff6d-05da-a07a-a48fb63a330f --- utils/logval.h | 5 +++-- utils/max_plus.h | 40 +++++++++++++++++----------------------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/utils/logval.h b/utils/logval.h index 868146de..833da7b8 100644 --- a/utils/logval.h +++ b/utils/logval.h @@ -110,10 +110,10 @@ class LogVal { //remember, s_ means negative. inline bool lt(Self const& o) const { - return s_ ? (!o.s_ || o.v_ o.s_; } inline bool gt(Self const& o) const { - return s_ ? (o.s_ && v_ struct semiring_traits > : default_semiring_traits > { static const bool has_logplus=true; static const bool has_besteq=true; + static const bool has_order=true; static const bool has_subtract=true; static const bool has_negative=true; }; diff --git a/utils/max_plus.h b/utils/max_plus.h index 5136b881..5ca26522 100755 --- a/utils/max_plus.h +++ b/utils/max_plus.h @@ -1,7 +1,6 @@ #ifndef MAX_PLUS_H_ #define MAX_PLUS_H_ -#include // max-plus algebra. ordering a > b really means that (i.e. default a > around // x+y := max{x,y} // x*y := x+y @@ -44,11 +43,6 @@ class MaxPlus { void logeq(const T& v) { v_ = v; } bool signbit() const { return false; } - std::size_t hash_impl() const { - using namespace boost; - return hash_value(v_); - } - Self& logpluseq(const Self& a) { if (a.is_0()) return *this; if (a.s_ == s_) { @@ -116,15 +110,15 @@ class MaxPlus { } // copy elision - as opposed to explicit copy of Self const& o1, we should be able to construct Logval r=a+(b+c) as a single result in place in r. todo: return std::move(o1) - C++0x - friend inline operator+(Self a,Self const& b) { + friend inline Self operator+(Self a,Self const& b) { a+=b; return a; } - friend inline operator*(Self a,Self const& b) { + friend inline Self operator*(Self a,Self const& b) { a*=b; return a; } - friend inline operator/(Self a,Self const& b) { + friend inline Self operator/(Self a,Self const& b) { a/=b; return a; } @@ -148,6 +142,15 @@ class MaxPlus { friend inline bool operator!=(Self const& lhs, Self const&rhs) { return lhs.v_ != rhs.v_; } + + std::size_t hash() const { + using namespace boost; + return hash_value(v_); + } + friend inline std::size_t hash_value(Self const& x) { + return x.hash(); + } + /* operator T() const { return std::exp(v_); @@ -170,6 +173,11 @@ struct semiring_traits > : default_semiring_traits > { template #if 0 +template +bool operator=(const MaxPlus& lhs, const MaxPlus& rhs) { + return (lhs.v_ <= rhs.v_); +} + template bool operator<=(const MaxPlus& lhs, const MaxPlus& rhs) { return (lhs.v_ <= rhs.v_); @@ -186,18 +194,4 @@ bool operator>=(const MaxPlus& lhs, const MaxPlus& rhs) { } #endif - -template -std::size_t hash_value(const MaxPlus& x) { return x.hash_impl(); } - -template -bool operator==(const MaxPlus& lhs, const MaxPlus& rhs) { - return (lhs.v_ == rhs.v_) && (lhs.s_ == rhs.s_); -} - -template -bool operator!=(const MaxPlus& lhs, const MaxPlus& rhs) { - return !(lhs == rhs); -} - #endif -- cgit v1.2.3