File size: 1,843 Bytes
fd49381
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * Hypothesis.cpp
 *
 *  Created on: 24 Oct 2015
 *      Author: hieu
 */

#include <boost/foreach.hpp>
#include <stdlib.h>
#include <deque>
#include "HypothesisBase.h"
#include "System.h"
#include "Scores.h"
#include "ManagerBase.h"
#include "MemPool.h"
#include "FF/StatefulFeatureFunction.h"

using namespace std;

namespace Moses2
{

//size_t g_numHypos = 0;

HypothesisBase::HypothesisBase(MemPool &pool, const System &system)
{
  m_scores = new (pool.Allocate<Scores>()) Scores(system, pool,
      system.featureFunctions.GetNumScores());

  // FF states
  const std::vector<const StatefulFeatureFunction*> &sfffs =
    system.featureFunctions.GetStatefulFeatureFunctions();
  size_t numStatefulFFs = sfffs.size();
  m_ffStates = (FFState **) pool.Allocate(sizeof(FFState*) * numStatefulFFs);

  BOOST_FOREACH(const StatefulFeatureFunction *sfff, sfffs) {
    size_t statefulInd = sfff->GetStatefulInd();
    FFState *state = sfff->BlankState(pool, system);
    m_ffStates[statefulInd] = state;
  }
}

size_t HypothesisBase::hash() const
{
  return hash(0);
}

size_t HypothesisBase::hash(size_t seed) const
{
  size_t numStatefulFFs =
    GetManager().system.featureFunctions.GetStatefulFeatureFunctions().size();

  // states
  for (size_t i = 0; i < numStatefulFFs; ++i) {
    const FFState *state = m_ffStates[i];
    size_t hash = state->hash();
    boost::hash_combine(seed, hash);
  }
  return seed;

}

bool HypothesisBase::operator==(const HypothesisBase &other) const
{
  size_t numStatefulFFs =
    GetManager().system.featureFunctions.GetStatefulFeatureFunctions().size();

  // states
  for (size_t i = 0; i < numStatefulFFs; ++i) {
    const FFState &thisState = *m_ffStates[i];
    const FFState &otherState = *other.m_ffStates[i];
    if (thisState != otherState) {
      return false;
    }
  }
  return true;

}

}