int Graph::GetTransitionCostGenericTimeBased(size_t* coordcurr, size_t* coordprev) { bool deletable = false; int mintime = -1; int maxtime = -1; int deletioncost = 0; int transitioncost = 0; for(size_t i=0; i<GetDimension(); ++i) { if(coordcurr[i] != coordprev[i]) { Token* aToken = m_TabVecHypRef[i][coordcurr[i]]; deletable = aToken->IsOptional(); if( (mintime == -1) || (aToken->GetStartTime() < mintime) ) mintime = aToken->GetStartTime(); if( (maxtime == -1) || (aToken->GetEndTime() > maxtime) ) maxtime = aToken->GetEndTime(); } } for(size_t i=0; i<GetDimension(); ++i) { if(coordcurr[i] != coordprev[i]) { Token* aToken = m_TabVecHypRef[i][coordcurr[i]]; transitioncost = maxtime - aToken->GetEndTime() + aToken->GetStartTime() - mintime; } else deletioncost += maxtime - mintime; } return( (GetCostInsertion(deletable)*deletioncost + GetCostTransition()*transitioncost)/m_TimeBasedSafeDivider ); }
bool Graph::ValidateTransitionInsertionDeletion(size_t* coordcurr, size_t* coordprev) { if(!m_bPruneOptimization && !m_bWordOptimization) return true; Token* pToken; size_t nrbchanged = NumberChanged(coordcurr, coordprev); if( (nrbchanged == 1) && m_bPruneOptimization )// Insertion or Deletion { size_t chgdim = 0; while( (chgdim<GetDimension()) && (coordcurr[chgdim] == coordprev[chgdim]) ) ++chgdim; pToken = m_TabVecHypRef[chgdim][coordcurr[chgdim]]; int currentchgbegin; int currentchgend; if(pToken) { currentchgbegin = pToken->GetStartTime(); if(currentchgbegin < 0) { currentchgbegin = pToken->GetParentSegment()->GetStartTime(); if(currentchgbegin < 0) return true; } else return true; currentchgend = pToken->GetEndTime(); if(currentchgend < 0) { currentchgend = pToken->GetParentSegment()->GetEndTime(); if(currentchgend < 0) return true; } else return true; } else return true; int currentstaybegin; int currentstayend; for(size_t i=0; i<GetDimension(); ++i) { if(i != chgdim) { pToken = m_TabVecHypRef[i][coordcurr[i]]; if(pToken) { currentstaybegin = pToken->GetStartTime(); if(currentstaybegin < 0) { currentstaybegin = pToken->GetParentSegment()->GetStartTime(); if(currentstaybegin < 0) return true; } currentstayend = pToken->GetEndTime(); if(currentstayend < 0) { currentstayend = pToken->GetParentSegment()->GetEndTime(); if(currentstayend < 0) return true; } } else return true; if(currentchgbegin < currentstaybegin) { int gap = 0; if(currentchgend < currentstaybegin) // Change before Stay { gap = currentstaybegin - currentchgend; } else if(currentstayend < currentchgbegin) // Stay before Change { gap = currentchgbegin - currentstayend; } if(gap > m_PruneOptimizationThreshold) return false; } } } return true; } else if( (nrbchanged == 2) && m_bWordOptimization )//Subsitution or Correct { size_t coord1 = 0; size_t coord2 = 0; bool bcoord1 = false; for(size_t i=0; i<GetDimension(); ++i) { if(coordcurr[i] != coordprev[i]) { if(!bcoord1) { bcoord1 = true; coord1 = i; } else coord2 = i; } } int start1 = m_TabVecHypRef[coord1][coordcurr[coord1]]->GetStartTime(); if(start1 < 0) start1 = m_TabVecHypRef[coord1][coordcurr[coord1]]->GetParentSegment()->GetStartTime(); int start2 = m_TabVecHypRef[coord2][coordcurr[coord2]]->GetStartTime(); if(start2 < 0) start2 = m_TabVecHypRef[coord2][coordcurr[coord2]]->GetParentSegment()->GetStartTime(); int end1 = m_TabVecHypRef[coord1][coordcurr[coord1]]->GetEndTime(); if(end1 < 0) end1 = m_TabVecHypRef[coord1][coordcurr[coord1]]->GetParentSegment()->GetEndTime(); int end2 = m_TabVecHypRef[coord2][coordcurr[coord2]]->GetEndTime(); if(end2 < 0) end2 = m_TabVecHypRef[coord2][coordcurr[coord2]]->GetParentSegment()->GetEndTime(); if( (start1 < 0) || (start2 < 0) || (end1 < 0) || (end2 < 0) ) return true; int gap; if(end1 < start2) // 1 before 2 { gap = start2 - end1; } else if(end2 < start1) // 2 before 1 { gap = start1 - end2; } else { gap = 0; } return(gap <= m_WordOptimizationThreshold); } return true; }