zeus.actors
Class ResourceDb

java.lang.Object
  extended byjava.util.Dictionary
      extended byjava.util.Hashtable
          extended byzeus.actors.ResourceDb
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable

public class ResourceDb
extends java.util.Hashtable

This class implements the Resource Database component, whose role is to store the resources owned by the agent, (which are Fact objects). The Resource Database is simply an extended Hashtable with the fact objects held indexed by their types.

Developers will probably interact the Resource Database on a regular basis, as it both contains the agent's knowledge and provides a means of altering it. A reference to the Resource Database can be obtained from the agent's AgentContext object, allowing access to the methods described below; (The methods without descriptions are primarily used by other agent components and so are unlikely to be useful to developers).

Change log

19/08/00 - added some code to the any(Fact) method at about line 580 - 590 this is to stop an unnecessary exception being thrown, the new behavior is that if the method is called and there are no facts of that type in the resourcedb then a new fact of that type will be returned instead.

Change log ---------- 13/06/01 added a number of fields (name,planner,ontologyDb, gensym,externaldb) which are used to store references that would be obtained from the AgentContext object, but cannot be if the context is not available at initialisation. I hope that this will enable better extensibility, but it might cause problems if the agent architecture is altered at run time. Added isSet method to allow programmers to check to see if Added setPlanner to permit this reference to be updated easily Added setName Added setOntologyDb Added setGenSym

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.util.Hashtable
 
Field Summary
private static int ACCESS
           
private static int ADD
           
protected  AgentContext context
           
private static int DELETE
           
private  HSet[] eventMonitor
           
protected  GenSym gensym
           
private static int MODIFY
           
protected  java.lang.String name
           
protected  OntologyDb ontologyDb
           
protected  Planner planner
           
 
Fields inherited from class java.util.Hashtable
 
Constructor Summary
ResourceDb()
           
ResourceDb(AgentContext context)
           
 
Method Summary
 ResourceItem add(Fact fact)
          The primary method for adding new facts to the Resource Database was synchronized
 ResourceItem add(Fact[] List)
          was synchronized
 ResourceItem add(java.util.Vector List)
          was synchronized
 void addFactMonitor(FactMonitor monitor, long event_type)
           
 void addFactMonitor(FactMonitor monitor, long event_type, boolean notify_previous)
          Use this if your code needs to react to changes in the Resource Database.
 Fact[] all(Fact fact)
          Use this to retrieve all the facts in the database that match the parameter
 Fact[] all(java.lang.String type)
           
 Goal allocateResource(PlanRecord rec, int position, int required)
           
 java.util.Vector allocateResources(PlanRecord rec)
           
 Fact any(Fact fact)
          Use this to randomly retrieve a fact that matches the parameter
 Fact any(java.lang.String type)
          Randomly retrieves a fact with the same type as the parameter
 void consume(DataRec rec)
           
 boolean contains(Fact fact, int start)
          Use this to test whether a particular fact exists in the database
 Fact debit(double amount)
          Special purpose method to decrease the value of the amount attribute of MONEY facts
private  void debug(java.lang.String str)
           
 void del(Fact fact)
          The primary method for permanently removing facts from the Resource Database
 void del(Fact[] List)
           
 void del(java.util.Vector List)
           
 void deleteAll(java.lang.String type)
          Deletes all facts matching the parameter type, should obviously be used with caution
 Fact evalLocal(Fact fact)
           
 boolean evalNegative(Fact fact)
           
 int findAll(PlanRecord rec, int precond_position, int required)
           
 void free(DataRec rec)
           
 AgentContext getAgentContext()
          Use this to obtain handles to the other internal components of agent
 boolean isContextSet()
          check that the AgentContext context field is set.
 boolean isGenSymSet()
          check that the gensym refernece is set
 boolean isNameSet()
          check that the name refernce is set
 boolean isOntologyDbSet()
          check that the ontologyDb reference is set
 boolean isPlannerSet()
          check that the planner reference is set
 boolean isSet()
          check to see if all necessary fields are set
 void modify(Fact f1, Fact f2)
          Use this if facts have changed and you need to update the Resource Database
private  void notifyMonitors(ResourceItem item, int type)
           
 void removeFactMonitor(FactMonitor monitor, long event_type)
           
(package private)  void replaceOrAdd(Fact fact)
          was synchronized
 int reserve(DataRec datarec, int start, int required)
           
 int reserve(DataRec datarec, PlanRecord rec, int start, int required)
          Enables a resource to be secured at a certain time period, (this is provided primarily for internal use)
 void setGenSym(GenSym gensym)
          this allows you to set the gensym referencce
 void setName(java.lang.String name)
          this allows you to set the name reference
 void setOntologyDb(OntologyDb ontologyDb)
          this allows you to set the ontolgyDb reference
 void setPlanner(Planner planner)
          this allows you to set the planner reference
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

eventMonitor

private HSet[] eventMonitor

ADD

private static final int ADD
See Also:
Constant Field Values

MODIFY

private static final int MODIFY
See Also:
Constant Field Values

DELETE

private static final int DELETE
See Also:
Constant Field Values

ACCESS

private static final int ACCESS
See Also:
Constant Field Values

context

protected AgentContext context

name

protected java.lang.String name

planner

protected Planner planner

ontologyDb

protected OntologyDb ontologyDb

gensym

protected GenSym gensym
Constructor Detail

ResourceDb

public ResourceDb()

ResourceDb

public ResourceDb(AgentContext context)
Method Detail

setPlanner

public void setPlanner(Planner planner)
this allows you to set the planner reference


setName

public void setName(java.lang.String name)
this allows you to set the name reference


setGenSym

public void setGenSym(GenSym gensym)
this allows you to set the gensym referencce


setOntologyDb

public void setOntologyDb(OntologyDb ontologyDb)
this allows you to set the ontolgyDb reference


isNameSet

public boolean isNameSet()
check that the name refernce is set


isGenSymSet

public boolean isGenSymSet()
check that the gensym refernece is set


isPlannerSet

public boolean isPlannerSet()
check that the planner reference is set


isOntologyDbSet

public boolean isOntologyDbSet()
check that the ontologyDb reference is set


isContextSet

public boolean isContextSet()
check that the AgentContext context field is set. Note: this is not necessary for the rdb to function, but is included so that


isSet

public boolean isSet()
check to see if all necessary fields are set


getAgentContext

public AgentContext getAgentContext()
Use this to obtain handles to the other internal components of agent


add

public ResourceItem add(java.util.Vector List)
was synchronized


add

public ResourceItem add(Fact[] List)
was synchronized


add

public ResourceItem add(Fact fact)
The primary method for adding new facts to the Resource Database was synchronized


replaceOrAdd

void replaceOrAdd(Fact fact)
was synchronized


del

public void del(java.util.Vector List)

del

public void del(Fact[] List)

del

public void del(Fact fact)
The primary method for permanently removing facts from the Resource Database


modify

public void modify(Fact f1,
                   Fact f2)
Use this if facts have changed and you need to update the Resource Database


free

public void free(DataRec rec)

consume

public void consume(DataRec rec)

findAll

public int findAll(PlanRecord rec,
                   int precond_position,
                   int required)

reserve

public int reserve(DataRec datarec,
                   PlanRecord rec,
                   int start,
                   int required)
Enables a resource to be secured at a certain time period, (this is provided primarily for internal use)


reserve

public int reserve(DataRec datarec,
                   int start,
                   int required)

allocateResources

public java.util.Vector allocateResources(PlanRecord rec)

allocateResource

public Goal allocateResource(PlanRecord rec,
                             int position,
                             int required)

debit

public Fact debit(double amount)
Special purpose method to decrease the value of the amount attribute of MONEY facts


evalLocal

public Fact evalLocal(Fact fact)

evalNegative

public boolean evalNegative(Fact fact)

all

public Fact[] all(java.lang.String type)

all

public Fact[] all(Fact fact)
Use this to retrieve all the facts in the database that match the parameter


deleteAll

public void deleteAll(java.lang.String type)
Deletes all facts matching the parameter type, should obviously be used with caution


any

public Fact any(java.lang.String type)
Randomly retrieves a fact with the same type as the parameter


any

public Fact any(Fact fact)
Use this to randomly retrieve a fact that matches the parameter


contains

public boolean contains(Fact fact,
                        int start)
Use this to test whether a particular fact exists in the database


addFactMonitor

public void addFactMonitor(FactMonitor monitor,
                           long event_type,
                           boolean notify_previous)
Use this if your code needs to react to changes in the Resource Database. This provides a programatic alternative to writing reaction rules


addFactMonitor

public void addFactMonitor(FactMonitor monitor,
                           long event_type)

removeFactMonitor

public void removeFactMonitor(FactMonitor monitor,
                              long event_type)

notifyMonitors

private void notifyMonitors(ResourceItem item,
                            int type)

debug

private void debug(java.lang.String str)


Copyright © 2000-2003 BT Exact Technologies. All Rights Reserved.