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


C++ FSM::states方法代码示例

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


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

示例1: preProcess

  void EncodedFSM::preProcess( const FSM& fsm ) {
    std::cout << "[EncodedFSM]: Preproccessing FSM ..." << std::endl;

    size_t k = _secretKeyPtr->k();
    size_t lambda = _secretKeyPtr->lambda();

    auto states = fsm.states();

    std::map<size_t, PolyRingMatrixPtr> stateSecretKeys;
    // secret start key is already generated
    stateSecretKeys[0] = make_unique<PolyRingMatrix>( *_secretKeyPtr->start() );
    // create new random key for every state except start state
    std::cout << "[EncodedFSM]: Creating encoded state keys ..." << std::endl;
    for ( size_t stateID = 1; stateID < fsm.numStates(); ++stateID ) {
      // key should be Z^n -> 1 polynomial in ring setting
      auto stateKey = PolyRingMatrix{1, 1, lambda, k};
      stateKey.uniformInit();
      stateSecretKeys[stateID] = make_unique<PolyRingMatrix>( stateKey );
    }

    /**
     * Encode transitions using public matrices and  secret start and terminal
     * states.
     */
    auto G = GTrapdoor{k, lambda};
    auto transitions = fsm.transitions();
    std::cout << "[EncodedFSM]: Creating encoded transitions ..." << std::endl;
    for ( size_t stateID = 0; stateID < fsm.numStates(); ++stateID ) {
      auto transition = transitions[stateID];

      // retrieve state keys
      auto currentStateKey = make_unique<PolyRingMatrix>( *stateSecretKeys[stateID] );
      auto stateKeyFor0 = make_unique<PolyRingMatrix>( *stateSecretKeys[transition.nextStateFor0()]);
      auto stateKeyFor1 = make_unique<PolyRingMatrix>( *stateSecretKeys[transition.nextStateFor1()] );

      // sample error
      auto e0 = _secretKeyPtr->buildTernaryTempMatrix( k, 1 );
      auto e1 = _secretKeyPtr->buildTernaryTempMatrix( k, 1 );

      // encode transitions
      auto t0 = *_secretKeyPtr->A0() * *currentStateKey + e0 + G * *stateKeyFor0;
      auto t1 = *_secretKeyPtr->A1() * *currentStateKey + e1 + G * *stateKeyFor1;
      
      _transitions.push_back( make_unique<PolyRingMatrix>( t0 ) );
      _transitions.push_back( make_unique<PolyRingMatrix>( t1 ) );

      // generate error for terminal transition
      auto et = _secretKeyPtr->buildTernaryTempMatrix( k, 1 );

      // encode terminal transition
      if ( states[stateID].acceptState() ) {
        auto tt = *_secretKeyPtr->At() * *currentStateKey + et + G * 
            *_secretKeyPtr->accept();
        _acceptTransitions.push_back( make_unique<PolyRingMatrix>( tt ) );
      } else {
        auto tt = *_secretKeyPtr->At() * *currentStateKey + et + G *
            *_secretKeyPtr->reject();
        _rejectTransitions.push_back( make_unique<PolyRingMatrix>( tt ) );
      }
    }
    std::cout << "[EncodedFSM]: DONE preprocessing" << std::endl;
  }
开发者ID:clear731,项目名称:lattice,代码行数:62,代码来源:EncodedFSM.cpp


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