Skip to content
Snippets Groups Projects
Commit a71432e6 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

notes in experimental random automaton factory

parent 8534e27a
No related branches found
No related tags found
No related merge requests found
......@@ -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 );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment