Reputation: 19
I have 5 agents - bus, transformer , generator, load , line. I have a requirement where i need dynamically connect the above agents.
I have written the following code, where i am trying to connect for example bus [2] and generator[5]. The connections are not random but based on a circuit, which i am dynamically reading through a text file.
for (int l = 0; l < busList.size(); l++) {
for (int k = 0; k < generatorList.size(); k++) {
if (generatorList.get(k).getBusNumber()==busList.get(l).getBusNumber()) {
busList.get(l).getBusID().connectTo(generatorList.get(k).getGenID());
}
}
}
Can someone help with the connection part. I cannot have a generic list because I need the agent attributes for other functionalities as well.
Upvotes: 0
Views: 516
Reputation: 1728
Assuming that busList and generatorList are collections containing entries of type Bus and Generator respectively, which both are derived of type Agent, the following code should work for connecting:
busList.get(l).connectTo(generatorList.get(k));
I don't know why you used getBusID and getGenID which I assume return an integer. If they really return a Bus or a Generator object it should work as you already wrote. In this case you would need to provide us the error message or the exact problem that you have.
Upvotes: 1