Agent decision making in tyrant emulation using java uses a lot of memory

I am building a model with multiple autonomous agents. They make decisions about which object to choose within their immediate environment or "neighborhood". They do this by rebuilding objects, adding them to the list, sorting the list based on preference, and choosing the best one each iteration . The decision determines their movement.

Unfortunately, when the number of agents gets too high, the program slows down massively.

I am using the compare method (below) which is relatively short but uses a lot of memory to compare objects. I'm wondering if there are any other methods that you guys are aware of that could 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();
    }
}

      

+3


source to share


1 answer


Some points that might be helpful (note that I have not used repast-simphony

, so some of them may already be implemented using this framework):

  • Measuring - comparing / sorting bottleneck? You said that it uses a lot of memory - it doesn't automatically make the program run slower (can there be problems with OX? Experiment with VM arguments). And, of course, before measuring - warming up the JVM (so that the JIT can catch up with the normal working conditions for your code, etc.). Find out what's going on with jvisualvm

    .

  • I don't know what kind of objects you are passing to the method append

    , but consider that you can return faster than comparing objects like the ones you are doing now. Try to use the knowledge of your specific domain model.

  • You said that agents "fetch objects, add them to the list" and sort. It might be useful to keep an already sorted list of neighbors, and if something changes, maybe (that's a guess) there will be a slight change in the list - so it's almost completely sorted. Use a sorting algorithm that processes "nearly sorted list" lists very quickly and compares the results with the default sorting algorithm. This, of course, depends on how often your neighbor model changes. If your model doesn't change (I suppose it TYPE

    doesn't change) then the sorting problem won't exist.

  • Consider using plain Java code for CompareToBuilder

    - if you have millions of objects, object creation can be a lot of overhead (if it's on a critical path / bottleneck).

  • Are you using concurrency? Perhaps it will speed up if you run your algorithm in parallel.



Many of the other optimizations depend on your specific object structure and relationships. For example. you have Tree

as a type in generics - perhaps this tree is not scored, perhaps you could use AVL

, Heap

or change LinkedList

to ArrayList

, etc. Experiment and Measurement.

Hope this helps a little.

+3


source







All Articles