当前位置: 首页>>代码示例>>C++>>正文


C++ DFA::isReachable方法代码示例

本文整理汇总了C++中DFA::isReachable方法的典型用法代码示例。如果您正苦于以下问题:C++ DFA::isReachable方法的具体用法?C++ DFA::isReachable怎么用?C++ DFA::isReachable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DFA的用法示例。


在下文中一共展示了DFA::isReachable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: minimize

size_t minimize(const DFA& dfa, const vector<size_t>& terminalStates)
{ 
  for (int stateA_ = dfa.statesCount() - 1; stateA_ >= 0; --stateA_)
  {
    size_t stateA = stateA_;
    if (!dfa.isReachable(stateA))
    {
      continue;
    }
    for (int stateB_ = 0; stateB_ <= stateA_; ++stateB_)
    {
      size_t stateB = stateB_;
      if (!dfa.isReachable(stateB))
      {
        continue;
      }

      if (stateA < stateB)
      {
        std::swap(stateA, stateB);
      }

      for (size_t index = 0; index < dfa.alphaberSize(); ++index)
      {
        char symbol = 'a' + index;
        size_t newStateA = dfa.adjcencyState(symbol, stateA);
        size_t newStateB = dfa.adjcencyState(symbol, stateB);

        if (newStateA < newStateB)
        {
          std::swap(newStateA, newStateB);
        }

        pairGraph[newStateA][newStateB].push_back(make_pair(stateA, stateB));
      }
    }
  }
  return countNonEquivalentStates(dfa, terminalStates);
}
开发者ID:yarchi,项目名称:My-Projects,代码行数:39,代码来源:main.cpp

示例2: countNonEquivalentStates

size_t countNonEquivalentStates(const DFA& dfa, const vector<size_t>& terminalStates)
{
  queue<pair<size_t, size_t> > bfsQueue;
  
  for (size_t index = 0; index < terminalStates.size(); ++index)
  {
    int terminalState = terminalStates[index];

    if (!dfa.isReachable(terminalState))
    {
      continue;
    }

    for (int state = 0; state < dfa.statesCount(); ++state)
    {
      if (!dfa.isReachable(state) || dfa.isTerminal(state))
      {
        continue;
      }
      if (terminalState < state)
      {
        bfsQueue.push(make_pair(state, terminalState));
        used[state][terminalState] = true;
      }
      else
      {
        bfsQueue.push(make_pair(terminalState, state));
        used[terminalState][state] = true;
      }      
    }
  }

  while (!bfsQueue.empty())
  {
    pair<size_t, size_t> begin = bfsQueue.front();
    bfsQueue.pop();

    size_t stateA = begin.first;
    size_t stateB = begin.second;

    for (size_t index = 0; index < pairGraph[stateA][stateB].size(); ++index)
    {
      size_t newStateA = pairGraph[stateA][stateB][index].first;
      size_t newStateB = pairGraph[stateA][stateB][index].second;

      if (!used[newStateA][newStateB])
      {
        bfsQueue.push(make_pair(newStateA, newStateB));
        used[newStateA][newStateB] = true;
      }
    }
  }

  Sets sets(dfa.statesCount());
  for (int stateA = dfa.statesCount() - 1; stateA >= 0; --stateA)
  {
    for (int stateB = 0; stateB < stateA; ++stateB)
    {
      if (!used[stateA][stateB] && dfa.isReachable(stateA) && dfa.isReachable(stateB))
      {
        sets.merge(stateA, stateB);
      }
    }
  }
  return sets.count();
}
开发者ID:yarchi,项目名称:My-Projects,代码行数:66,代码来源:main.cpp


注:本文中的DFA::isReachable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。