summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorgraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-09-23 00:10:52 +0000
committergraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-09-23 00:10:52 +0000
commit3a802d691a34fe4a75af110fc8c4a771f18b7641 (patch)
tree1d1494a1a1c1a1def5b05893f0d4dac9ae904c13 /utils
parent6409c2c91b7fd3d3b42c6bb0d3376b83eb4d5611 (diff)
pausing earley best-first fsa work
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@656 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'utils')
-rwxr-xr-xutils/agenda.h17
-rw-r--r--utils/d_ary_heap.h16
2 files changed, 31 insertions, 2 deletions
diff --git a/utils/agenda.h b/utils/agenda.h
index 1dbcd7bb..d4f13696 100755
--- a/utils/agenda.h
+++ b/utils/agenda.h
@@ -107,14 +107,27 @@ struct Agenda : intern_pool<Item,KeyF,HashKey,EqKey,Pool> {
}
// no need to destroy the canon. item because we want to remember the best cost and reject more expensive ways of using it).
ItemC pop() {
- DBG_AGENDA(assert(!empty()));
ItemC r=q.top();
q.pop();
return r;
}
+ void pop_discard() {
+ q.pop();
+ }
+
+ ItemC top() {
+ DBG_AGENDA(assert(!empty()));
+ return q.top();
+ }
+
agenda_best_t best() const {
- return priomap[q.top()]; //TODO: cache/track the global best?
+ return q.best(); //TODO: cache/track the global best?
}
+
+ agenda_best_t second_best() const {
+ return q.second_best();
+ }
+
// add only if worse than queue current best, otherwise evaluate immediately (e.g. for early stopping w/ expensive to compute additional cost). return true if postponed (added)
bool postpone(ItemP i) {
if (better(priomap[i],best())) return false;
diff --git a/utils/d_ary_heap.h b/utils/d_ary_heap.h
index 3a071772..1270638a 100644
--- a/utils/d_ary_heap.h
+++ b/utils/d_ary_heap.h
@@ -283,6 +283,22 @@
return false;
}
+ distance_type best(distance_type null=0) const {
+ return empty() ? null : get(distance,data[0]);
+ }
+ distance_type second_best(distance_type null=0) const {
+ if (data.size()<2) return null;
+ int m=std::min(data.size(),Arity+1);
+// if (m>=Arity) m=Arity+1;
+ distance_type b=get(distance,data[1]);
+ for (int i=2;i<m;++i) {
+ distance_type d=get(distance,data[i]);
+ if (better(d,b))
+ b=d;
+ }
+ return b;
+ }
+
#include "warning_push.h"
#pragma GCC diagnostic ignored "-Wtype-limits"