The objective cost of TSP is defined as:
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:
In DISCROPT, we use the Graph Template Library (GTL) to provide the graph data structure for TSP. There is no need for GTL if the user provides his own data structure helped to define the objective function.
For permutation, subset, and partition representations, their elements can still be accessed or enumerated through theindexing mechanism: first_index(), last_index(), next_index(), [ ]. For example, the first element of a circular permutation s is s[s.first_index()].
It must be reminded that DISCROPT minimizes, i.e. if is
subjectively better than
, then cost(
) must be lower than
cost(
).