From a71432e613d2d9bf455b200edfe5890dc8e6d112 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Wed, 15 Nov 2017 21:32:06 +0100 Subject: [PATCH] notes in experimental random automaton factory --- .../src/automaton/RandomAutomatonFactory2.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/alib2algo_experimental/src/automaton/RandomAutomatonFactory2.h b/alib2algo_experimental/src/automaton/RandomAutomatonFactory2.h index 6eb06cf09c..766b7177ae 100644 --- a/alib2algo_experimental/src/automaton/RandomAutomatonFactory2.h +++ b/alib2algo_experimental/src/automaton/RandomAutomatonFactory2.h @@ -72,12 +72,15 @@ void RandomAutomatonFactory2::addTransition ( automaton::DFA < SymbolType, unsig template < class SymbolType > automaton::DFA < SymbolType, unsigned > RandomAutomatonFactory2::NonminimalDFA( size_t statesMinimal, size_t statesDuplicates, size_t statesUnreachable, size_t statesUseless, const ext::deque < SymbolType > & alphabet, double density ) { + // TODO make the same transition function on one of final states and one of the nonfinal ones. + // unreachable states accesible from each other atleast a bit if( alphabet.size( ) <= 0 ) throw exception::CommonException( "Alphabet size must be greater than 0." ); ext::deque < bool > VStates; ext::deque < bool > FStates; ext::deque < bool > DStates; + // to represent states that will merge ext::deque < ext::vector < unsigned > > duplicates; size_t visited; @@ -158,6 +161,7 @@ automaton::DFA < SymbolType, unsigned > RandomAutomatonFactory2::NonminimalDFA( depleted ++; } + // ---- make 0 state and leaf states connected by path unsigned last = 0; for ( unsigned i = 0; i < statesMinimal; ++ i ) { if ( automaton.getTransitionsFromState ( i ).size ( ) == 0 ) { @@ -167,6 +171,7 @@ automaton::DFA < SymbolType, unsigned > RandomAutomatonFactory2::NonminimalDFA( } } + // ---- make 1/3 to 2/3 of base states final for ( unsigned i = 0; i < statesMinimal * 2 / 3; ++ i ) { if ( i > statesMinimal / 3 && ext::random_devices::semirandom() % 2 == 0 ) continue; @@ -179,6 +184,7 @@ automaton::DFA < SymbolType, unsigned > RandomAutomatonFactory2::NonminimalDFA( automaton.addFinalState ( s ); } + // ---- make 1/3 to 2/3 of unreachable states final for ( unsigned i = 0; i < statesUnreachable * 2 / 3; ++ i ) { if ( i > statesUnreachable / 3 && ext::random_devices::semirandom() % 2 == 0 ) continue; @@ -196,6 +202,7 @@ automaton::DFA < SymbolType, unsigned > RandomAutomatonFactory2::NonminimalDFA( VStates [ statesMinimal + statesUseless + i ] = true; } + // ---- fill in the rest of transition function randomly double mnn100 = 100.0 / alphabet.size( ) / ( statesMinimal + statesUseless + statesUnreachable + statesDuplicates ); while( automaton.getTransitions ( ).size( ) * mnn100 < density ) { size_t a = randomSourceState ( statesMinimal + statesUseless + statesUnreachable, visited, depleted, VStates, DStates ); -- GitLab