From ea0ad5a622760ad654fb9c8fea959c24fc6d1911 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Pecka?= <peckato1@fit.cvut.cz>
Date: Thu, 1 May 2014 11:09:53 +0200
Subject: [PATCH] arand: one automaton, not automata :)

---
 arand/src/RandomAutomatonFactory.cpp | 46 ++++++++++++++--------------
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/arand/src/RandomAutomatonFactory.cpp b/arand/src/RandomAutomatonFactory.cpp
index 5f6d2d7019..c599f9adb4 100644
--- a/arand/src/RandomAutomatonFactory.cpp
+++ b/arand/src/RandomAutomatonFactory.cpp
@@ -43,7 +43,7 @@ FSM RandomAutomatonFactory::LeslieConnectedNFA( size_t n, const deque<Symbol> &
 
     srand( time( NULL ) );
 
-    FSM automata;
+    FSM automaton;
 
     deque<bool> VStates;
     deque<State> Q;
@@ -51,22 +51,22 @@ FSM RandomAutomatonFactory::LeslieConnectedNFA( size_t n, const deque<Symbol> &
 
 
     for( const auto & s : alphabet )
-        automata.addInputSymbol( s );
+        automaton.addInputSymbol( s );
 
     for( size_t i = 0; i < n; i ++ )
     {
         VStates.push_back( false );
         Q.push_back( State( to_string( i ) ) );
-        automata.addState( Q[ i ] );
+        automaton.addState( Q[ i ] );
     }
 
     if( n == 0 )
     {
-        return automata;
+        return automaton;
     }
     else if( n == 1 )
     {
-        automata.addTransition( Q[ 0 ], alphabet[ rand( ) % alphabet.size( ) ], Q[ 0 ] );
+        automaton.addTransition( Q[ 0 ], alphabet[ rand( ) % alphabet.size( ) ], Q[ 0 ] );
 
         unvisited = 0;
         VStates[ 0 ] = true;
@@ -74,14 +74,14 @@ FSM RandomAutomatonFactory::LeslieConnectedNFA( size_t n, const deque<Symbol> &
     else
     {
         int x = ( rand( ) % ( n - 1 ) ) + 1;
-        automata.addTransition( Q[ 0 ], alphabet[ rand( ) % alphabet.size( ) ], Q[ x ] );
+        automaton.addTransition( Q[ 0 ], alphabet[ rand( ) % alphabet.size( ) ], Q[ x ] );
         unvisited = n - 2;
 
         VStates[ 0 ] = true;
         VStates[ x ] = true;
     }
 
-    automata.addInitialState( Q [ 0 ] );
+    automaton.addInitialState( Q [ 0 ] );
 
     while( unvisited != 0 )
     {
@@ -113,7 +113,7 @@ FSM RandomAutomatonFactory::LeslieConnectedNFA( size_t n, const deque<Symbol> &
         }
 
         int c = rand() % alphabet.size( );
-        automata.addTransition( Q[ a ], alphabet[ c ], Q[ b ] );
+        automaton.addTransition( Q[ a ], alphabet[ c ], Q[ b ] );
 
 
         unvisited -= 1;
@@ -124,25 +124,25 @@ FSM RandomAutomatonFactory::LeslieConnectedNFA( size_t n, const deque<Symbol> &
 
     for( State const& q : Q )
     {
-        if( automata.getTransitionsFromState( q ).size( ) == 0 && rand( ) % 100 < 90 )
-            automata.addFinalState( q );
-        else if( automata.getTransitionsFromState( q ).size( ) > 0 && rand( ) % 100 < 10 )
-            automata.addFinalState( q );
+        if( automaton.getTransitionsFromState( q ).size( ) == 0 && rand( ) % 100 < 90 )
+            automaton.addFinalState( q );
+        else if( automaton.getTransitionsFromState( q ).size( ) > 0 && rand( ) % 100 < 10 )
+            automaton.addFinalState( q );
     }
 
-    if( automata.getFinalStates( ).size( ) == 0 )
+    if( automaton.getFinalStates( ).size( ) == 0 )
     {
         if( n == 1 )
         {
-            automata.addFinalState( * automata.getInitialStates( ).begin( ) );
+            automaton.addFinalState( * automaton.getInitialStates( ).begin( ) );
         }
         else
         {
             for( State const& q : Q )
             {
-                if( automata.getTransitionsFromState( q ).size( ) == 0 )
+                if( automaton.getTransitionsFromState( q ).size( ) == 0 )
                 {
-                    automata.addFinalState( q );
+                    automaton.addFinalState( q );
                     break;
                 }
             }
@@ -150,26 +150,26 @@ FSM RandomAutomatonFactory::LeslieConnectedNFA( size_t n, const deque<Symbol> &
     }
 
     double mnn100 = 100.0 / alphabet.size( ) / n / n;
-    while( automata.getTransitions( ).size( ) * mnn100 < density )
+    while( automaton.getTransitions( ).size( ) * mnn100 < density )
     {
         int y = rand( ) % n;
         int z = rand( ) % n;
         int a = rand( ) % alphabet.size();
 
         TransitionFSM t ( Q[ y ], alphabet [ a ], Q[ z ] );
-        if( ! isInSet( t, automata.getTransitions( ) ) )
-            automata.addTransition( t );
+        if( ! isInSet( t, automaton.getTransitions( ) ) )
+            automaton.addTransition( t );
     }
 
     map<Symbol, bool> alphabetUsage;
-    for( const auto & a : automata.getInputAlphabet( ) )
+    for( const auto & a : automaton.getInputAlphabet( ) )
         alphabetUsage[ a ] = false;
-    for( const auto & t : automata.getTransitions( ) )
+    for( const auto & t : automaton.getTransitions( ) )
         alphabetUsage[ t.getInput( ) ] = true;
 
     for( const auto & kv : alphabetUsage )
         if( kv.second == false )
-            automata.removeInputSymbol( kv.first );
+            automaton.removeInputSymbol( kv.first );
 
-    return automata;
+    return automaton;
 }
-- 
GitLab