Agent Programming in Goal Modules

download Agent Programming in  Goal Modules

of 53

  • date post

    10-Feb-2016
  • Category

    Documents

  • view

    28
  • download

    3

Embed Size (px)

description

Agent Programming in Goal Modules. Koen Hindriks Delft University of Technology, The Netherlands. Agents in Games. Outline. Modules BW4T Assignment. Modules. An Agent is a Set of Modules. init module{ knowledge{ … } beliefs{ %%% INITIAL BELIEFS ONLY IN INIT MODULE %%% } - PowerPoint PPT Presentation

Transcript of Agent Programming in Goal Modules

GOAL

Agent Programming in GoalModulesKoen HindriksDelft University of Technology, The NetherlandsKoen HindriksProgramming Multi-Agent SystemsKoen HindriksProgramming Multi-Agent SystemsAgents in GamesKoen HindriksProgramming Multi-Agent SystemsKoen HindriksProgramming Multi-Agent SystemsOutlineModules

BW4T AssignmentKoen HindriksProgramming Multi-Agent SystemsKoen HindriksProgramming Multi-Agent SystemsModulesKoen HindriksProgramming Multi-Agent SystemsKoen HindriksProgramming Multi-Agent SystemsAn Agent is a Set of ModulesBuilt-in modules:init module:Define global knowledgeDefine initial beliefs & goalsProcess send once perceptsSpecify environment actionsmain moduleAction selection strategyevent moduleProcess perceptsProcess messagesGoal management

User-defined modules.init module{ knowledge{ } beliefs{ %%% INITIAL BELIEFS ONLY IN INIT MODULE %%% } goals{ } program{ %%% PROCESS SEND ONCE PERCEPTS HERE %%% } actionspec{ %%% SPECIFY ENVIRONMENT ACTIONS HERE %%% }} main module{ % OPTIONAL knowledge section % NO beliefs section HERE! % OPTIONAL goal section (not advised in main) program{ %%% ENVIRONMENT ACTION SELECTION HERE %%% }}

event module{ program{ %%% PROCESS PERCEPTS HERE %%% %%% PROCESS MESSAGES HERE %%% %%% PERFORM GOAL MANAGEMENT HERE %%% }}Koen HindriksProgramming Multi-Agent SystemsKoen HindriksProgramming Multi-Agent SystemsProcessing PerceptsTypes of percepts:send oncesend alwayssend on changesend on change with negation

How to handle these different type of percepts?Koen HindriksProgramming Multi-Agent SystemsKoen HindriksProgramming Multi-Agent SystemsPattern for Send AlwaysLast Lecture:Rule 1: If the agentperceives block X is on top of block Y, anddoes not believe that X is on top of YThen insert on(X,Y)into the belief base.Rule 2: If the agentbelieves that X is on top of Y, anddoes not perceive block X is on top of block YThen remove on(X,Y)from the belief base.

event module { program{ % assumes full observability. forall bel(percept(on(X,Y)), not(on(X,Y))) do insert(on(X,Y)). forall bel(on(X,Y), not(percept(on(X,Y)))) do delete(on(X,Y)). }}Koen HindriksProgramming Multi-Agent SystemsKoen HindriksProgramming Multi-Agent SystemsPattern for Send OnceSend once percepts are sent only once when the environment just has been launched.

Use the init module to insert the beliefs you want to use in the agents belief base.

init module { program{ forall bel(percept(place(X)) do insert(place(X)). }}Koen HindriksProgramming Multi-Agent SystemsKoen HindriksProgramming Multi-Agent SystemsPattern for Send on ChangeSend on change percepts are sent only when something a feature in the environment has changed.

Rule: remove old belief and insert the new percept.

Put rule in event module.NB: Use forall rules for processing percepts.event module { program{ forall bel(state(Old), percept(state(New))do delete(state(Old) + insert(state(New)). }}Koen HindriksProgramming Multi-Agent SystemsKoen HindriksProgramming Multi-Agent SystemsSend on Change Perceptsend on change percepts are sent once when change occurs:

Note that pattern for send always percepts does not work for send on change due to second rule in that pattern.event module { % send always pattern program{ forall bel(on(X,Y), not(percept(on(X,Y)))) do delete(on(X,Y)). }}State 1State 2State 3State 4State 5at(RoomA1)at(FrontA1)- Koen HindriksProgramming Multi-Agent SystemsKoen HindriksProgramming Multi-Agent SystemsSend on Change with NegationSend on change with negation percepts:Positive fact sent once when it becomes true in environment .Negative fact sent once when it becomes false in environment.

Rule: insert positive and remove negative facts.

Put rule in event module.

event module { program{ forall bel(percept(in(RoomID)) do insert(in(RoomID)). forall bel(percept(not(in(RoomID))) do delete(in(RoomID)). ... }}Koen HindriksProgramming Multi-Agent SystemsKoen HindriksProgramming Multi-Agent SystemsCombining InformationIn BW4T it is most important to remember in which place a colored block can be found.Idea: combine at location with color percept using a new block predicate.

NB: make sure by earlier rule that at belief is correct.event module { program{ forall bel( percept(color(BlockID, ColorID)), at(PlaceID) )do insert( block(BlockID, ColorID, PlaceID) ). forall bel( at(PlaceID), block(BlockID, ColorID, PlaceID), percept(not(color(BlockID, ColorID))) )do delete( block(BlockID, ColorID, PlaceID) ). }}Koen HindriksProgramming Multi-Agent SystemsKoen HindriksProgramming Multi-Agent SystemsModules

Koen HindriksProgramming Multi-Agent SystemsKoen HindriksProgramming Multi-Agent SystemsDefined Module ComponentsUser-defined module is similar to any other module.

Even though knowledge may be specified within a module, knowledge is global. I.e. all knowledge is put in a global knowledge base.

Goals, macros, rules and actions specified within a module are local: They can only be used within that module.

init module{ ...} main module{ program{

}}

event module{ ... }

%%% YOUR OWN MODULES GO HERE %%%%%% CAN ALSO IMPORT MODULES %%%

module moduleName { % may have: [] knowledg{ } % optional goals{ } % optional program{ } % OBLIGATORY actionspec{ } % optional}

Koen HindriksProgramming Multi-Agent SystemsKoen HindriksProgramming Multi-Agent SystemsCurrently, no submodules; working on that. Also working on making agent = module hold.14Tower Env: Agent Design% moving X on top of Y is a constructive move if that move results in X being% in position.#define constructiveMove(X, Y) a-goal( tower([X, Y | T]) ), bel( tower([Y | T]), clear(Y), (clear(X) ; holding(X)) ) .main module{ program{ % pick up a block if you can and want to. if a-goal( holding(X) ) then pickup(X) . % put a block you're holding down, ideally where you want it, but otherwise put it on the table. if bel( holding(X) ) then { if constructiveMove(X,Y) then putdown(X, Y) . if true then putdown(X, table) . }

% otherwise, there is nothing to do, so we can move the gripper to the top left corner. % no need to check whether we're holding a block because of linear order. if true then nil . }}

Design rule: Try to only use action rules that select environment actions in main module.Use main module to define a strategy for handling the environment as above. Koen HindriksProgramming Multi-Agent SystemsKoen HindriksProgramming Multi-Agent SystemsTower Env: Agent Design main module{ program{ if a-goal( holding(X) ) then pickup(X) . if bel( holding(X) ) then { if constructiveMove(X,Y) then putdown(X, Y) . if true then putdown(X, table) . } if true then nil . } } event module{ program{ % process percepts from Tower World environment. rules below assume full observability. forall bel( block(X), not(percept(block(X))) ) do delete( block(X) ) . forall bel( percept(block(X)), not(block(X)) ) do insert( block(X) ) . forall bel( holding(X), not(percept(holding(X))) ) do delete( holding(X) ) . forall bel( percept(holding(X)), not(holding(X)) ) do insert( holding(X) ) . forall bel( on(X,Y), not(percept(on(X,Y))) ) do delete( on(X,Y) ) . forall bel( percept(on(X,Y)), not(on(X,Y)) ) do insert( on(X,Y) ) . }

Process percepts first in event module. Always use most up-to-date information.Koen HindriksProgramming Multi-Agent SystemsKoen HindriksProgramming Multi-Agent SystemsTower Env: Agent Design event module{ program{ % a block is *in position* if it achieves a goal. #define inPosition(X) goal-a( tower([X|T]) ) . % GOAL MANAGEMENT % check for reasons to DROP a goal FIRST. if goal( holding(X) ) then {% first reason: cannot pick up block X because it's not clear.if bel( not(clear(X)) ) then drop( holding(X) ) .% second reason: cannot pick up block X because now holding other block!if bel( holding(_) ) then drop( holding(X) ) .% third reason: block X is already in position, don't touch it.if inPosition( X ) then drop( holding(X) ) .% fourth reason: we can do better by moving another block constructively. listall L