public List < PossibleState > bfs ( int min ) throws ModelException { List < PossibleState > bootStrap = new LinkedList <> ( ) ; TransitionTarget initial = model . getInitialTarget ( ) ; PossibleState initialState = new PossibleState ( initial , fillInitialVariables ( ) ) ; bootStrap . add ( initialState ) ; while ( bootStrap . size ( ) < min ) { PossibleState state = bootStrap . remove ( 0 ) ; TransitionTarget nextState = state . nextState ; if ( nextState . getId ( ) . equalsIgnoreCase ( "end" ) ) { throw new ModelException ( "Could not achieve required bootstrap without reaching end state" ) ; } //run every action in series List < Map < String , String > > product = new LinkedList <> ( ) ; product . add ( new HashMap <> ( state . variables ) ) ; OnEntry entry = nextState . getOnEntry ( ) ; List < Action > actions = entry . getActions ( ) ; for ( Action action : actions ) { for ( CustomTagExtension tagExtension : tagExtensionList ) { if ( tagExtension . getTagActionClass ( ) . isInstance ( action ) ) { product = tagExtension . pipelinePossibleStates ( action , product ) ; } } } //go through every transition and see which of the products are valid, adding them to the list List < Transition > transitions = nextState . getTransitionsList ( ) ; for ( Transition transition : transitions ) { String condition = transition . getCond ( ) ; TransitionTarget target = ( ( List < TransitionTarget > ) transition . getTargets ( ) ) . get ( 0 ) ; for ( Map < String , String > p : product ) { Boolean pass ; if ( condition == null ) { pass = true ; } else { //scrub the context clean so we may use it to evaluate transition conditional Context context = this . getRootContext ( ) ; context . reset ( ) ; //set up new context for ( Map . Entry < String , String > e : p . entrySet ( ) ) { context . set ( e . getKey ( ) , e . getValue ( ) ) ; } //evaluate condition try { pass = ( Boolean ) this . getEvaluator ( ) . eval ( context , condition ) ; } catch ( SCXMLExpressionException ex ) { pass = false ; } } //transition condition satisfied, add to bootstrap list if ( pass ) { PossibleState result = new PossibleState ( target , p ) ; bootStrap . add ( result ) ; } } } } return bootStrap ; }
Performs a partial BFS on model until the search frontier reaches the desired bootstrap size