//Finate State Machine Morpher (The Environmental Feedback, God) import java.util.*; public class FogelFSM { public FSM bestMachine; private boolean[] input; public int numOffspring; public FogelFSM(int numStates){ bestMachine = new FSM(numStates); } public void setInput(boolean[] input){ this.input = input; } // returns the percentage guessed correctly of the new best machine public float runGeneration(){ float bestPercent = 0; FSM child = null; for (int i = 0; i < numOffspring; i++){ child = bestMachine.makeChild(); int trues = 0; for (int state = 0; state < input.length-1; state++){ boolean answer = child.doStep(input[state]); if (answer == input[state+1]) trues++; } float thisPercent = (trues)/(float)(input.length-1); if (thisPercent > bestPercent) { bestPercent = thisPercent; bestMachine = child; } } return bestPercent; } public static void main(String[] args){ FogelFSM jerry = new FogelFSM(10); jerry.numOffspring = 100; boolean[] data = {true, true, true, false, true, true, true, true, false, true, true, true, true, false, true, true, true, true, false, true, true, true, true, false, true}; jerry.setInput(data); for (int i = 0; i<10000; i++){ float result = jerry.runGeneration(); if (result >= 1){ System.out.println(result); System.out.println(jerry.bestMachine); System.exit(0); } else { System.out.println(result); } } System.exit(0); } }