Hello,
I'm seeing some odd behavior in my program and I can't seem to find the reason.
The majority of time is spent on simple calculations that look up several numbers from a distance matrix and add or substract those numbers.
Now, as an attempt at lowlevel optimizations, I changed the calculation functions slightly: using the fact that (a  b + c) = (b + c + a) and that my Distance matrix is symmetric (d[a][b] == d[b][a]), I changed the sequence of the calculations in hopes of getting faster lookups. So, as example:
1 2 3

COST exampleCost(int I, int J) {
return d[i][j+1] + d[j][i+1] + d[i][i+1] + d[i][j];
}
 
might become:
1 2 3

COST exampleCost(int I, int J) {
return d[i][i+1] + d[i][j] + d[i][j+1] + d[i+1][j];
}
 
With the goal being that each lookup is closer together compared to the first version.
Effectivity aside, I'm seeing odd results: just changing around the order of the calculation (and reversing indeces) for some reason is changing the results. Due to the nature of the program, it's nearly impossible to debug and manually find the cause unless I have a very good idea what the possible causes are.
So, my question is: is there anything else than "you messed up one of the functions" that could cause this? How do I check for it?
(Alternatively: would this change ever have any significant effect?)
Extra info:
All COSTrelated variables are doubles.
The distance table is conceptually a NxN matrix (N = 5000 in this case and expected to get larger in future testing) and practically a std::vector<COST> of size N². Lookups are done through operator(i, j) that returns vector[i*N+j].
I'm certain (?) the Distance matrix is symmetrical: it's generated by calculating cost(i, j) for i <= j and copying from (j, i) in case i > j.
I'm compiling with /fp:precise, Win7 64bit, using MSV express 2010.