Local search heuristics such as simulated annealing and hill
climb move from one solution to a neighboring solution to find the
best one. Instead of recomputing the cost, we can use delta_cost to save a factor of O computation.
Delta_costs takes a solution and a mutation and returns the cost of the change a solution to the neighboring solution obtained by mutating the given solution. Different solution representations have different definitions of mutation (implementation details are in operator.cpp):
Therefore, a neighbor of has the same permutation as
except at
two indices.
The difference is that a circular_permutation is equivalent (i.e. same objective cost) to all of its cyclic orders; the search space is narrower.
Therefore, a neighbor of has the same subset as
except one
element whose position is flipped.
Therefore, A neighbor of , has the same partition as
except an
element is moved to another (possibly new) part.
Relevant files to look at are: combinatorial_solution.h, (circular_)permutation.h, subset.h, partition.h, operator.cpp, basic_types.h.
For TSP, any two neighboring circular permutations differ by an
exchange of two indices. In other words, if and
are
neighbors, then they are exactly the same except at two indices, say
and
, where
and
. Suppose
, then we can define delta_cost
as:
![]() |
|||
![]() |
double ObjectiveFunction::delta_cost(CircularPermutation & sol, const mutation_element &mut_el) { int i = mut_el.first; int j = mut_el.second; int first = sol[i]; int before_first = sol[sol.previous_index(i)]; int after_first = sol[sol.next_index(i)]; int second = sol[i]; int after_second = sol[sol.next_index(j)]; int before_second = sol[sol.previous_index(j)]; double d = 0; if((first != before_second) && (second != before_first)){ d -= search_space->edge_weight(before_first, first); d -= search_space->edge_weight(first, after_first); d -= search_space->edge_weight(before_second, second); d -= search_space->edge_weight(second, after_second); d += search_space->edge_weight(before_first, second); d += search_space->edge_weight(second, after_first); d += search_space->edge_weight(before_second, first); d += search_space->edge_weight(first, after_second); } \\ other cases are omitted... }
Delta_cost must be defined so that