public Optimizer() {
}
public static short[] flipOptimize(NDVis view) {
DataVisualization dataVis = view.getActiveDataVisualization();
ColorEngine engine = dataVis.getLookup().lookup(ColorMapper.class).getEngine();
// TODO: why are you getting the number of parameters on X from the
// color engine instead of parameters?
int numParametersOnX = dataVis.getLookup().lookup(Parameters.class).getNumParametersOnX();
int[] rgb = engine.getPixels();
int[] rgbCopy = new int[rgb.length];
short[] currentOrder = engine.getCurrentOrder();
short[] bestOrder = PermutorCombinator.cloneShorts(engine.getCurrentOrder());
// I leave this as being a local reference to bases because the user may
// actually set a different value while this processing is happening
short[] bases = view.getDataInfoForVisualization(
dataVis).getBases();
ParametersUtils paramUtils = dataVis.getLookup().lookup(Parameters.class).getParametersUtils();
// score the current image
int score = Score0.score(paramUtils, currentOrder, numParametersOnX,
rgb, Integer.MAX_VALUE);
int bestScore = score;
short[] candidate = null;
boolean keepgoing = true;
// int j = 0;
while (keepgoing) {
if (bestScore == 0) {
return bestOrder;
}
// j += 1;
// System.out.println("Front of while and bestScore is " + bestScore
// + " and currentOrder is: ");
// PermuterCombinatorTest.printPermutation(currentOrder);
// immediately reset keep going, only keep going if there is
// some score out of the next series of flips that is better
// than the current best score
keepgoing = false;
// get every pair-wise swap of values in bestOrder - i.e. this will
// be bestOrder.length choose 2 short[]s returned in an ArrayList
ArrayList permutations = generateAllPairWiseFlips(bestOrder);
for (int k = 0, n = permutations.size(); k < n; k++) {
candidate = (short[]) permutations.get(k);
// PermuterCombinatorTest.printPermutation(candidate);
// reorder the pixels given the candidate ordering
engine.reorderPixelColors(rgb, rgbCopy, currentOrder,
candidate, bases);
// score the new rgb int[] (in terms of what it would look like
// if used to create an image)
score = Score0.score(paramUtils, candidate, numParametersOnX,
rgbCopy, bestScore);