next up previous
Next: TSP's delta_cost Up: Example: Implementing TSP Previous: Example: Implementing TSP

TSP's Cost

The objective cost of TSP is defined as:

$\displaystyle d(\pi_{N-1}, \pi_0) + \sum_{i=0}^{N-2} d(\pi_i, \pi_{i+1})
$

In DISCROPT, this is written as:

double ObjectiveFunction::cost(CircularPermutation & sol)
{
  int current, next, size = sol.get_permutation_size();
  double weight=0;

  current = sol.first_index();
  for(int i=0; i<size; i++){
    next = sol.next_index(current);
    weight += search_space->edge_weight(sol[current], sol[next]);
    current = next;
  }
  return weight;
}

A few observations:

It must be reminded that DISCROPT minimizes, i.e. if $ s_1$ is subjectively better than $ s_2$, then cost($ s_1$) must be lower than cost($ s_2$).


next up previous
Next: TSP's delta_cost Up: Example: Implementing TSP Previous: Example: Implementing TSP
Vinhthuy Phan 2003-05-15