有关多Agent系统的分析.docx_第1页
有关多Agent系统的分析.docx_第2页
有关多Agent系统的分析.docx_第3页
有关多Agent系统的分析.docx_第4页
有关多Agent系统的分析.docx_第5页
已阅读5页,还剩44页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1. 简介在软件工程领域,多代理系统是比较常见的一个研究课题,尤其是在分布式,开放式的网络环境中,多代理系统有很多的优势。所谓多代理系统是指一个由多个自治运行的Agent组成的集体.在开放分布式网络环境中Agent是一个抽象实体.它是自治的可以对自身环境、操作环境和环境变化采取行动,一个系统中一般有多个IntelligentAgent这样的系统就称为多Agent系统.多Agent系统必须找出一种使各个Agent能够协同工作的适当方法。依据这些理论基础建立起来的系统均称为多Agent系统,即MAS.最近研究的东西就是使用多代理的方法,对在线网络拍卖进行欺诈检测。在线拍卖的一个很重要的特点就是其隐蔽性。每个竞标者可以很轻松的拥有很多的拍卖的账号,进行欺诈性投标,进而达到inflate成交价格的目的。当然了,对于欺诈投标有很多策略,想了解更多关于欺诈投标的特点,方法,可以参考我的一片会议论文A real-time Monitoring Framework for Online Auction Frauds,这是跟我的研究生导师Dr. Samira Sadaoui合作发表的一片论文。写该系列博客的主要目的是,关于多代理系统(multi-agent)的实现,资料很少,并且,德国人开发的一个框架Jadex学习起来成本很高,可以提供的API很少,并且都是英文的,理解起来有一定的难度。为了能够尽快完成研究生的毕业设计,也为了能够给大家提供一些学习的资源,就把学习Jadex的过程以及部分资料进行翻译,希望会对国内的相同研究方向的学生,学者有一定的帮助。我所使用的Jadex是Jadex BDI V3,纯Java实现,没有使用XML。后面慢慢会引入一点关于下一篇论文的一些Implementation的核心。2. 大笔一挥,Helloworld首先Jadex的启动问题,相信只要能够懂一点Eclipse使用,并且懂一点英文的都可以做到。按照手册BDI V3 Tutorial上的步骤,就可以直接启动。1. 创建第一个Agent,简单来说就是Helloworld创建Agent的方法很简单,新建一个java文件,然后命名为*BDI.java,注意:命名的结尾要以BDI结束,这表示你的多代理系统能够认识这个文件为BDI Agent,其他的文件命名是不被接受的。接下来,就是键入如下的代码:package a1;import jadex.bdiv3.BDIAgent;import jadex.micro.annotation.Agent;import jadex.micro.annotation.AgentBody;import jadex.micro.annotation.Description;AgentDescription(Hello, Jadex!)public class AucControllerBDI Agent protected BDIAgent agent; AgentBody public void body() System.out.println(Hello, Jadex); 启动Agent,你会看见控制台输出:Hello, Jadex. 说明,一切万事大吉,你已经踏入了,Jadex大门了。恭喜恭喜!3. 使用Plan在Jadex中,Plans起着很重要的作用,因为Plan封装了很多的状态(下面会介绍)。Plan的使用包括两个方面:Plan说明了Plan的元信息已经被定义了,从此以后这个就是Plan了,像是宣誓主权一样。那么,这个Plan就已经定义了很多的属性,比如Plan被激活的条件或者与其他Plan之间的关系。另外一方面就是Plan的body部分,主要包含具体的实现部分。首先,Plan在Multi-Agent中,有三种形式:可以定义成成员方法,内部类,以及类。关于这三种的优劣势,下面会通过代码进行说明。如果Plan来驱动events和goals,我们可以在Plan的头部进行说明,进而使这个Agent知道,这个Plan能够处理的events。这样的话,当这个Agent收到来自于其他的Agent的events时候,就可以创建自己的Plan表或者候选Plan来处理该events。通常情况下,一个Plan会处于等待状态,直到某个状态被执行完毕。这样的话,一个Plan就可以使用Plan API的waitFor()方法。作为一个对象的Plan API能够有两种方法被检索到:1,在Plan的类中,可以使用PlanAPI的标识,声明一个field。然后Jadex的推理引擎就会自动加入这个plan的实例。请注意,Jadex的方法能够被框架随时调用。推理引擎会自动决定哪些值是所期待的,哪些参数是需要设置的。如果没有找到的话,系统就会返回null。3.1 Plan作为一个普通的类一个简单的实例,实现中英文之间的翻译:使用一个Java的类来定义Plan:/ TranslatePlan.javapackage a1;import java.util.HashMap;import java.util.Map;import jadex.bdiv3.annotation.Plan;import jadex.bdiv3.annotation.PlanBody;Planpublic class TranslatePlan protected Map wordTable; public TranslatePlan() this.wordTable = new HashMap(); / add some examples of word pairs wordTable.put(milk, 牛奶); wordTable.put(banana, 香蕉); wordTable.put(school, 学校); wordTable.put(teacher, 老师); wordTable.put(science, 科学); PlanBody public void translateEnglishChinese() / Here we only test one example System.out.println(Translated: teacher to Chinese is + wordTable.get(teacher); 定义Plan很简单,就是要一个类要实现的功能,然后加上对应的annotation,也就是Plan和PlanBody等等。/TranslateEngChBDI.javapackage a1;import jadex.bdiv3.BDIAgent;import jadex.bdiv3.annotation.Body;import jadex.bdiv3.annotation.Plan;import jadex.bdiv3.annotation.Plans;import jadex.micro.annotation.Agent;import jadex.micro.annotation.AgentBody;import jadex.micro.annotation.Description;AgentDescription(Translate English to Chinese)Plans(Plan(body=Body(TranslatePlan.class)public class TranslateEngChBDI Agent protected BDIAgent translateAgent; AgentBody public void body() TranslatePlan transPlan = new TranslatePlan(); translateAgent.adoptPlan(transPlan); 两点需要主要,首先要在Agent类的开始部分加上可能要使用的Plan,就是Plans(Plan(body=Body(TranslatePlan.class)这一行。主要了,agent体中得body方法是在启动JCC的时候,自动被调用的。然后adopt这个Plan。输出:Translated: teacher to Chinese is 老师3.2 Plan作为一个内部类package a1;import java.util.HashMap;import java.util.Map;import jadex.bdiv3.BDIAgent;import jadex.bdiv3.annotation.Plan;import jadex.bdiv3.annotation.PlanBody;import jadex.micro.annotation.Agent;import jadex.micro.annotation.AgentBody;import jadex.micro.annotation.Description;AgentDescription(Translate English to Chinese)/ Plans(Plan(body=Body(TranslatePlan.class)public class TranslateEngChBDI Agent protected BDIAgent translateAgent; Plan public class TranslatePlan protected Map wordTable; public TranslatePlan() this.wordTable = new HashMap(); / add some examples of word pairs wordTable.put(milk, 牛奶); wordTable.put(banana, 香蕉); wordTable.put(school, 学校); wordTable.put(teacher, 老师); wordTable.put(science, 科学); PlanBody public void translateEnglishChinese() / Here we only test one example System.out.println(Translated: teacher to Chinese is + wordTable.get(teacher); AgentBody public void body() TranslatePlan transPlan = new TranslatePlan(); translateAgent.adoptPlan(transPlan); 不太建议把Plan作为内部类进行使用,懂编程的人,都知道为什么。对吧?可能我的经验不足,还是比较讨厌这种使用方法。3.3 Plan作为方法使用package a1;import java.util.HashMap;import java.util.Map;import jadex.bdiv3.BDIAgent;import jadex.bdiv3.annotation.Plan;import jadex.micro.annotation.Agent;import jadex.micro.annotation.AgentBody;import jadex.micro.annotation.AgentCreated;import jadex.micro.annotation.Description;AgentDescription(Translate English to Chinese)/ Plans(Plan(body=Body(TranslatePlan.class)public class TranslateEngChBDI Agent protected BDIAgent translateAgent; protected Map wordTable; AgentCreated public void init() this.wordTable = new HashMap(); / add some examples of word pairs wordTable.put(milk, 牛奶); wordTable.put(banana, 香蕉); wordTable.put(school, 学校); wordTable.put(teacher, 老师); wordTable.put(science, 科学); Plan public void translateEngCh() / Here we only test one example System.out.println(Translated: teacher to Chinese is + wordTable.get(teacher); AgentBody public void body() translateAgent.adoptPlan(translateEngCh); 作为方法使用是,在Agent的body方法中,要使用Plan方法的名字就可以。框架提供了自动检索的方法。3.4 使用其他Plan的方法除了已经学习到的使用方法外,下面介绍其他三个Plan的生命周期方法。1. PlanPassed Plan顺利执行的2. PlanFailed Plan执行失败3. PlanAborted Plan被取消,比如当Plan的上下文变得不可用的时候。演示这个例子的时候,需要用到try-catch块,完成adoptPlan()的调用和等待Plan被执行完成的调用(在调用完成以后,使用get()。get() 是基于future的异步转同步的方法。package a1;import java.util.HashMap;import java.util.Map;import jadex.bdiv3.BDIAgent;import jadex.bdiv3.annotation.Plan;import jadex.bdiv3.annotation.PlanAborted;import jadex.bdiv3.annotation.PlanBody;import jadex.bdiv3.annotation.PlanFailed;import jadex.bdiv3.annotation.PlanPassed;import jadex.micro.annotation.Agent;import jadex.micro.annotation.AgentBody;import jadex.micro.annotation.Description;AgentDescription(Translate English to Chinese)/ Plans(Plan(body=Body(TranslatePlan.class)public class TranslateEngChBDI Agent protected BDIAgent translateAgent; Plan public class TranslateEngChPlan protected Map wordTable; public TranslateEngChPlan() this.wordTable = new HashMap(); / add some examples of word pairs wordTable.put(milk, 牛奶); wordTable.put(banana, 香蕉); wordTable.put(school, 学校); wordTable.put(teacher, 老师); wordTable.put(science, 科学); PlanBody public void translateEngCh() / Here we only test one example System.out.println(Translated: teacher to Chinese is + wordTable.get(teacher); PlanPassed public void passed() System.out.println(Plan finished successfully!); PlanAborted public void aborted() System.out.println(Plan Aborted!); PlanFailed public void failed() System.out.println(Plan failed); AgentBody public void body() try translateAgent.adoptPlan(new TranslateEngChPlan().get(); catch (Exception e) / TODO: handle exception e.printStackTrace(); 上面代码的主要功能就是在Plan执行完成之后,其他的Plan方法会相应的根据Plan来执行。如果是成功执行,就执行PlanPassed,不成功就会根据异常的类型执行相应的方法。3.5 Plan的上下文条件除了Plan的生命周期方法之外,一个Plan,还有其他的先决条件或者上下文条件的方法。先决条件的方法是在Plan执行之前进行evaluated的。作为对比,上下文条件则是必须在Plan执行的时候来evalued。也就是说,如果在Plan执行的某个时候,上下文条件变成false了,那么该计划就不得不被取消了。package a1;import java.util.HashMap;import java.util.Map;import jadex.bdi.runtime.IPlan;import jadex.bdiv3.BDIAgent;import jadex.bdiv3.annotation.Belief;import jadex.bdiv3.annotation.Plan;import jadex.bdiv3.annotation.PlanAPI;import jadex.bdiv3.annotation.PlanAborted;import jadex.bdiv3.annotation.PlanBody;import jadex.bdiv3.annotation.PlanContextCondition;import jadex.bdiv3.annotation.PlanFailed;import jadex.bdiv3.annotation.PlanPassed;import jadex.micro.annotation.Agent;import jadex.micro.annotation.AgentBody;import jadex.micro.annotation.Description;AgentDescription(Translate English to Chinese)/ Plans(Plan(body=Body(TranslatePlan.class)public class TranslateEngChBDI Agent protected BDIAgent translateAgent; Belief protected boolean boolContext = true; Plan public class TranslateEngChPlan protected Map wordTable; PlanAPI protected IPlan plan; PlanContextCondition(beliefs=boolContext) public boolean checkContext() return boolContext; public TranslateEngChPlan() this.wordTable = new HashMap(); / add some examples of word pairs wordTable.put(milk, 牛奶); wordTable.put(banana, 香蕉); wordTable.put(school, 学校); wordTable.put(teacher, 老师); wordTable.put(science, 科学); PlanBody public void translateEngCh() throws InterruptedException / Here we only test one example System.out.println(Plan started:); plan.wait(10000); System.out.println(Plan resumed.); System.out.println(Translated: teacher to Chinese is + wordTable.get(teacher); PlanPassed public void passed() System.out.println(Plan finished successfully!); PlanAborted public void aborted() System.out.println(Plan Aborted!); PlanFailed public void failed() System.out.println(Plan failed); AgentBody public void body() try translateAgent.adoptPlan(new TranslateEngChPlan(); translateAgent.waitForDelay(1000); boolContext = false; System.out.println(); catch (Exception e) / TODO: handle exception e.printStackTrace(); 总结:该篇主要介绍了关于Jadex的Agent的创建方法和Plan的使用。Agent在V3中得使用只需要Java文件就可以,并且,在需要设置为Plan的方法或者类上面添加Plan就可以声明为Plan,在Agent的body中直接调用使用。Plan的定义方法比较多,但是常用的还是每个Plan定义为一个类文件,比较符合常规的系统开发规范。这一篇是学习关于Beliefs的使用。1.Beliefs的简单说明一个Agent的Belief集是表示这个Agent对这个世界环境的了解。跟人类一样,知识积累的越多,越会处理世界上发生事情,换句话来说,就是你的适应性很强。当然,Agent就是Intelligent的,这样研究的东西才会对人类有所贡献。Beliefs不仅能够初始化goals或者Plans,从而使agent执行相应的action,而且能够控制正在执行的行为。Beliefs的表示方法:作为类的一个成员来使用。这是比较常见的一种方式,并且把这个成员作为这个agent的belief。这个成员可以使任意类型的Getter/Setter的方法对。为了满足更多的逻辑要求,增加了这两个pair。未实现的Getter和Setter方法对。一句话点破Belief的功能:就是让Agent知道这些beliefs的改变。换句话来说,就是一个人肯定知道自己知道什么和不知道什么,当你学了点新东西的时候,肯定会提醒自己的大脑。当belief被重新赋值,那么Agent就能够发现这点变化然后做出相应的动作。2. Belief触发Plan和普通的Plan区别就是在Plan之后增加了相应的信息。package a1;import java.util.HashMap;import java.util.Map;import jadex.bdiv3.BDIAgent;import jadex.bdiv3.annotation.Belief;import jadex.bdiv3.annotation.Plan;import jadex.bdiv3.annotation.Trigger;import jadex.micro.annotation.Agent;import jadex.micro.annotation.AgentCreated;import jadex.micro.annotation.Description;AgentDescription(Translate English to Chinese)/ Plans(Plan(body=Body(TranslatePlan.class)public class TranslateEngChBDI Agent protected BDIAgent translateAgent; protected int i = 1; Belief protected Map wordTable; AgentCreated public void init() this.wordTable = new HashMap(); / add some examples of word pairs wordTable.put(milk, 牛奶); wordTable.put(banana, 香蕉); wordTable.put(school, 学校); wordTable.put(teacher, 老师); wordTable.put(science, 科学); Plan(trigger = Trigger(factaddeds = wordTable) public void checkMacPlan() / directly show the automatically triggered. System.out.println(Beliefs have been added + i+ + elements); 这个例子是关于静态的Belief的使用,而有些时候,一个Belief依赖于其他的Beliefs,并且任何时候其他Beliefs的其中一个改变时,都会自动被重新评估。下面就是关于动态Belief的例子。3. 动态的Beliefs开启动态Beliefs的方法比较简单,相当于一个开关,把Dynamic设置成true即可。4. Getter and Setter Belief为了能够进一步动态获取和设定Beliefs,那么需要使用Getter和Setter的方法。当然,这个也不是很确切的说法。用一个简单的例子来说明一下。package a1;import java.text.SimpleDateFormat;import jadex.bdiv3.BDIAgent;import jadex.bdiv3.annotation.Belief;import jadex.bdiv3.annotation.Plan;import jadex.bdiv3.annotation.Trigger;import jadex.micro.annotation.Agent;import jadex.micro.annotation.AgentBody;import jadex.micro.annotation.Description;AgentDescription(Print the time)public class ClockBDI Agent public BDIAgent clockAgent; protected long time; AgentBody public void body() setTime(); protected SimpleDateFormat formatData = new SimpleDateFormat( yyyy.MM.dd HH:mm:ss); Belief public long getTime() return System.currentTimeMillis(); Belief public void setTime() / TODO Auto-generated method stub Plan(trigger = Trigger(factchangeds = time) public void printTime() System.out.println(Now, the time is: + formatData.format(getTime(); 5. 动态更新的Belief动态更新就是说,Belief能够每个一定的时间间隔进行更新。例子是关于打印时间的程序:package a1;import java.text.SimpleDateFormat;import jadex.bdiv3.BDIAgent;import jadex.bdiv3.annotation.Belief;import jadex.bdiv3.annotation.Plan;import jadex.bdiv3.annotation.Trigger;import jadex.micro.annotation.Agent;import jadex.micro.annotation.AgentBody;import jadex.micro.annotation.Description;AgentDescription(Print the time)public class ClockBDI Agent public BDIAgent clockAgent; protected long time; AgentBody public void body() setTime(); protected SimpleDateFormat formatData = new SimpleDateFormat( yyyy.MM.dd HH:mm:ss); Belief public long getTime() return System.currentTimeMillis(); Belief(updaterate=1000) public void setTime() / TODO Auto-generated method stub Plan(trigger = Trigger(factchangeds = time) public void printTime() System.out.println(Now, the time is: + formatData.format(getTime(); 在setTime的函数上,添加updaterate就可以实现动态的更新。总结:对于Belief的使用,方法有两种1,使用类的成员;2,使用getter和setter方法。但是在实际的应用中,第一种方法用的还是会比较多一些。另外关于Belief的使用,就是动态更新检测。但是这种定时的更新检测,还是会消耗一定的资源。具体的应用还是根据自己的使用情况来定。本篇介绍如何实现多代理系统的Goal。1. Goals的简单介绍面向Goal的编程是Agent Programming的一个核心概念。它表示一个Agent把自己托付给一个托管者,尝试所有的可能性来实现目标。Goal的分类为四种。1. achieve goal:比如飞机着落。这个Agent会尝试所有的Plans,直到飞机安全着落。否则是没有机会去尝试其他的可能性,造成飞机坠毁。这种就是Agent必须要到达某种事物的状态。2. query goal:顾名思义就是要查询某个目标,检索某些信息。比如清洁工Agent,无时不刻在寻找垃圾这个目标。3. maintain goal:维持目标。一直使事物能够保持某种状态。比如核反应堆。当反应的状态不满足的时候,就会调用相应的Plan来维持这种状态。4. perform goal:Agent必须要执行的某个动作。比如边境官兵的巡逻,只有执行巡逻这个动作,才能保证边疆的安全。从这些生活中得例子可以看出,多代理的应用在我们的生活中,无处不在。只有从生活中得例子得到启发,才能从理论上更好的改进提升我们的生活空间。那么,Goal的表示方法有几种呢?1. 内部类:如果一个Goal是某个Agent的私有物,比人是不可以也不能用到的话,那么就是用内部类。简单并且方便参数的传递。2. 类:这个Goal没有直接的联系与某个agent。2. 开始使用Goal是用Goal作为内部类。添加Goal标记。package a1;import java.util.HashMap;import java.util.Map;import jadex.bdiv3.BDIAgent;import jadex.bdiv3.annotation.Belief;import jadex.bdiv3.annotation.Goal;import jadex.bdiv3.annotation.Plan;import jadex.bdiv3.annotation.Trigger;import jadex.micro.annotation.Agent;import jadex.micro.annotation.AgentBody;import jadex.micro.annotation.AgentCreated;import jadex.micro.annotation.Description;AgentDescription(Translate English to Chinese)/ Plans(Plan(body=Body(TranslatePlan.class)public class TranslateEngChBDI Agent protected BDIAgent translateAgent; Belief protected Map wordTable; AgentCreated public void init() this.wordTable = new HashMap(); / add some examples of word pairs wordTable.put(milk, 牛奶); wordTable.put(banana, 香蕉); wordTable.put(school, 学校); wordTable.put(teacher, 老师); wordTable

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论