Well , I have a image in grey scale with his rows in a different order , so i thought in order the rows with a fitness function to know which order is the best i did the following heuristics:
for(int i=0;i<or.size()-1;i++) {
for(int j=0;j<imagen[0].length;j++) {
aux+=imagen[or.get(i)][j];
aux2+=imagen[or.get(i+1)][j];
}
fitness+=Math.abs(aux-aux2);
}
return fitness;
what i am doing is to sum the grey of each row and see the different with the next row. I think that the correct order is the rows with less variation , so the correct order should be the order with the smallest fitness. But it doesn't work , any idea about how to change the heuristics to know the best order?
Adding some information to the problem : The image is given as a matrix with the pixel information , but the rows are in an incorrect order , the columns are fine.
I resolved with calculating the distance between each pixel and his neighbors , that means : distance = sum ( abs(current-corner1)+abs(current-corner2)+abs(current-top)... etc...