⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newspaperboyagent.java

📁 自己编写的一个Jade 的agent卖报纸小程序 可以自动添加报纸
💻 JAVA
字号:
import jade.core.*;import jade.lang.acl.*;import jade.domain.FIPANames.InteractionProtocol;import jade.proto.SimpleAchieveREResponder;public class NewspaperBoyAgent extends Agent {     class RefillResponder extends SimpleAchieveREResponder{        public RefillResponder(Agent agent){            super(agent,createMessageTemplate(InteractionProtocol.FIPA_REQUEST));        }        /*create a prepareResponse method to respones the messages which the agent receive*/        protected ACLMessage prepareResponse(ACLMessage msg) {            ACLMessage response = msg.createReply();            if(msg.getContent()!=null && msg.getSender().getLocalName().equals("NC")){                System.out.println(myAgent.getLocalName() + ":refill the newspapers to  " +                       msg.getContent());                /*create a new message to response the message which receive from                 the NewspaperControlAgent and inform the ControlAgent he will refill                 the NewspaperMachine*/                ACLMessage msg1 = new ACLMessage(ACLMessage.REQUEST);                AID to1 = new AID();                to1.setLocalName("NC");                msg1.setSender(getAID());                msg1.addReceiver(to1);                msg1.setContent(msg.getContent());                msg1.setProtocol(InteractionProtocol.FIPA_REQUEST);                myAgent.send(msg1);                /*the newspaper boy refills a newspapermachine by sending a ACLMessage                 to the machine*/                ACLMessage msg0 = new ACLMessage(ACLMessage.REQUEST);                AID to0 = new AID();                to0.setLocalName(msg.getContent());                msg0.setSender(getAID());                msg0.addReceiver(to0);                msg0.setContent("boy");                msg0.setProtocol(InteractionProtocol.FIPA_REQUEST);                myAgent.send(msg0);            }            return response;        }    }    protected void setup() {         /*The task object is added to the list of Agent Missions*/        addBehaviour(new RefillResponder(this));     }//}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -