diff options
Diffstat (limited to 'src/lattice.cc')
-rw-r--r-- | src/lattice.cc | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/lattice.cc b/src/lattice.cc index aa1df3db..56bc9551 100644 --- a/src/lattice.cc +++ b/src/lattice.cc @@ -5,6 +5,39 @@ using namespace std; +static const int kUNREACHABLE = 99999999; + +void Lattice::ComputeDistances() { + const int n = this->size() + 1; + dist_.resize(n, n, kUNREACHABLE); + for (int i = 0; i < this->size(); ++i) { + const vector<LatticeArc>& alts = (*this)[i]; + for (int j = 0; j < alts.size(); ++j) + dist_(i, i + alts[j].dist2next) = 1; + } + for (int k = 0; k < n; ++k) { + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + const int dp = dist_(i,k) + dist_(k,j); + if (dist_(i,j) > dp) + dist_(i,j) = dp; + } + } + } + + for (int i = 0; i < n; ++i) { + int latest = kUNREACHABLE; + for (int j = n-1; j >= 0; --j) { + const int c = dist_(i,j); + if (c < kUNREACHABLE) + latest = c; + else + dist_(i,j) = latest; + } + } + // cerr << dist_ << endl; +} + bool LatticeTools::LooksLikePLF(const string &line) { return (line.size() > 5) && (line.substr(0,4) == "((('"); } @@ -23,5 +56,6 @@ void LatticeTools::ConvertTextOrPLF(const string& text_or_plf, Lattice* pl) { HypergraphIO::PLFtoLattice(text_or_plf, pl); else ConvertTextToLattice(text_or_plf, pl); + pl->ComputeDistances(); } |