1. A method for optimizing state assignments for a finite state machine, the method comprising: generating a random initial state assignment for each of a plurality of states of the finite state machine; determining, using processing circuitry, an initial cost associated with the random initial state assignments; identifying, using the processing circuitry, a code swap to explore as a function of a code swap probability; calculating a cost for the code swap when one or more criteria is satisfied; updating, using the processing circuitry, the code swap probability as a function of the cost of the code swap and a best cost; performing the code swap, when the cost of the swap is smaller than the best cost and/or a current cost, to optimize the state assignments; and outputting optimized state assignments.