'Compare sets of objects efficiently
I have a program which describes growing pieces of roots in a soil with a daily time step. The soil is made up of a grid of cube-shaped cells and what happens with a root is affected by the cell and vice versa.
The pieces of root are coded as instances of the module ExtendingRootOrgan and the cells are instances of a module named RichSoil. Both are a sub-sub modules of a class (different classes), but also with a non Java construct inbetween the module and the class it (eventually) belongs too.
Each ExtendingRootOrgan is located in a RichSoil cell, but, as it grows, it can move into another cell.
In each time step, properties of RichSoil are updated based on the values of properties of ExtendingRootOrgan, after which the properties of ExtendingRootOrgan are changed based on new values of the properties of RichSoil.
In the current code (which is only partially Java), the program checks all combinations of instances of RichSoil and ExtendingRootOrgan to update the properties.
The problem I have is that this code starts costing a lot of time as the number of instances of ExtendingRootOrgan and RichSoil increases.
My question is: is there an efficient way to link instances of two modules from two separate classes? The knowns are that:
- ExtendingRootOrgans often are linked to the same RichSoil when the code is run again.
- There are always a lot more instances of ExtendingRootOrgan than of RichSoil
- There are only 26 other instances of RichSoil in which ExtendingRootOrgan can be located if it moves out of the current RichSoil.
- The best solution I can up with is to create a duplicate of RichSoil in Java and update it with the properties of RichSoil when needed. I would make this duplicate a list with an index which I can directly calculate from the (known) location of ExtendingRootOrgan. In this case, I only need to check a much smaller number of combinations in the XL code.
I would appreciate any suggestion that allows me to link the two modules in a more efficient way.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
