Class TSP.Integer

    • Constructor Detail

      • Integer

        public Integer​(int n,
                       double w)
        Constructs a random TSP instance with cities randomly distributed within a square region. The edge cost of a pair of cities is the Euclidean distance between them rounded to the nearest integer.
        Parameters:
        n - The number of cities.
        w - The width (and height) of a square region containing the cities.
        Throws:
        IllegalArgumentException - if n < 2.
        IllegalArgumentException - if w ≤ 0.0.
      • Integer

        public Integer​(int n,
                       double w,
                       TSPEdgeDistance distance)
        Constructs a random TSP instance with cities randomly distributed within a square region.
        Parameters:
        n - The number of cities.
        w - The width (and height) of a square region containing the cities.
        distance - The distance function to use for the edge costs.
        Throws:
        IllegalArgumentException - if n < 2.
        IllegalArgumentException - if w ≤ 0.0.
      • Integer

        public Integer​(int n,
                       double w,
                       long seed)
        Constructs a random TSP instance with cities randomly distributed within a square region. The edge cost of a pair of cities is the Euclidean distance between them rounded to the nearest integer.
        Parameters:
        n - The number of cities.
        w - The width (and height) of a square region containing the cities.
        seed - The seed for the random number generator to enable reproducing the same instance for experiment reproducibility.
        Throws:
        IllegalArgumentException - if n < 2.
        IllegalArgumentException - if w ≤ 0.0.
      • Integer

        public Integer​(int n,
                       double w,
                       TSPEdgeDistance distance,
                       long seed)
        Constructs a random TSP instance with cities randomly distributed within a square region.
        Parameters:
        n - The number of cities.
        w - The width (and height) of a square region containing the cities.
        distance - The distance function to use for the edge costs.
        seed - The seed for the random number generator to enable reproducing the same instance for experiment reproducibility.
        Throws:
        IllegalArgumentException - if n < 2.
        IllegalArgumentException - if w ≤ 0.0.
    • Method Detail

      • cost

        public int cost​(Permutation candidate)
        Description copied from interface: IntegerCostOptimizationProblem
        Computes the cost of a candidate solution to the problem instance. The lower the cost, the more optimal the candidate solution.
        Specified by:
        cost in interface IntegerCostOptimizationProblem<Permutation>
        Parameters:
        candidate - The candidate solution to evaluate.
        Returns:
        The cost of the candidate solution. Lower cost means better solution.