/* * Improves k to the maximum extent possible. */ Keyboard improver(Keyboard k) { printPercentages(&k); Keyboard tk, bestk; copy(&tk, &k); copy(&bestk, &k); int64_t bestEval = k.fitness; int64_t curEval = anneal(&tk, NULL, 0); if (curEval < bestEval) { copy(&bestk, &tk); bestEval = curEval; printPercentages(&tk); } return bestk; }
/* WARNING: Deprecated. Does not work with shifted characters. */ int bestSwap(Keyboard *k) { printPercentages(k); calcFitness(k); int64_t fitness = k->fitness; int64_t origFitness = fitness; int64_t bestFitness = fitness; int bestIndices[2]; Keyboard bestKeyboard = *k; int i, j; for (i = 0; i < trueksize; i++) { for (j = i+1; j < trueksize; j++) { if (!isLegalSwap(k, indices[i], indices[j])) continue; swap(k, indices[i], indices[j]); calcFitness(k); if (k->fitness < bestFitness) { bestFitness = k->fitness; bestKeyboard = *k; bestIndices[0] = indices[i]; bestIndices[1] = indices[j]; } /* Print out all swaps that are a certain percentage better. */ if ((origFitness - k->fitness) / ((double) origFitness) > 0.05) { printPercentages(k); } swap(k, indices[i], indices[j]); } } printf("swap: %c and %c\n", k->layout[bestIndices[0]], k->layout[bestIndices[1]]); printPercentages(&bestKeyboard); return 0; }
/* * Read in each layout from the file and print out detailed information. */ int compare(char *filename) { FILE *fp = fopen(filename, "r"); int ret = 1; while (ret != EOF && ret >= 0) { Keyboard k; ret = layoutFromFile(fp, &k); if (ret >= 0) { printPercentages(&k); } } fclose(fp); printf("\n"); return 0; }
/* * Read in each layout from the file and print out detailed information. */ int compare(const char *const filename) { FILE *file = fopen(filename, "r"); CHECK_FILE_FOR_NULL(file, filename); int ret = 1; while (ret != EOF && ret >= 0) { Keyboard k; ret = layoutFromFile(file, &k); if (ret >= 0) { printPercentages(&k); } } fclose(file); printf("\n"); return 0; }