我面临的问题是,当运行一组玉代理解决一个简单问题时,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启动jade gui。
我是多代理编程和使用玉的新手,所以我可以理解运行这种系统可能有更好、更优化的方法,这本身就可以解释问题。但希望能在这件事上得到一些帮助。
谢谢,卡鲁姆