Package isula.aco
Class Ant<C,E extends Environment>
java.lang.Object
isula.aco.Ant<C,E>
- Type Parameters:
C
- Class for components of a solution.E
- Class representing the Environment.
- Direct Known Subclasses:
AntWithPartialSolution
The little workers that build solutions: They belong to a colony. This is an
Abstract Type so you must extend it in order to fill the characteristics of
your optimization problem.
Some convenient methods to define are:
- isSolutionReady(), to define when the Ant must stop adding components to its solution.
- getSolutionCost(), to define the cost of the current solution. It will help to decide the best solution built so far.
- getHeuristicValue(), to explote problem domain information while constructing solutions.
- getNeighbourhood(), this returns a list of possible components to add to the solution.
- getPheromoneTrailValue(), returns the pheromone trail value associated to a Solution Component.
- setPheromoneTrailValue(), to assign a pheromone value to a Solution Component.
- Author:
- Carlos G. Gavidia
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
void
clear()
Resets the visited vector, clears current solution components and sets the index to 0.void
doAfterSolutionIsReady
(E environment, ConfigurationProvider configurationProvider) Improves the quality of the solution produced.int
Gets the current index for the Ant while constructing a solution.abstract Double
getHeuristicValue
(C solutionComponent, Integer positionInSolution, E environment) Calculates the heuristic contribution for the cost of the solution by adding a component at an specific position.getNeighbourhood
(E environment) The components that are available for selection while an Ant is constructing its solution.abstract Double
getPheromoneTrailValue
(C solutionComponent, Integer positionInSolution, E environment) Returns the pheromone value associated to a solution component at an specific positionGets th solution built as a String.getSolutionAsString
(List<C> solution) double
getSolutionCost
(E environment) abstract double
getSolutionCost
(E environment, List<C> solution) Calculates the cost associated to the solution build, which is needed to determine the performance of the Ant.boolean
isNodeValid
(C node) boolean
isNodeVisited
(C component) Verifies if a component.abstract boolean
isSolutionReady
(E environment) Returns true when the solution build by the current Ant is finished.void
selectNextNode
(E environment, ConfigurationProvider configurationProvider) Selects a node and marks it as visited.void
setCurrentIndex
(int currentIndex) Sets the current index for the Ant.abstract void
setPheromoneTrailValue
(C solutionComponent, Integer positionInSolution, E environment, Double value) Updates the value of a cell on the pheromone matrix.void
setSolution
(List<C> solution) void
setVisited
(Map<C, Boolean> visited) void
Mark a node as visited.
-
Constructor Details
-
Ant
public Ant()
-
-
Method Details
-
visitNode
Mark a node as visited.- Parameters:
visitedNode
- Visited node.
-
clear
public void clear()Resets the visited vector, clears current solution components and sets the index to 0. -
getSolutionAsString
Gets th solution built as a String.- Returns:
- Solution as a String.
-
getSolutionAsString
-
addPolicy
-
selectNextNode
Selects a node and marks it as visited.- Parameters:
environment
- Environment where the ant is building a solution.configurationProvider
- Configuration provider.
-
doAfterSolutionIsReady
Improves the quality of the solution produced.- Parameters:
environment
- Environment where the ant is building a solution.configurationProvider
- Configuration provider.
-
isNodeVisited
Verifies if a component. is already included in the solution.- Parameters:
component
- Component to verify.- Returns:
- True if the node is already visited. False otherwise.
-
getSolutionCost
-
isNodeValid
-
setCurrentIndex
public void setCurrentIndex(int currentIndex) Sets the current index for the Ant.- Parameters:
currentIndex
- Current index.
-
getCurrentIndex
public int getCurrentIndex()Gets the current index for the Ant while constructing a solution.- Returns:
- Current index.
-
isSolutionReady
Returns true when the solution build by the current Ant is finished.- Parameters:
environment
- Environment instance with problem information.- Returns:
- True if the solution is finished, false otherwise.
-
getSolutionCost
Calculates the cost associated to the solution build, which is needed to determine the performance of the Ant.- Parameters:
environment
- Environment instance with problem information.- Returns:
- The cost of the solution built.
-
getHeuristicValue
public abstract Double getHeuristicValue(C solutionComponent, Integer positionInSolution, E environment) Calculates the heuristic contribution for the cost of the solution by adding a component at an specific position.- Parameters:
solutionComponent
- Solution component.positionInSolution
- Position of this component in the solution.environment
- Environment instance with problem information.- Returns:
- Heurisitic contribution.
-
getNeighbourhood
The components that are available for selection while an Ant is constructing its solution.- Parameters:
environment
- Environment instance with problem information.- Returns:
- List of available components.
-
getPheromoneTrailValue
public abstract Double getPheromoneTrailValue(C solutionComponent, Integer positionInSolution, E environment) Returns the pheromone value associated to a solution component at an specific position- Parameters:
solutionComponent
- Solution component.positionInSolution
- Position of this component in the solution.environment
- Environment instance with problem information.- Returns:
- Pheromone value.
-
setPheromoneTrailValue
public abstract void setPheromoneTrailValue(C solutionComponent, Integer positionInSolution, E environment, Double value) Updates the value of a cell on the pheromone matrix.- Parameters:
solutionComponent
- Solution component.positionInSolution
- Position of this component in the solution.environment
- Environment instance with problem information.value
- New pheromone value.
-
getSolution
-
setSolution
-
getVisited
-
setVisited
-