Here you can find the source of pathToAdjacencyList(final int[] path, final int[] adjacencyList)
Parameter | Description |
---|---|
path | the source: an int[] holding a permutation in representing a solution in <a href="#pathRepresentation"> <em>path representation</em></a> |
adjacencyList | the destination, an int[] to receive a solution in <a href="#adjacencyRepresentation"> <em>adjacency representation</em></a> |
public static final void pathToAdjacencyList(final int[] path, final int[] adjacencyList)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w ww. ja v a2 s .c om*/ * Convert a solution from <a href="#pathRepresentation"> * <em>path representation</em></a> to <a * href="#adjacencyRepresentation"> <em>adjacency representation</em> * </a>. An adjacency list is an integer array where the element at index * {@code (i-1)} stands for the city {@code i} and holds the index of the * city which should appear after that element. A path, too, is a * permutation represented as integer array. Here, the element at index * {@code i} will come at position {@code i} in the tour. * * @param path * the source: an {@code int[]} holding a permutation in * representing a solution in <a href="#pathRepresentation"> * <em>path representation</em></a> * @param adjacencyList * the destination, an {@code int[]} to receive a solution in <a * href="#adjacencyRepresentation"> * <em>adjacency representation</em></a> * @see #adjacencyListToPath(int[], int[]) */ public static final void pathToAdjacencyList(final int[] path, final int[] adjacencyList) { int last; last = path[path.length - 1]; for (final int p : path) { adjacencyList[last - 1] = p; last = p; } } }