ants.gnutant
Class GnutantPheromone

java.lang.Object
  |
  +--ants.gnutant.GnutantPheromone
All Implemented Interfaces:
ResourceManager

public class GnutantPheromone
extends Object
implements ResourceManager

Gnutant Pheromone is "the routing table" of the Gnutant species. Ants may only add knowledge about new keywords, and the nest where documents relating to that keyword may be found. The underlying data structure will take care of limiting the resource (memory) usage, by implementing an LRU policy. Ants may also obtain a list of nests that contain more information about a given keyword or closely matching keywords.

Version:
$Revision: 1.6 $
Author:
Hein Meling

Field Summary
static String NAME
          Identifier used in the configuration files
static String PAR_CAPACITY
          String name of the parameter used to determine the number of repetitions to be executed.
static String PAR_CLOSENESS
          String name of the parameter used to determine the number of iterations to be executed.
 
Constructor Summary
GnutantPheromone(Factory factory, String name)
          Creates a new GnutantPheromone instance.
 
Method Summary
 boolean addKeyhash(HashedKeyword keyhash, NestId nestid)
          Add a new nest containing a document that match the specified keyword, represented by a hash of the keyword.
 ArrayList getNextNest(HashedKeyword keyhash, ArrayList path)
          Obtains a set of possible next nests based on the provided keyhash.
 String toString()
          Returns a string representation of the GnutantPheromone.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NAME

public static final String NAME
Identifier used in the configuration files

See Also:
Constant Field Values

PAR_CAPACITY

public static final String PAR_CAPACITY
String name of the parameter used to determine the number of repetitions to be executed.

See Also:
Constant Field Values

PAR_CLOSENESS

public static final String PAR_CLOSENESS
String name of the parameter used to determine the number of iterations to be executed.

See Also:
Constant Field Values
Constructor Detail

GnutantPheromone

public GnutantPheromone(Factory factory,
                        String name)
Creates a new GnutantPheromone instance. The object is created through the factory; possible initialization is performed through init methods.

Parameters:
factory - the factory to be used to read configuration arguments and to create other configurable objects
name - the name that is associated to this instance in the configuration file
Method Detail

addKeyhash

public boolean addKeyhash(HashedKeyword keyhash,
                          NestId nestid)
Add a new nest containing a document that match the specified keyword, represented by a hash of the keyword.

Note that this method is synchronized because there may be a race condition if trying to simultaneously add the same keyhash with different nest identifiers.

Parameters:
keyhash - Hash of the keyword represented by a HashedKeyword object.
nestid - Identifier for the nest holding a document represented by the specified keyword.
Returns:
true if the given keyword is already known. That is, other nests store information about this keyword. false is returned if the keyword is unknown.

getNextNest

public ArrayList getNextNest(HashedKeyword keyhash,
                             ArrayList path)
Obtains a set of possible next nests based on the provided keyhash. If there is no exact match for the specified keyhash in the underlying datastructure the closes match will be made available in the first position in the returned ArrayList.

Parameters:
keyhash - the keyword to match against to find the set of possible next nests.
path - a list of nests to avoid, since we have already visited them.
Returns:
a list of possible next nests, sorted according to their closeness to the specified keyhash.

toString

public String toString()
Returns a string representation of the GnutantPheromone. Since this a sort routing table, it will typically be large, so using this for outputing to the screen is ill-advised. It is mainly useful for logging the content of the pheromone tables at various times during a run.

Overrides:
toString in class Object
Returns:
a String representation of the GnutantPheromone object. A multiline string will be returned.