void update_grid(Solution s)
{
// recalculate ranges for grid in the light of a new solution s
//static int change = 0;
int change = 0;
int a, b;
int square;
double[] offset = new double[10];//MAX_OBJ
double[] largest = new double[10];
double sse;
double product;
for (a = 0; a < objectives; a++)
{
offset[a] = LARGE;
largest[a] = -LARGE;
}
for (b = 0; b < objectives; b++)
{
for (a = 0; a < arclength; a++)
{
if (arc[a].obj[b] < offset[b])
offset[b] = arc[a].obj[b];
if (arc[a].obj[b] > largest[b])
largest[b] = arc[a].obj[b];
}
}
for (b = 0; b < objectives; b++)
{
if (s.obj[b] < offset[b])
offset[b] = s.obj[b];
if (s.obj[b] > largest[b])
largest[b] = s.obj[b];
}
sse = 0;
product = 1;
for (a = 0; a < objectives; a++)
{
sse += ((gl_offset[a] - offset[a]) * (gl_offset[a] - offset[a]));
sse += ((gl_largest[a] - largest[a]) * (gl_largest[a] - largest[a]));
product *= gl_range[a];
}
if (sse > (0.1 * product * product)) //if the summed squared error (difference) between old and new
//minima and maxima in each of the objectives
{ //is bigger than 10 percent of the square of the size of the space
change++; // then renormalise the space and recalculte grid locations
for (a = 0; a < objectives; a++)
{
gl_largest[a] = largest[a] + 0.2 * largest[a];
gl_offset[a] = offset[a] + 0.2 * offset[a];
gl_range[a] = gl_largest[a] - gl_offset[a];
}
//for (a = 0; a < Math.Pow(2, (objectives * depth)); a++)
for (a = 0; a < Math.Pow((objectives * depth),4); a++)
{
grid_pop[a] = 0;
}
for (a = 0; a < arclength; a++)
{
square = find_loc(arc[a].obj);
//(&arc[a])->grid_loc = square;
arc[a].grid_loc = square;
grid_pop[square]++;
}
}
square = find_loc(s.obj);
s.grid_loc = square;
//grid_pop[(int)Math.Pow(2, (objectives * depth))] = -5;
grid_pop[(int)Math.Pow((objectives * depth),4)] = -5;
grid_pop[square]++;
}