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

📄 newspapermachine.java

📁 自己编写的一个Jade 的agent卖报纸小程序 可以自动添加报纸
💻 JAVA
字号:
import jade.core.behaviours.*;import jade.core.*;import jade.lang.acl.*;import jade.domain.FIPANames.InteractionProtocol;import jade.proto.SimpleAchieveREResponder;public class NewspaperMachine extends Agent{  private class RequestPerformerBehaviour extends Behaviour {      /*initialize the number of newspapers in each Newspaper Machine*/      private int numberofpaper = 100;      public void action()      {          /*if one machine sells a newspaper then sends a message to the           NewspaperControlMachine and it is uesed to update the information           in the NewspaperControlMachine*/          while (numberofpaper > 0)          {              ACLMessage msg1 = new ACLMessage(ACLMessage.REQUEST);              AID to1 = new AID();              to1.setLocalName("NC");              msg1.setSender(getAID());              msg1.addReceiver(to1);              msg1.setContent("sell one paper");              msg1.setProtocol(InteractionProtocol.FIPA_REQUEST);              myAgent.send(msg1);              numberofpaper--;          }      }      public boolean done()      {          /*ending the loop control */          return numberofpaper == 0;      }  }  /*receive the message from the newspaper boy,if the newspaper boy refills   this machine, then output the machine is full*/class ReceiveMessage extends SimpleAchieveREResponder{    public ReceiveMessage(Agent agent)        {            super(agent,createMessageTemplate(InteractionProtocol.FIPA_REQUEST));        }      protected ACLMessage  prepareResponse(ACLMessage msg)      {          ACLMessage response = msg.createReply();          if(msg.getContent()!=null && msg.getContent().equals("boy"))          {              System.out.println(myAgent.getLocalName()+": NewspaperMachine is full");          }          return response;      }  }/** Creates a new instance of SimpleAgent */  protected void setup()  {      System.out.println("NewspaperMachine "+getLocalName()+" is ready.");      // Add the generic behaviour      addBehaviour(new RequestPerformerBehaviour());      addBehaviour(new ReceiveMessage(this));  }}

⌨️ 快捷键说明

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