org.apache.mahout.ga.watchmaker.travellingsalesman
Class RouteEvaluator
java.lang.Object
org.apache.mahout.ga.watchmaker.travellingsalesman.RouteEvaluator
- All Implemented Interfaces:
- org.uncommons.watchmaker.framework.FitnessEvaluator<java.util.List<java.lang.String>>
public class RouteEvaluator
- extends java.lang.Object
- implements org.uncommons.watchmaker.framework.FitnessEvaluator<java.util.List<java.lang.String>>
Fitness evalator that measures the total distance of a route in the travelling salesman problem. The
fitness score of a route is the total distance (in km). A route is represented as a list of cities in the
order that they will be visited. The last leg of the journey is from the last city in the list back to the
first.
The original code is from the Watchmaker project (https://watchmaker.dev.java.net/).
Method Summary |
double |
getFitness(java.util.List<java.lang.String> candidate,
java.util.List<? extends java.util.List<java.lang.String>> population)
Calculates the length of an evolved route. |
boolean |
isNatural()
Returns false since shorter distances represent fitter candidates. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
RouteEvaluator
public RouteEvaluator(DistanceLookup distances)
- Parameters:
distances
- Provides distances between a set of cities.
getFitness
public double getFitness(java.util.List<java.lang.String> candidate,
java.util.List<? extends java.util.List<java.lang.String>> population)
- Calculates the length of an evolved route.
- Specified by:
getFitness
in interface org.uncommons.watchmaker.framework.FitnessEvaluator<java.util.List<java.lang.String>>
- Parameters:
candidate
- The route to evaluate.population
-
- Returns:
- The total distance (in kilometres) of a journey that visits each city in order and returns to the
starting point.
isNatural
public boolean isNatural()
- Returns false since shorter distances represent fitter candidates.
- Specified by:
isNatural
in interface org.uncommons.watchmaker.framework.FitnessEvaluator<java.util.List<java.lang.String>>
- Returns:
- false
Copyright © 2008-2010 The Apache Software Foundation. All Rights Reserved.