190 likes | 392 Views
JACK Execution. Part I. JACK Execution. BDI Execution Model Tasks with co-operative scheduling under JACK control makes efficient use of Java threads Message-based communication instead of RPC/CORBA (not prohibited) Object constructions through sentinels minimises type casting - faster.
E N D
JACK Execution Part I
JACK Execution • BDI Execution Model • Tasks with co-operative scheduling • under JACK control • makes efficient use of Java threads • Message-based communication • instead of RPC/CORBA (not prohibited) • Object constructions through sentinels • minimises type casting - faster
BDI Execution Model • Conceptually straight-forward and simple: • look for relevant plans • compute applicable plan instances • pick one to run • The evil is in the details: • where to look for plans • how to compute applicable instances • what happens on failure
databases events plans post handle assert retract JACK BDI Execution beliefs desires intentions
databases events plans post handle assert retract select plan (plan choice) JACK BDI Execution observe change beliefs desires intentions observe "environment" messages
databases events plans post handle assert retract select plan (plan choice) JACK BDI Execution observe change beliefs desires intentions observe "environment" step intention messages
Event Posting • Synchronous • In plans: @subtask(..) , @achieve(..) , @test(..) • From Java: Agent.postAndWait(..) • Asynchronous • In plans: @post(..) • From Java: Agent.postEvent(..) • also from database callbacks
Plan Instance Selection • The options: • of plan types that handle the event type, and • are relevant (static method), and • are applicable (plan instance method), and • are not already attempted and failed • The choice is: • first instance of first listed plan type, or • first of highest getInstanceInfo().rank(), or • chosen through PlanChoice event handling
Plan Example plan ComputeFactorialKnown extends Plan { #handles event Computation ev; static boolean relevant(Computation ev) { return ev.n > 1; } #reads database FactorialDB factorial; context() { factorial.get(ev.n, ev.v); } body() { } }
The Plan Header plan ComputeFactorialKnown extends Plan { #handles event Computation ev; static boolean relevant(Computation ev) { return ev.n > 1; } #reads database FactorialDB factorial; context() { factorial.get(ev.n, ev.v); } body() { } } • plan <Type> extends <PlanBase> • becomes a Java class of name <Type> • additional package and import statements as in Java • aos.jack.jak.plan.Plan auto-imported and the only <PlanBase> provided
The Handled Event plan ComputeFactorialKnown extends Plan { #handles event Computation ev; static boolean relevant(Computation ev) { return ev.n > 1; } #reads database FactorialDB factorial; context() { factorial.get(ev.n, ev.v); } body() { } } • #handles event <Type> <ref> ; • the <Type> is looked up through the enclosing Capability structure at initialisation time • the <ref> becomes a plan member that holds the actual event instance being handled
The relevant(..) Method plan ComputeFactorialKnown extends Plan { #handles event Computation ev; static boolean relevant(Computation ev) { return ev.n > 1; } #reads database FactorialDB factorial; context() { factorial.get(ev.n, ev.v); } body() { } } • static boolean relevant( <Type> <ref> ) { ... } • can inspect the event instance (argument) and decide whether or not the plan type is actually relevant for the particular event instance • returns true for relevant, and false otherwise • if omitted, the plan type is relevant
The context(..) Method plan ComputeFactorialKnown extends Plan { #handles event Computation ev; static boolean relevant(Computation ev) { return ev.n > 1; } #reads database FactorialDB factorial; context() { factorial.get(ev.n, ev.v); } body() { } } • context( ) { <cond> ; } • a single expression • “generates” plan instances by providing different bindings for logical variables involved
Plan Instance Execution • Some plan instance is chosen. • Executed as subtask of the event. • The plan succeeds, fails, or throws an exception. • BDI: on plan failure, an alternative plan instance is chosen.
Event Example event Computation extends Event { int n; logical long v; #posted as compute(int n,logical long v) { this.n = n; this.v = v; } }
The Event Header event Computation extends Event { int n; logical long v; #posted as compute(int n,logical long v) { this.n = n; this.v = v; } } • event <Type> extends <EventBase> • becomes a Java class of name <Type> • additional package and import statements as in Java • aos.jack.jak.event.* auto-imported with several <EventBase>: • Event • BDIGoalEvent, BDIFactEvent • MessageEvent, TracedMessageEvent • BDIMessageEvent, TracedBDIMessageEvent • event handling behaviour is tied to event base class
The Event Data Members event Computation extends Event { int n; logical long v; #posted as compute(int n,logical long v) { this.n = n; this.v = v; } } • like normal Java members • maybe logical, maybe bound by handling plan • used for qualifying event instance • “polymorphic”
The Posting Methods event Computation extends Event { int n; logical long v; #posted as compute(int n,logical long v) { this.n = n; this.v = v; } } • #posted as <name> ( <args> ) <body> • for constructing instances off sentinel • usually merely assigns event data members
BDI* Event Bases • Advanced event handling • Failure is not automatic - instead, the agent “keeps trying”, • Applicable set and Failure set • Tuning the event behaviour • “#set behavior <attribute> <value> ;” statements • Plan choice and meta-level reasoning • requiring the PlanChoice event generation (delivered as subtask) for choosing applicable plan instance through meta-level plans