JADE代理使用堆空间太快



我面临的问题是,当运行一组jade代理来解决一个简单的问题时,jvm会在90分钟内耗尽堆空间,这取决于运行的代理的数量。代理的目标是在简化的微电网模型中平衡负载和生成,其中几个代理代表负载和另一代。

加载代理在每次迭代它的行为时用一个新值更新生成器,如下面的代码所示:

    public class House9 extends Agent
    {
      double load  = 50;
      boolean offline = false;
      boolean valid = true;
      int counter = 0;
      double cur = 50;
      int next;
      public void setup()
      {
          addBehaviour(new SimpleBehaviour(this)
          {
             public void action()
             {
                //Adjusting load value
                if(counter == 0)
                {
                  load = (int)load;
                  cur = load;
                  next = 20+(int)(Math.random()*80);
                  //System.out.println("current: " + cur + " next " + next);
                  counter++;
                }
                else if(counter <= 1000)
                {
                  load = load + ((next - cur)/1000);
                  //System.out.println("added " + ((next - cur)/1000) +" to load");
                  counter++;
                }               
                else
                {
                  counter = 0;
                }
                //System.out.println("counter " + counter);
                //Sending result to the generator agent
                ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
                msg.setContent(Double.toString(load));
                msg.addReceiver(new AID("gen", AID.ISLOCALNAME));
                myAgent.send(msg);
           }
           public boolean done()
           {
              return offline;
           }
      });
}

所有负载代理都与此相同,生成代理如下:

    public class Generator extends Agent
    {
       int output = 100; 
       long time = System.currentTimeMillis();
       int iter = 0;

       public void setup()
       {
           System.out.println("Iterations,Time");
           addBehaviour(new CyclicBehaviour(this)
           {
               public void action()
               {
                   //myAgent.setQueueSize(2);
                     int temp = output;
                     ACLMessage reply = receive();
                     if(reply != null)
                     {
                        int load = Integer.parseInt(reply.getContent());
                        //System.out.println("current state--- output: " + output + " load: " + load);
                        if(load > output)
                        {
                           iter = 0;
                           while(load > output)
                           {
                               output = output + 10;
                               iter++;
                           }
                           //System.out.println((System.currentTimeMillis()-time)+ "," + iter );
                        }
                        else if(load < output)
                        {
                            iter = 0;
                            while(load < output)
                            {
                                output = output - 10;
                                iter--;
                            }
                            //System.out.println((System.currentTimeMillis()-time)+ "," + iter );
                        }
                        System.out.println((System.currentTimeMillis()-time)+ "," + iter + "," + load + "," + temp + "," + myAgent.getCurQueueSize());
                  }
              }
         });
      }
 }

从互联网上关于这类事情的其他帖子中,我尝试限制生成代理的消息队列大小,以防它消耗堆空间,以及在每个生成器行为迭代结束时清除jade消息队列。但这些似乎都没有什么不同,我尝试添加更多的堆空间,但这只延迟了一分钟左右的内存不足异常。通过netbeans调用翡翠引擎并启动翡翠gui。

我是多代理编程和使用jade的新手,所以我可以理解可能有更好、更优的方式来运行这种系统,这本身就可以解释这个问题。但我希望在这件事上得到帮助。

谢谢,Calum

House9座席内部的行为没有任何终止条件。每次调度行为时,每个Agent都会发送一条消息。由于您已经覆盖了done方法,它们将继续通过该行为循环发送消息。

你的意思是要发这么多信息吗?消息之间是否应该有某种停顿?您的Generator代理将尝试处理所有这些消息,但它将无法跟上队列中的负载。

相关内容

最新更新