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