private Plan selectPlanAtRandom ( ) { Plan plan = null ; Set < Belief > vars = null ; int index = rand . nextInt ( size ( ) ) ; int idx = 0 ; boolean bindingsExist = false ; for ( Plan p : bindings . keySet ( ) ) { vars = bindings . get ( p ) ; bindingsExist = ( vars != null && ! vars . isEmpty ( ) ) ; idx += bindingsExist ? vars . size ( ) : 1 ; if ( idx > index ) { plan = p ; if ( bindingsExist ) { index = index - ( idx - vars . size ( ) ) ; setPlanVariables ( plan . getAgent ( ) , plan , vars , index ) ; } break ; } } return plan ; }
Selects a plan instance at random from the set of plan bindings .