I am building a model with a number of autonomous agents. They make decisions on which object to choose within their immediate environment or "neighborhood". They do this retrieving the objects, add them to a list, sort the list based on preferences, and choose the top choice every iteration. The decision determines their movement.
Unfortunately, once the population of agents becomes too high, the program slows down massively.
I use a compare method (below), which is relatively short, but uses a lot of memory, to compare the objects. I am wondering if there are any other methods you guys know of that might be more computationally efficient?
class ObjectComparator implements Comparator <Tree> {
@Override
public int compare(Object object1, Object object2) {
return new CompareToBuilder()
.append(object1.getTYPE(), object2.getTYPE())
.append(object2.getDBH(), object1.getDBH())
.append(object1.getDistanceFrom(), object2.getDistanceFrom())
.append(object2.isIdeal(), tree1.isIdeal()).toComparison();
}
}