Package libai.ants.algorithms
Class AntSystem
- java.lang.Object
-
- libai.ants.algorithms.Metaheuristic
-
- libai.ants.algorithms.AntSystem
-
- All Implemented Interfaces:
java.util.Comparator<Ant>
- Direct Known Subclasses:
ElitistAntSystem
public abstract class AntSystem extends Metaheuristic
This class belong to the core classes of the Ant Framework.Implements the Ant System algorithm. First developed by Dorigo, this algorithm introduces a transition probability rule (implemented here in
desicionRule()
) to include heuristic information. However, this is still basic algorithm which will probably won't work very well for large problems. Other algorithm, such as AntConolySystem introduce several upgrades which greatly improve performance.
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
debug
If true, print debug information over System.out.printlnprotected static int
pheromonesEvaporationRate
Holds the rate at which pheromones will evaporate in thepheromonesEvaporation()
method-
Fields inherited from class libai.ants.algorithms.Metaheuristic
alpha, Ants, bestSolution, beta, candidates, currentIterationNumber, destinationNode, E, Graph, initialNode, maxNumIterations, numberOfAnts, numberOfNodes, Parameters, Pheromones
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AntSystem()
Constructor.protected
AntSystem(Enviroment E)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
antCycle(java.util.List<java.lang.Integer> Solution)
double
antDensity()
double
antQuantity()
void
candidateList(int max)
Generate, per node in the graph, a list of candidates nodes according to some problem specific heuristic.void
checkParameters()
Checks whether or not all of the algorithm's parameters exists.void
daemonActions()
This function is called on each iteration and it provides a way to implement centralized actionsint
decisionRule(int i, java.util.List<java.lang.Integer> currentSolution)
Used by ants to decided the next node to visit.boolean
linkOccursInPath(int i, int j, java.util.List<java.lang.Integer> solution)
Determine whether a link i,j exists in a Vectorvoid
pheromonesEvaporation()
Evaporates the pheromone trail contained in the enviroment E according to some ACO algorithm specific logicvoid
pheromonesUpdate()
Updates the pheromone trail contained in the enviroment E according to some ACO algorithm specific logicvoid
solve()
This is the body of the algorithm.-
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Methods inherited from class libai.ants.algorithms.Metaheuristic
compare, constrains, f, getBestSolution, getCurrentIterationNumber, getE, getNumberOfNodes, getParam, heuristicInfo, setE, setNumberOfNodes, setParam
-
-
-
-
Field Detail
-
debug
public static final boolean debug
If true, print debug information over System.out.println- See Also:
- Constant Field Values
-
pheromonesEvaporationRate
protected static final int pheromonesEvaporationRate
Holds the rate at which pheromones will evaporate in thepheromonesEvaporation()
method- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AntSystem
protected AntSystem(Enviroment E)
Constructor. Allocates the enviroment.- Parameters:
E
- enviroment
-
AntSystem
protected AntSystem()
Constructor. Empty constructor.
-
-
Method Detail
-
checkParameters
public void checkParameters() throws AntFrameworkException
Description copied from class:Metaheuristic
Checks whether or not all of the algorithm's parameters exists. If some obligatory parameter do not exist, the function throws an exception. If some other parameter do not exists but it is possible to set a default value, here is the place to do it.- Specified by:
checkParameters
in classMetaheuristic
- Throws:
AntFrameworkException
-
solve
public void solve() throws AntFrameworkException
Description copied from class:Metaheuristic
This is the body of the algorithm. Implements the fundamental logic and calls to other functions: pheromonesUpdate,pheromonesEvaporation.. according to some ACO algorithm specific logic- Specified by:
solve
in classMetaheuristic
- Throws:
AntFrameworkException
- AntFrameworkException
-
daemonActions
public void daemonActions()
Description copied from class:Metaheuristic
This function is called on each iteration and it provides a way to implement centralized actions- Specified by:
daemonActions
in classMetaheuristic
-
pheromonesUpdate
public void pheromonesUpdate()
Description copied from class:Metaheuristic
Updates the pheromone trail contained in the enviroment E according to some ACO algorithm specific logic- Specified by:
pheromonesUpdate
in classMetaheuristic
-
pheromonesEvaporation
public void pheromonesEvaporation()
Description copied from class:Metaheuristic
Evaporates the pheromone trail contained in the enviroment E according to some ACO algorithm specific logic- Specified by:
pheromonesEvaporation
in classMetaheuristic
-
decisionRule
public int decisionRule(int i, java.util.List<java.lang.Integer> currentSolution)
Description copied from class:Metaheuristic
Used by ants to decided the next node to visit.- Specified by:
decisionRule
in classMetaheuristic
- Parameters:
i
- source nodecurrentSolution
-currentSolution
- Returns:
- destination node
-
candidateList
public final void candidateList(int max)
Description copied from class:Metaheuristic
Generate, per node in the graph, a list of candidates nodes according to some problem specific heuristic. The candidates are stored in this class's candidates hashtable- Specified by:
candidateList
in classMetaheuristic
- Parameters:
max
- maximum number of candidates allowed
-
linkOccursInPath
public boolean linkOccursInPath(int i, int j, java.util.List<java.lang.Integer> solution)
Determine whether a link i,j exists in a Vector- Parameters:
i
- component i of the linkj
- component j of the linksolution
- a Vector- Returns:
- true if link i,j exists in vector otherwise false
-
antCycle
public double antCycle(java.util.List<java.lang.Integer> Solution)
-
antDensity
public double antDensity()
-
antQuantity
public double antQuantity()
-
-