Class TspModel

java.lang.Object
edu.cnu.mdi.sim.simanneal.tspdemo.TspModel

public class TspModel extends Object
Model for the Traveling Salesman Problem (TSP), optionally including a vertical "river" that adds a penalty (or bonus) when crossed.
  • Field Details

    • cityCount

      public final int cityCount
    • includeRiver

      public final boolean includeRiver
    • riverX

      public final double riverX
    • cities

      public final Point2D.Double[] cities
  • Constructor Details

    • TspModel

      public TspModel(int cityCount, boolean includeRiver, double riverPenalty, Random rng)
      Create a randomized TSP model.
      Parameters:
      cityCount - number of cities; must be at least four
      includeRiver - whether the model includes a vertical river
      riverPenalty - finite cost added to each river crossing
      rng - source of randomness
  • Method Details

    • setRiverEnabled

      public void setRiverEnabled(boolean enabled)
      Enable or disable the river penalty dynamically.
    • isRiverEnabled

      public boolean isRiverEnabled()
      Returns:
      whether river-crossing costs are enabled
    • getRiverPenalty

      public double getRiverPenalty()
      Returns:
      current river-crossing cost
    • setRiverPenalty

      public void setRiverPenalty(double riverPenalty)
      Set the river-crossing cost.
      Parameters:
      riverPenalty - finite penalty or bonus
    • getDistance

      public double getDistance(int cityA, int cityB)
      Distance between two cities including optional river penalty. Note: because of the river penalty, this "distance" can be negative!!!
      Parameters:
      cityA - index of first city
      cityB - index of second city
      Returns:
      Euclidean distance plus any applicable river cost