Package jason.asSemantics
Class Agent
java.lang.Object
jason.asSemantics.Agent
- All Implemented Interfaces:
ToDOM
,java.io.Serializable
- Direct Known Subclasses:
ReplAg
public class Agent extends java.lang.Object implements java.io.Serializable, ToDOM
The Agent class has the belief base and plan library of an
AgentSpeak agent. It also implements the default selection
functions of the AgentSpeak semantics.
- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
aslSource
protected BeliefBase
bb
(package private) static javax.xml.parsers.DocumentBuilder
builder
private java.util.Map<java.lang.String,ArithFunction>
functions
private boolean
hasCustomSelOp
private java.util.List<Literal>
initialBels
private java.util.List<Literal>
initialGoals
private java.util.Map<java.lang.String,InternalAction>
internalActions
protected java.util.logging.Logger
logger
protected PlanLibrary
pl
private static java.util.concurrent.ScheduledExecutorService
scheduler
private static long
serialVersionUID
protected TransitionSystem
ts
-
Constructor Summary
Constructors Constructor Description Agent()
-
Method Summary
Modifier and Type Method Description void
abolish(Literal bel, Unifier un)
Removes all occurrences of bel in BB.boolean
addBel(Literal bel)
Adds bel in belief base (calling brf) and generates the events.void
addFunction(java.lang.Class<? extends ArithFunction> c)
register an arithmetic function implemented in Javaprivate void
addFunction(java.lang.Class<? extends ArithFunction> c, boolean user)
register an arithmetic function implemented in Javavoid
addFunction(java.lang.String function, int arity, java.lang.String literal)
register an arithmetic function implemented in AS (by a rule, literal, or internal action)private void
addInitBel(Literal b)
void
addInitialBel(Literal b)
Belief b will be stored to be included as an ordinary belief when the agent will start running.protected void
addInitialBelsFromProjectInBB()
void
addInitialBelsInBB()
add the initial beliefs in BB and produce the corresponding eventsvoid
addInitialGoal(Literal g)
goal g will be stored to be included as an initial goal when the agent will start runningprotected void
addInitialGoalsFromProjectInBB()
void
addInitialGoalsInTS()
includes all initial goals in the agent reasonerboolean
believes(LogicalFormula bel, Unifier un)
Returns true if BB contains the literal bel (using unification to test).java.util.List<Literal>[]
brf(Literal beliefToAdd, Literal beliefToDel, Intention i)
This function should revise the belief base with the given literal to add, to remove, and the current intention that triggered the operation.java.util.List<Literal>[]
brf(Literal beliefToAdd, Literal beliefToDel, Intention i, boolean addEnd)
This function should revise the belief base with the given literal to add, to remove, and the current intention that triggered the operation.int
buf(java.util.Collection<Literal> percepts)
Belief Update Function: adds/removes percepts into belief base.private void
checkCustomSelectOption()
void
clearAg()
Clear Agent's Beliefs and Plan LibraryAgent
clone(AgArch arch)
Clone BB, PL, Circumstance.static Agent
create(AgArch arch, java.lang.String agClass, ClassParameters bbPars, java.lang.String asSrc, Settings stts)
Setup the default agent configuration.boolean
delBel(Literal bel)
If the agent believes in bel, removes it (calling brf) and generate the event.Literal
findBel(Literal bel, Unifier un)
Find a literal in BB using unification to test.private void
fixAgInIAandFunctions(Agent a)
private void
fixAgInIAandFunctions(Agent a, Literal l)
org.w3c.dom.Document
getAgProgram()
Gets the agent program (Beliefs and plans) as XMLorg.w3c.dom.Document
getAgState()
Gets the agent "mind" (beliefs, plans, and circumstance) as XMLorg.w3c.dom.Element
getAsDOM(org.w3c.dom.Document document)
Gets the agent "mind" as XMLjava.lang.String
getASLSrc()
Returns the .asl file source used to create this agentBeliefBase
getBB()
ArithFunction
getFunction(java.lang.String function, int arity)
get the object the implements the arithmetic function function/arity, either global (like math.max) or local (like .count).InternalAction
getIA(java.lang.String iaName)
java.util.List<Literal>
getInitialBels()
java.util.Collection<Literal>
getInitialGoals()
java.util.logging.Logger
getLogger()
PlanLibrary
getPL()
static java.util.concurrent.ScheduledExecutorService
getScheduler()
TransitionSystem
getTS()
boolean
hasCustomSelectOption()
void
importComponents(Agent a)
Imports beliefs, plans and initial goals from another agent.void
initAg()
Initialises the TS and other components of the agentTransitionSystem
initAg(AgArch arch, BeliefBase bb, java.lang.String asSrc, Settings stts)
Deprecated.Prefer the initAg method with only the source code of the agent as parameter.void
initAg(java.lang.String asSrc)
Deprecated.use initAg() and load(src)void
initDefaultFunctions()
boolean
killAcc(java.lang.String agName)
Returns true if this agent accepts to be killed by another agent called agName.void
load(java.io.InputStream in, java.lang.String sourceId)
parse and load asl codevoid
load(java.lang.String asSrc)
parse and load the initial agent code, asSrc may be nullvoid
loadAgSrc(java.lang.String asSrc)
only parse and load the initial agent code, asSrc may be null it does not load kqml default plans and do not trigger initial beliefs and goalsvoid
loadKqmlPlans()
void
parseAS(java.io.File asFile)
Adds beliefs and plans form a filevoid
parseAS(java.io.InputStream asIn, java.lang.String sourceId)
void
parseAS(java.io.Reader asIn, java.lang.String sourceId)
void
parseAS(java.net.URL asURL)
Adds beliefs and plans form an URLvoid
parseAS(java.net.URL asURL, java.lang.String sourceId)
ActionExec
selectAction(java.util.Queue<ActionExec> actions)
Event
selectEvent(java.util.Queue<Event> events)
Intention
selectIntention(java.util.Queue<Intention> intentions)
Message
selectMessage(java.util.Queue<Message> messages)
Option
selectOption(java.util.List<Option> options)
void
setASLSrc(java.lang.String file)
void
setBB(BeliefBase bb)
void
setIA(java.lang.String iaName, InternalAction ia)
void
setLogger(AgArch arch)
void
setPL(PlanLibrary pl)
void
setTS(TransitionSystem ts)
TS Initialisation (called by the AgArch)boolean
socAcc(Message m)
Follows the default implementation for the agent's message acceptance relation and selection functionsvoid
stopAg()
java.lang.String
toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
- Constant Field Values
-
bb
-
pl
-
ts
-
aslSource
protected java.lang.String aslSource -
initialGoals
-
initialBels
-
internalActions
-
functions
-
hasCustomSelOp
private boolean hasCustomSelOp -
scheduler
private static java.util.concurrent.ScheduledExecutorService scheduler -
logger
protected transient java.util.logging.Logger logger -
builder
static javax.xml.parsers.DocumentBuilder builder
-
-
Constructor Details
-
Agent
public Agent()
-
-
Method Details
-
create
public static Agent create(AgArch arch, java.lang.String agClass, ClassParameters bbPars, java.lang.String asSrc, Settings stts) throws java.lang.ExceptionSetup the default agent configuration. Creates the agent class defined by agClass, default is jason.asSemantics.Agent. Creates the TS for the agent. Creates the belief base for the agent.- Throws:
java.lang.Exception
-
initAg
public void initAg()Initialises the TS and other components of the agent -
initAg
@Deprecated public void initAg(java.lang.String asSrc) throws java.lang.ExceptionDeprecated.use initAg() and load(src)parse and load the agent code, asSrc may be null- Throws:
java.lang.Exception
-
load
public void load(java.lang.String asSrc) throws java.lang.Exceptionparse and load the initial agent code, asSrc may be null- Throws:
java.lang.Exception
-
load
public void load(java.io.InputStream in, java.lang.String sourceId) throws java.lang.Exceptionparse and load asl code- Throws:
java.lang.Exception
-
clearAg
public void clearAg()Clear Agent's Beliefs and Plan Library -
loadAgSrc
public void loadAgSrc(java.lang.String asSrc) throws java.lang.Exceptiononly parse and load the initial agent code, asSrc may be null it does not load kqml default plans and do not trigger initial beliefs and goals- Throws:
java.lang.Exception
-
loadKqmlPlans
public void loadKqmlPlans() throws java.lang.Exception- Throws:
java.lang.Exception
-
initAg
@Deprecated public TransitionSystem initAg(AgArch arch, BeliefBase bb, java.lang.String asSrc, Settings stts) throws JasonExceptionDeprecated.Prefer the initAg method with only the source code of the agent as parameter. A call of this method likeTransitionSystem ts = ag.initAg(arch, bb, asSrc, stts)
can be replaced bynew TransitionSystem(ag, new Circumstance(), stts, arch); ag.setBB(bb); // only if you use a custom BB ag.initAg(asSrc); TransitionSystem ts = ag.getTS();
- Throws:
JasonException
-
stopAg
public void stopAg() -
clone
Clone BB, PL, Circumstance. A new TS is created (based on the cloned circumstance). -
fixAgInIAandFunctions
- Throws:
java.lang.Exception
-
fixAgInIAandFunctions
- Throws:
java.lang.Exception
-
setLogger
-
getLogger
public java.util.logging.Logger getLogger() -
getScheduler
public static java.util.concurrent.ScheduledExecutorService getScheduler() -
getASLSrc
public java.lang.String getASLSrc()Returns the .asl file source used to create this agent -
setASLSrc
public void setASLSrc(java.lang.String file) -
parseAS
public void parseAS(java.net.URL asURL) throws java.lang.ExceptionAdds beliefs and plans form an URL- Throws:
java.lang.Exception
-
parseAS
public void parseAS(java.net.URL asURL, java.lang.String sourceId) throws java.lang.Exception- Throws:
java.lang.Exception
-
parseAS
public void parseAS(java.io.File asFile) throws java.lang.ExceptionAdds beliefs and plans form a file- Throws:
java.lang.Exception
-
parseAS
public void parseAS(java.io.InputStream asIn, java.lang.String sourceId) throws jason.asSyntax.parser.ParseException, JasonException- Throws:
jason.asSyntax.parser.ParseException
JasonException
-
parseAS
public void parseAS(java.io.Reader asIn, java.lang.String sourceId) throws jason.asSyntax.parser.ParseException, JasonException- Throws:
jason.asSyntax.parser.ParseException
JasonException
-
getIA
public InternalAction getIA(java.lang.String iaName) throws java.lang.ClassNotFoundException, java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.IllegalArgumentException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.SecurityException- Throws:
java.lang.ClassNotFoundException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.SecurityException
-
setIA
-
initDefaultFunctions
public void initDefaultFunctions() -
addFunction
register an arithmetic function implemented in Java -
addFunction
register an arithmetic function implemented in Java -
addFunction
public void addFunction(java.lang.String function, int arity, java.lang.String literal)register an arithmetic function implemented in AS (by a rule, literal, or internal action) -
getFunction
get the object the implements the arithmetic function function/arity, either global (like math.max) or local (like .count). -
addInitialBel
Belief b will be stored to be included as an ordinary belief when the agent will start running. This method is usually called by the parser; at compile time, when the TS may not be ready yet and thus no events can be produced. Beliefs are then scheduled here to be definitely included later when the TS is ready. -
getInitialBels
-
addInitialBelsInBB
add the initial beliefs in BB and produce the corresponding events- Throws:
RevisionFailedException
-
addInitialBelsFromProjectInBB
protected void addInitialBelsFromProjectInBB() -
addInitBel
- Throws:
RevisionFailedException
-
addInitialGoal
goal g will be stored to be included as an initial goal when the agent will start running -
getInitialGoals
-
addInitialGoalsInTS
public void addInitialGoalsInTS()includes all initial goals in the agent reasoner -
addInitialGoalsFromProjectInBB
protected void addInitialGoalsFromProjectInBB() -
importComponents
Imports beliefs, plans and initial goals from another agent. Initial beliefs and goals are stored in "initialBels" and "initialGoals" lists but not included in the BB / TS. The methods addInitialBelsInBB and addInitialGoalsInTS should be called in the sequel to add those beliefs and goals into the agent.- Throws:
JasonException
-
socAcc
Follows the default implementation for the agent's message acceptance relation and selection functions -
killAcc
public boolean killAcc(java.lang.String agName)Returns true if this agent accepts to be killed by another agent called agName. This method can be overridden to customize this option. -
selectEvent
-
selectOption
-
selectIntention
-
selectMessage
-
selectAction
-
setTS
TS Initialisation (called by the AgArch) -
getTS
-
setBB
-
getBB
-
setPL
-
getPL
-
buf
Belief Update Function: adds/removes percepts into belief base.- Returns:
- the number of changes (add + dels)
-
believes
Returns true if BB contains the literal bel (using unification to test). The unifier un is updated by the method. -
findBel
Find a literal in BB using unification to test. Returns the belief as it is in BB, e.g. findBel(a(_),...) may returns a(10)[source(ag)]. The unifier un is updated by the method. -
brf
public java.util.List<Literal>[] brf(Literal beliefToAdd, Literal beliefToDel, Intention i) throws RevisionFailedExceptionThis function should revise the belief base with the given literal to add, to remove, and the current intention that triggered the operation.In its return, List[0] has the list of actual additions to the belief base, and List[1] has the list of actual deletions; this is used to generate the appropriate internal events. If nothing change, returns null.
- Throws:
RevisionFailedException
-
brf
public java.util.List<Literal>[] brf(Literal beliefToAdd, Literal beliefToDel, Intention i, boolean addEnd) throws RevisionFailedExceptionThis function should revise the belief base with the given literal to add, to remove, and the current intention that triggered the operation.In its return, List[0] has the list of actual additions to the belief base, and List[1] has the list of actual deletions; this is used to generate the appropriate internal events. If nothing change, returns null.
- Throws:
RevisionFailedException
-
addBel
Adds bel in belief base (calling brf) and generates the events. If bel has no source, addsource(self)
. (the belief is not cloned!)- Throws:
RevisionFailedException
-
delBel
If the agent believes in bel, removes it (calling brf) and generate the event.- Throws:
RevisionFailedException
-
abolish
Removes all occurrences of bel in BB. If un is null, an empty Unifier is used.- Throws:
RevisionFailedException
-
checkCustomSelectOption
private void checkCustomSelectOption() -
hasCustomSelectOption
public boolean hasCustomSelectOption() -
getAgState
public org.w3c.dom.Document getAgState()Gets the agent "mind" (beliefs, plans, and circumstance) as XML -
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-
getAsDOM
public org.w3c.dom.Element getAsDOM(org.w3c.dom.Document document)Gets the agent "mind" as XML -
getAgProgram
public org.w3c.dom.Document getAgProgram()Gets the agent program (Beliefs and plans) as XML
-