File size: 1,282 Bytes
158b61b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
#pragma once
#include <queue>
#include <vector>
#include <utility>
#include <boost/unordered_set.hpp>
#include "SHyperedge.h"
#include "SHyperedgeBundle.h"
namespace Moses
{
namespace Syntax
{
// A cube -- in the cube pruning sense (see Chiang (2007)) -- that lazily
// produces SHyperedge objects from a SHyperedgeBundle in approximately
// best-first order.
class Cube
{
public:
Cube(const SHyperedgeBundle &);
~Cube();
SHyperedge *Pop();
SHyperedge *Top() const {
return m_queue.top().first;
}
bool IsEmpty() const {
return m_queue.empty();
}
private:
typedef boost::unordered_set<std::vector<int> > CoordinateSet;
typedef std::pair<SHyperedge *, const std::vector<int> *> QueueItem;
class QueueItemOrderer
{
public:
bool operator()(const QueueItem &p, const QueueItem &q) const {
return p.first->label.futureScore < q.first->label.futureScore;
}
};
typedef std::priority_queue<QueueItem, std::vector<QueueItem>,
QueueItemOrderer> Queue;
SHyperedge *CreateHyperedge(const std::vector<int> &);
void CreateNeighbour(const std::vector<int> &);
void CreateNeighbours(const std::vector<int> &);
const SHyperedgeBundle &m_bundle;
CoordinateSet m_visited;
Queue m_queue;
};
} // Syntax
} // Moses
|