Class TspModel
java.lang.Object
edu.cnu.mdi.sim.simanneal.tspdemo.TspModel
Model for the Traveling Salesman Problem (TSP), optionally including
a vertical "river" that adds a penalty (or bonus) when crossed.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoublegetDistance(int cityA, int cityB) Distance between two cities including optional river penalty.doublebooleanvoidsetRiverEnabled(boolean enabled) Enable or disable the river penalty dynamically.voidsetRiverPenalty(double riverPenalty) Set the river-crossing cost.
-
Field Details
-
cityCount
public final int cityCount -
includeRiver
public final boolean includeRiver -
riverX
public final double riverX -
cities
-
-
Constructor Details
-
TspModel
Create a randomized TSP model.- Parameters:
cityCount- number of cities; must be at least fourincludeRiver- whether the model includes a vertical riverriverPenalty- finite cost added to each river crossingrng- 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 citycityB- index of second city- Returns:
- Euclidean distance plus any applicable river cost
-