




已阅读5页,还剩9页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
4.2.1 开发工具及理念开源软件Jason的开发语言主要是Java和AgentSpeak。Jason对开发多Agent系统提供了很好的支持,可以很方便的创建Agent、协调Agent之间的相互通讯、Agent认知环境与环境相互作用从而改变环境等。4.2.1.1 Agent构建在AgentSpeak中,一个Agent是由一系列的bs(Bliefs)信念(Agent的初始化信念集)和一系列ps(Plans)计划(Agent的计划库)。at对应的P表示的是定义符号(定义一个信念),而f对应的A是一个行为符号(表示一个行为)。注意bs中的at应该是“实”的,即信念是实的,如变量在这里是不允许的。在AgentSpeak中,“实”的用小写字母,而虚的,如变量,用大写字母表示。AgentSpeak中的计划plan表示agent在环境中能执行的基本动作,由上图的p来表示,p所指向的te是触发事件(表示了计划的目的),ct是计划执行的条件,h是一组行为、意图或信念更新序列;te:ct为计划中的头部,h则是它的体。那么Agent中的一组计划是有ps所指向的计划列表。每一个规划的头部都有一个ct,它是规划能否正常执行的条件。ct必须是由Agent信念对规划是否可行的逻辑推理结果。ct为true,或是条件表达式,依据当前信念判断条件是否为真。触发事件te可以是增加或减少Agent的信念集(分别用+at,-at来表示),或者是增加或减少一个意图(分别由+g和-g来表示)。由原子行为,意图和信念更新组成的h是计划的体。行为A由行为标志符和参量表示。是Agent可执行的原子行为。意图g由前缀和标志符表示,可以是achievement goal(前缀用! 表示,) 或 test goals(前缀用? 表示)。achievement goal在实际应用中可产生子计划的执行(以+!g为标志的计划)。而test goals是查询信念库是否有相应的信念,如有,则从信念库中取出相应的信念;如果没有,则产生事件+?g,如果有相匹配的计划,则执行,如无,则fail,因为no applicable plans,此时仍然可能试执行-?g计划,如果依然没有该计划,则丢弃此意图并告知用户。Test GoalsTest goals are normally used to retrieve information from the belief base, or to check if something we expected is indeed believed by the agent, during the execution of a plan body. One may wonder why we do not use the context of the plan to get all the necessary information before the agent starts on its course of action. Conceptually, the context should be used only to determine if the plan is applicable or not (i.e. whether the course of action has a chance of succeeding), and practically we may need to get the latest information which might only be available, or indeed might be more recently updated, when it is really necessary.For example, if the agent is guaranteed to have some information about a targets coordinates, which are constantly updated, and only needed before a last action in the course of action defined by the plan body, then it would make more sense to use ?coords(Target, X, Y); just before that action than to include coords(Target, X, Y) in the context. In this particular example of test goal, presumably the variable Target would already be bound (by previous formula in the body) with the particular target in question, and assuming X and Y were free (i.e. not bound yet), any use of those variables after the test goal will be referring to the particular coordinates as believed at the time the test goal is executed of the target referred to by Target.-! g 事件和 -? g 事件这些在语义中还没有被形式化。-! g 事件或 -? g 事件仅仅在相应的 +!g 或 +?g 计划失败(如行为失败或者某个子意图没有相应的可实施的计划)时产生。如果没有相应的计划与-! g 事件或 -? g 事件匹配,则丢弃该意图,并发出警告。最后,+at和-at(在规划的体中)代表着信念集更新的操作,分别表示增加at和移除at。busy_until(john,autumn).例1 AgentSpeak 中的Blief 例2 AgentSpeak 中的Plan当环境宣布一个新的招标时,Agent ag1 总是投6。Agent ag2投4,除非他已经同意和ag3联手(这时他投0) 。当ag2 收到ag3的联手信息时,一个信念alliance(ag3,ag2) 添加到 ag2的信念库中(此时要用到默认的信任功能ally(ag3)。这是最后一个计划的触发事件,该计划通知ag3 关于ag2投的数,并发送确认消息,表示ag2 同意与ag3联手。句法Agent ( init_bels | init_goals )* plansinit_bels beliefs rulesbeliefs ( literal . )*rules(规则) ( literal :- log_expr .)*init_goals(初始意图) ( ! literal . )*plans ( plan )*plan atomic_formula triggering_event : context - body .triggering_event ( + | - ) ! | ? literalliteral(文字) atomic_formulacontext(条件) log_expr | truelog_expr(逻辑表达式) simple_log_expr| not log_expr| log_expr & log_expr| log_expr | log_expr| ( log_expr )simple_log_expr ( literal | rel_expr | )body body_formula ( ; body_forumula )*| truebody_formula ( ! | ? | + | - | -+ ) literal| atomic_formula| | rel_expratomic_formula ( | ) ( list_of_terms ) list_of_terms list_of_terms term ( , term )*term(术语) literal| list| arithm_expr| | list term ( , term )* | ( list | ) rel_expr rel_term (|=|=|=|=) rel_termrel_term (literal|arithm_expr)arithm_expr arithm_term ( + | - ) arithm_expr arithm_term arithm_factor ( * | / | div | mod ) arithm_term arithm_factor arithm_simple * arithm_factor arithm_simple | | - arithm_simple| ( arithm_expr )p(t1,. . .,tn), 这里前缀 表示强否定。默认的否定用在计划的条件中,用加前缀not表示。4.2.1.2构建多Agent系统句法mas MAS infrastructure environment exec_control agentsInfrastructure(架构) infrastructure : (ID表明了是集中式或分布式SACI)Environment(环境) environment : at (一种特殊的java类,一般用于编制环境)exec_control executionControl : at (允许用户定义管理agent执行)agents agents : ( agent )+agent filename options agentArchClass beliefBaseClass agentClass # at (在分布式架构中需要用到);filename options option ( , option )* option events = ( discard | requeue | retrieve )| intBels = ( sameFocus | newFocus )| nrcbp = | verbose = | = ( | | )Discard:当外部事件没有与之相对应的可实施的计划时,丢弃。Requeue:插回事件队列的末尾。Retrieve:即使计划为空,也调用用户定义的选择项功能。这允许agents向其它可能知道怎么做的agents要求实施计划。intBels: 有sameFocus和 newFocus两个选项。verbose:02,数字越大,表示打印越多此agent的信息,默认是1,此时只打印在环境中的行为与它们间交换的信息。编译和运行定义新的内部行为package ;import jason.asSyntax.*;import jason.asSemantics.*;public class extends DefaultInternalAction public Object execute( TransitionSystem ts, Unifier un,Term args ) throws Exception .定义环境import java.util.*;import jason.asSyntax.*;import jason.environment.*;public class extends Environment / any class members you may needpublic () / 设置初始知觉percept .,所有的agents都会获得该知觉addPercept(Literal.parseLiteral(p(a);/ if you are using open-world.addPercept(Literal.parseLiteral(q(b);/ 如果只是使 agent ag1获得该知觉addPercept(ag1, Literal.parseLiteral(p(a);.public boolean executeAction(String ag, Structure act) . 在这里可以知道是哪个agent(ag)在执行哪一个行为act/ any other methods you may need对于知觉的操作:addPercept(L):addPercept(A,L)removePercept(L):removePercept(A,L):clearPercepts():clearPercepts(A):4.2.3 Agent间的协调机制在多Agent系统中,通信是实现Agent间协作的一种重要的方式和手段。Agent之间进行通信的目的是交换某些信息,因而需要相应的语言以对这些消息进行表示和描述。Agent通信语言是一种用于表达主体间交互信息的描述性语言。它定义了交互信息格式(即语法)和内涵(即语义),支持参与交互的Agent对这些消息进行理解和分析。4.2.3.1 Agent的协作需求分析除了协作意图外,Agent间的协作还设计协作内容的问题,也就是说要针对那些方面开展协作。比如一个Agent请求另一个Agent为它提供某种服务,那么服务的内容是什么?是要提供某项股票的信息,还是要提供某些商品的价格信息。一般地,Agent通讯语言具备以下特点:1) Agent通信语言应该是一种描述性语言(而不是一种过程性语言),能够用于刻画Agent间交互的意图和内容。2) Agent通信语言应该具有严格的语法、语义和语用,能够有效地支持Agent对用Agent通信语言描述的消息进行组装、分析和理解。3) Agent通信语言应独立于具体的Agent实现体系结构和运行平台。4.2.3.2 Agent通信语言在Jason中AgentSpeak提供了一套Agent之间相互通讯的标准库.send:这个动作用来实现Agent之间的通讯。用法如下:.send(receiver,illocutionary force,propositional content),表达式中的receiver表示的是在多Agent系统中配置文件中存在Agent的名字。注意receiver也可以是一个Agent序列,这样可以用来对多个Agent进行广播信息。illocutionary force目前有如下可选项:tell, untell, achieve, unachieve, tellHow, untellHow, askIf, askOne, aslAll,and askHow。tell:s(发送者)通知r(接收者)让其相信所发送的信息内容会实现untell:s(发送者)通知r(接收者)让其相信所发送的信息内容不会实现achieve:s(发送者)请求r(接收者)让其试图去实现信息内容所指的目标。unachieved:s(发送者)请求r(接收者)让其试图去放弃信息内容所指的意图。tellhow:s(发送者)通知r(接收者)选择一个规划。untellhow:s要求r忽视一个规划如:从规划库里删除规划askif:s想要知道在r中信息内容能否能实现askAll:s要得到r对一个问题的所有回答askHow:s要的得到r对一个触发事件的所以规划.broadcast:用法: .broadcast(illocutionary force,propositional_content),表达式的参数和.sent中的一样,不过这里的信息发送是针对群体环境的所有已知的Agent。.createAgent:用来创建一个新的Agent,如.createAgent(bob, bob.asl)第一个参数表示新创建的Agent的名字,第二个字符串参数表示要创建的Agent的代码所在的文件路径。.killAgent:终止参数中所指定的Agent。.print:用来打印系统运行时控制台打印出来的信息。4.3系统功能示例4.3.1单元建模现以Jason自带例子中的采矿Agent为例说明多Agent的创建4.3.1.1 概述此例子由三个采矿Agent(col.asl文件)和一个金矿仓库Agent(builder.asl文件,以下简称仓库Agent)组成,由于三个Agent的初始信念和规划都一样,因此在.mas2j工程文件可以用col #3;来创建三个Agent。Jason中要创建Agent首先的创建以.mas2j为后缀名的工程文件。此工程文件可以定义Agent所驻守的环境(详见4.3.1.2)、创建Agent(详见4.3.1.3)等。图4.3.1.1下面对本例的工程文件作简单说明。L2: 特性设置,比如支持分布式等L3:定义Agent环境,冒号后面指的是所对应环境的文件L6:表示创建3个col.asl类型的Agent(采矿),创建的Agent名分别默认为col1,col2,col3L7:创建一个builder类型的Agent(存矿处)1 package env;2 3 Import jason.environment.*;4 /56 public class planetEnv extends Environment 78 public final int gridSize;9 public final int middle;10 / 1112 public planetEnv() /13 public boolean executeAction(String agent, Term action) / 14 void updatePercepts(String agent) / 15 public PlanetCell getPlanet() return planet; 16 public int geta1() return col1; 17 public int geta2() return col2; 18 public int geta3() return col3; 19 public void stop() super.stop(); gui.dispose();20 4.3.1.2 Agent所驻留的环境环境定义文件基本结构如下: 图4.3.1.2当程序运行时,将初始化Agent所驻留的环境。如上图所示,Agent的驻留环境扩展于jason.environment包下的Environment类(见第6行),初始化时即执行构造函数planetEnv()(见第12行),在此函数中,程序做了初始化用户界面和更新感知调用updatePercepts()(见第14行),updatePercepts中更新的Agent的信念,在此例子中添加了my_pos(x,y).初始化Agent环境后,初始化并启动所定义的Agent。Agent将执行其内部定义的规则。4.3.1.3 采矿Agent的创建1 / Beliefs2 pos(boss,15,15).3 checking_cells.4 resource_needed(1).5 / Plans6 +my_pos(X,Y) 7 : checking_cells & not building_finished8 - !check_for_resources.910 +!check_for_resources11 : resource_needed(R) & found(R)12 - !stop_checking;13 !take(R,boss);14 !continue_mine.151617 +!check_for_resources18 : resource_needed(R) & not found(R)19 - move_to(next_cell).20 +!stop_checking : true21 - ?my_pos(X,Y);22 +pos(back,X,Y);23 -checking_cells.2425 +!take(R,B) : true26 - mine(R);27 !go(B);28 drop(R).29 30 +!continue_mine : true31 - !go(back);32 -pos(back,X,Y);33 +checking_cells;34 !check_for_resources.图4.3.1.3上图2、3、4行都是Agent col的初始信念集,由于前面初始化环境时,col的信念集得到了更新,因此此时col的信念集应该是pos(boss,15,15), checking_cells, resource_needed(1), my_pos(0,0).由于此时的Agent相信my_pos(0,0),因此规划(Plan)my_pos(x,y)执行(第6行)。由于此时col的信念集包含checking_cells、 resource_needed(1)因此,规划中的上下文满足(第7行),执行规划中的体,此处规划中的体只有一个!check_for_resources(第8行)这说明此时的col想完成一个目标(check_for_resources)。此时Event !check_for_resources触发,col选择规划。由于此时col相信resource_needed(R) & not found(R)(第18行),所以此规划被选中。并执行规划体。此时规划体为move_to(next_cell)动作,当col做了此动作,将会对环境产生影响,此时环境文件中的executeAction(String agent, Term action)执行。在此函数中col按规则执行了移动动作且更新感知调用updatePercepts,updatePercepts中更新的Agent的信念此处更新了my_pos(x,y),如此循环.4.3.2 业务流程建模1 public boolean executeAction(String agent, Term action) 2 if(action.equals(nc) 3if(agent.equals(col1) 4 col1X+;5 if (col1X = gridSize) 6col1X = 0;7col1Y+;8 9 if (col1Y = gridSize) 10col1Y = 0;11 1213/以上为col1移动时界面变化规则的代码14/.15if(action.getFunctor().equals(dr) 16rid+;17Literal r1store = Literal.parseLiteral(new_resource(1,+rid+);18Literal r2store = Literal.parseLiteral(new_resource(2,+rid+);19Literal r3store = Literal.parseLiteral(new_resource(3,+rid+);20if(agent.equals(col1) 21 Site s = (Site) planetmiddlemiddle;22 s.addstore(c1res);23 gui.out(Agent A dropped resource +c1res+ at home base);24 switch(c1res) 25case 1:26 addPercept(builder,r1store);27 break;28/29 3031updatePercepts(agent);32 3334 void updatePercepts(String agent) 35if(agent.equals(col1) 36 clearPercepts(col1);37 col1Pos = Literal.parseLiteral(my_pos(+col1X+,+col1Y+);38 addPercept(col1,col1Pos); 图4.3.1.41 +enough(R): true2 - -resource_needed(R);3 +resource_needed(R+1);4 .broadcast(achieve, search_for(R+1).图4.3.1.5 图4.3.1.6采矿Agent与环境和收矿Agent之间的交互见上图4.3.1.6创建环境见图4.3.1.1检测不到金矿向前移动见图4.3.1.3第1719行环境更改,更新col1感知见图4.3.1.4第312行、第3438行环境更改、更新builder感知见图4.3.1.4第1530行通知采下一颜色的矿见图4.3.1.5代码行(用交互图说明场景)From the point of view of an (extended) AgentSpeak interpreter, and agent is a set of beliefs, a set of plans, some user-defined selection functions and trust function (a “socially acceptable” relation for r
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年国家司法考试模拟试卷及答案
- 2025年公共卫生服务体系职业水平考试题及答案
- 2025年山东烟台中考数学试卷真题及答案详解(精校打印)
- 特殊地面保护管理制度
- 特殊普通合伙管理制度
- 特殊疾病学生管理制度
- 特殊饮食医院管理制度
- 特色配电维护管理制度
- 特色餐厅员工管理制度
- 独居酒店日常管理制度
- 《美国太空优先事项框架》解读分析
- 《非物质文化遗产数字化保护 数字资源采集和著录 第9部分:传统技艺》
- 中药鉴定综合技能-矿物类中药鉴定
- 2022-2023学年福建省福州市鼓楼区数学六年级第二学期期末教学质量检测试题含解析
- 语言学概论复习(全)
- 公务员考试理论与实践(山东联盟)知到章节答案智慧树2023年山东财经大学
- 工艺安全检查表
- 洗染行业消费纠纷处理指南
- GB/T 19995.1-2005天然材料体育场地使用要求及检验方法第1部分:足球场地天然草面层
- 全民经纪人协议书
- 护理学课件-铺床法
评论
0/150
提交评论