//private void evaluateFitness(CAState state) //{ // CAState temp0 = new CAState(); // CAState temp1 = new CAState(); // temp0.copyFrom(state); // for (int k=0; k<period; ++k) // { // rule_set.getTransition(temp0, temp1); // temp0.copyFrom(temp1); // } // float oscillatorness = 1.0f - temp0.getDifference(state); // //float density = (float)(population[j].numberOfLiveCells()) / (CAState.Width * CAState.Height); // int nas = state.numberOfLiveCells(); // int min_nas = 20; // float density = (nas > min_nas) ? 1.0f : nas / min_nas; // float t = 0.75f; // state.fitness = t * oscillatorness + (1.0f - t) * density; //} // no state should look more like the first than the end state private void evaluateFitness(CAState state) { float oscillatorness = 0.0f; CAState temp0 = new CAState(state); CAState temp1 = new CAState(state); float[] f = new float[period]; for (int k = 0; k < period; ++k) { rule_set.getTransition(temp0, temp1); temp0.copyFrom(temp1); f[k] = fitness_weights[k] * (1.0f - temp0.getRelativeDifference(state)); oscillatorness += f[k]; } float final_difference = temp0.getRelativeDifference(state); if (final_difference == 0) { state.fitness = 1.0f; return; } //oscillatorness = 1.0f - final_difference; //float oscillatorness = Math.Max(0, 1.0f - final_difference - 20*(final_difference - min_difference)); //if (final_difference == min_difference) //{ // oscillatorness = 1.0f - final_difference + (final_difference - min_difference); //} //else //{ // oscillatorness = Math.Max(1.0f - 10.0f*min_difference, 0); //} //float density = (float)(population[j].numberOfLiveCells()) / (CAState.Width * CAState.Height); int nas = state.numberOfLiveCells(); int min_nas = 20; float density = (nas > min_nas) ? 1.0f : nas / min_nas; float t = 0.8f; state.fitness = t * oscillatorness + (1.0f - t) * density; }
public static void printOscillator(CAState c, CARuleSet rule_set) { CAState temp0 = new CAState(c); CAState temp1 = new CAState(c); while (true) { Console.WriteLine(temp0.ToString()); Console.WriteLine(); rule_set.getTransition(temp0, temp1); if (temp1.getRelativeDifference(c) == 0) { break; } temp0.copyFrom(temp1); } }
public static void saveImages(CAState c, CARuleSet rule_set, String path) { CAState temp0 = new CAState(c); CAState temp1 = new CAState(c); int i = 0; while (true) { Bitmap image = temp0.toImage(c.Width * 100, c.Height * 100); image.Save(path + "/" + i + ".bmp"); rule_set.getTransition(temp0, temp1); if (temp1.getRelativeDifference(c) == 0) { break; } temp0.copyFrom(temp1); ++i; } }