diff options
author | Eva Hasler <ehasler@saxnot.inf.ed.ac.uk> | 2012-06-01 04:49:42 +0400 |
---|---|---|
committer | Eva Hasler <ehasler@saxnot.inf.ed.ac.uk> | 2012-06-01 04:49:42 +0400 |
commit | 6a6a35c65eaeb42b3f1aa44237332dd6f1bc652c (patch) | |
tree | 8a02d798832fe36e9efb60f8a2e30d9368728a13 /mira/HypothesisQueue.cpp | |
parent | 62d10a2af3f9509bf7680b8549ff1ffd9774dd83 (diff) |
fix start weights in experiment.perl, add hypothesis queue for picking hope and fear translations, add variations to 1slack formulation
Diffstat (limited to 'mira/HypothesisQueue.cpp')
-rw-r--r-- | mira/HypothesisQueue.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/mira/HypothesisQueue.cpp b/mira/HypothesisQueue.cpp new file mode 100644 index 000000000..67a42dfdd --- /dev/null +++ b/mira/HypothesisQueue.cpp @@ -0,0 +1,57 @@ +/*********************************************************************** + Moses - statistical machine translation system + Copyright (C) 2006-2011 University of Edinburgh + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +***********************************************************************/ + +#include <iostream> +#include "HypothesisQueue.h" + +using namespace std; + +namespace Moses { + +HypothesisQueue::~HypothesisQueue() { + m_queue.clear(); +} + +void HypothesisQueue::Push(BleuIndexPair hypo) { + pair<set<BleuIndexPair>::iterator,bool> ret; + + if (m_capacity == 0 || m_queue.size() < m_capacity) { + ret = m_queue.insert(hypo); + } else if (hypo.first > (*(m_queue.rbegin())).first) { + // Remove the worst-scoring item from the queue and insert hypo (only erase item if new item was successfully added ) + ret = m_queue.insert(hypo); + if ((*(ret.first)).second == 1) { + HypoQueueType::iterator p = m_queue.end(); + --p; + m_queue.erase(p); + } + } else { + // The hypo is unusable: the queue is full and hypo has a worse (or + // equal) score than the worst-scoring item already held. + } +} + +BleuIndexPair HypothesisQueue::Pop() { + HypoQueueType::iterator p = m_queue.begin(); + BleuIndexPair top = *p; + m_queue.erase(p); + return top; +} + +} // namespace Moses |