Java Path Convert To pathToAdjacencyList(final int[] path, final int[] adjacencyList)

Here you can find the source of pathToAdjacencyList(final int[] path, final int[] adjacencyList)

Description

Convert a solution from path representation to adjacency representation .

License

Open Source License

Parameter

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>

Declaration

public static final void pathToAdjacencyList(final int[] path,
        final int[] adjacencyList) 

Method Source Code

//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;
        }
    }
}

Related

  1. filePathToJavaBinaryName(final String filePath, final String separator)
  2. filePathToPackagePathOrNull(String path)
  3. filePathToUrl(String filePath)
  4. pathTo(String filename)
  5. pathTo(String ref)
  6. pathToClassName(String path)
  7. pathToClassName(String pathName)
  8. pathToEmbedded(String relationType)
  9. pathToFields(String beanPath)