public Model getBestModel(int maxOutputStates) {
logger.info( "Will score candidates by " + outputScorer );
// Sort candidates by output scorer
Candidate resultsSorted[] = results.keySet().toArray(new Candidate[] {});
Arrays.sort(resultsSorted, (SearchStrategy)outputScorer);
int minNumStatesReached = Integer.MAX_VALUE;
for( int i=0; i<resultsSorted.length; i++ ) {
int numStates = resultsSorted[i].getNumStates();
if( (numStates>1) && (numStates < minNumStatesReached) ) {
minNumStatesReached = numStates;
}
}
int realisticMaxOutputStates = maxOutputStates;
if( minNumStatesReached > maxOutputStates ) {
logger.warn( "Could not find a model with " + maxOutputStates + " states or less" );
logger.warn( "Apart from the model with one state (which is never returned!), all the other models had " + minNumStatesReached + " states or more" );
realisticMaxOutputStates = minNumStatesReached;
}
// Try to find the best one
Candidate winner = null;
for( int i=0; i<resultsSorted.length; i++ ) {
int numStates = resultsSorted[i].getNumStates();
// The model with only 1 state is never returned
if( (numStates>1) && (numStates <= realisticMaxOutputStates ) ) {
winner = resultsSorted[i];