Package libai.ants
Class Enviroment
- java.lang.Object
-
- libai.ants.Enviroment
-
public class Enviroment extends java.lang.Object
This class belong to the core classes of the Ant Framework.It represent the enviroment in which an optimization problem is going to be solved. An enviroment is composed of a problem Graph, a Matrix of pheromones and a number of Ants. This class is highly coupled with the Metaheuristic class, which utilizes this class to obtain all the necesary information to solve a given optimization problem.
-
-
Field Summary
Fields Modifier and Type Field Description protected Ant[]
Ants
Array of Antsprotected Graph
Graph
Graph wich represent the information of the problem to optimizeprotected int
numberOfAnts
protected Matrix
Pheromones
The trail of pheromones which ants will use to make desicions about where to move next in the graph
-
Constructor Summary
Constructors Constructor Description Enviroment()
Empty constructor.Enviroment(int numberOfAnts, Graph G, boolean randomPheromones)
Constructor.Enviroment(int numberOfAnts, Graph G, double v)
Constructor alias for Enviroment(numberOfAnts,G,false).Enviroment(Graph G)
Constructor.Enviroment(Graph G, boolean randomPheromones)
Constructor.Enviroment(Graph G, double v)
Constructor alias for Enviroment(G,false).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Ant
getAnt(int i)
Returns the ant located in the i position of the Ants arrayAnt[]
getAnts()
Returns the array of ants of this enviromentGraph
getGraph()
Returns the Graph of the problemint
getNumberOfAnts()
Returns the number of antsMatrix
getPheromones()
Returns the Pheromone trailvoid
setAnts()
Sets the array of ants of this enviroment.void
setAnts(int numberOfAnts)
Sets both the number of ants and the array of antsvoid
setGraph(Graph Graph)
void
setNumberOfAnts(int numberOfAnts)
Sets the number of ants of this Enviromentvoid
setPheromones(double v)
Set the pheromones trail to a fix value received as parameter This function must be call only if the graph of the enviroment has already been setvoid
setPheromones(Matrix Pheromones)
Set the pheromones trail to something received as parametervoid
showAnts()
Prints the array of Ants to the standard outputvoid
sortAnts(java.util.Comparator<Ant> comparator)
-
-
-
Field Detail
-
Graph
protected Graph Graph
Graph wich represent the information of the problem to optimize
-
Pheromones
protected Matrix Pheromones
The trail of pheromones which ants will use to make desicions about where to move next in the graph
-
numberOfAnts
protected int numberOfAnts
-
Ants
protected Ant[] Ants
Array of Ants
-
-
Constructor Detail
-
Enviroment
public Enviroment()
Empty constructor.
-
Enviroment
public Enviroment(Graph G)
Constructor. Allocates only the Graph- Parameters:
G
- the graph with the problem related information
-
Enviroment
public Enviroment(Graph G, boolean randomPheromones)
Constructor. Allocates only the Graph and the pheromone trail- Parameters:
G
- the graph with the problem related informationrandomPheromones
-randomPheromones
-
Enviroment
public Enviroment(Graph G, double v)
Constructor alias for Enviroment(G,false). Initializates the trail pheromone to a value v.- Parameters:
G
- object Graphv
- initial value of the pheromone trail
-
Enviroment
public Enviroment(int numberOfAnts, Graph G, boolean randomPheromones) throws AntFrameworkException
Constructor. Allocates the number of ants and the Graph. It also initialize the array of ants and the pheromone trail accoridng to the dimension of the graph.- Parameters:
numberOfAnts
- the number of ants to useG
- the graph with the problem related informationrandomPheromones
-randomPheromones
- Throws:
AntFrameworkException
- if numberOfAnts is less or equal to 0
-
Enviroment
public Enviroment(int numberOfAnts, Graph G, double v) throws AntFrameworkException
Constructor alias for Enviroment(numberOfAnts,G,false). Initializates the trail pheromone to a value v.- Parameters:
numberOfAnts
- number of antsG
- object Graphv
- initial value of the pheromone trail- Throws:
AntFrameworkException
- AntFrameworkException
-
-
Method Detail
-
getNumberOfAnts
public int getNumberOfAnts()
Returns the number of ants- Returns:
- the number of ants.
-
setNumberOfAnts
public void setNumberOfAnts(int numberOfAnts)
Sets the number of ants of this Enviroment- Parameters:
numberOfAnts
-numberOfAnts
-
getAnt
public Ant getAnt(int i)
Returns the ant located in the i position of the Ants array- Parameters:
i
- ant's position in the array- Returns:
- an Ant
-
setAnts
public void setAnts() throws AntFrameworkException
Sets the array of ants of this enviroment.- Throws:
AntFrameworkException
- AntFrameworkException
-
getAnts
public Ant[] getAnts()
Returns the array of ants of this enviroment- Returns:
- array of Ant
-
setAnts
public void setAnts(int numberOfAnts) throws AntFrameworkException
Sets both the number of ants and the array of ants- Parameters:
numberOfAnts
- number of ants- Throws:
AntFrameworkException
- if number of ants is <= 0
-
showAnts
public void showAnts()
Prints the array of Ants to the standard output
-
getPheromones
public Matrix getPheromones()
Returns the Pheromone trail- Returns:
- a Matrix containing the Pheromones trail
-
setPheromones
public void setPheromones(double v)
Set the pheromones trail to a fix value received as parameter This function must be call only if the graph of the enviroment has already been set- Parameters:
v
- value to set the pheromone
-
getGraph
public Graph getGraph()
Returns the Graph of the problem- Returns:
- Graph
-
setGraph
public void setGraph(Graph Graph)
- Parameters:
Graph
- the Graph to set
-
setPheromones
public void setPheromones(Matrix Pheromones)
Set the pheromones trail to something received as parameter- Parameters:
Pheromones
- the Pheromones to set
-
sortAnts
public void sortAnts(java.util.Comparator<Ant> comparator)
-
-