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

public abstract class Ant<C,E extends Environment> extends Object
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 Details

    • Ant

      public Ant()
  • Method Details

    • visitNode

      public void visitNode(C visitedNode, E environment)
      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

      public String getSolutionAsString()
      Gets th solution built as a String.
      Returns:
      Solution as a String.
    • getSolutionAsString

      public String getSolutionAsString(List<C> solution)
    • addPolicy

      public void addPolicy(AntPolicy<C,E> antPolicy)
    • selectNextNode

      public void selectNextNode(E environment, ConfigurationProvider configurationProvider)
      Selects a node and marks it as visited.
      Parameters:
      environment - Environment where the ant is building a solution.
      configurationProvider - Configuration provider.
    • doAfterSolutionIsReady

      public void doAfterSolutionIsReady(E environment, ConfigurationProvider configurationProvider)
      Improves the quality of the solution produced.
      Parameters:
      environment - Environment where the ant is building a solution.
      configurationProvider - Configuration provider.
    • isNodeVisited

      public boolean isNodeVisited(C component)
      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

      public double getSolutionCost(E environment)
    • isNodeValid

      public boolean isNodeValid(C node)
    • 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

      public abstract boolean isSolutionReady(E environment)
      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

      public 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.
      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

      public abstract List<C> getNeighbourhood(E environment)
      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

      public List<C> getSolution()
    • setSolution

      public void setSolution(List<C> solution)
    • getVisited

      public Map<C,Boolean> getVisited()
    • setVisited

      public void setVisited(Map<C,Boolean> visited)