Resources, operations and buffers are connected with each other with loads and flows. An operation has a collection of loads and flows. Each flow establishes a connection with a buffer, and each load a connection with a resources. The entities thus constitute a network graph. In this network context we define clusters and level as follows.
A cluster is a set of connected entities. When a network path across loads and flows exists between 2 entities they belong to the same cluster. When no such path exists they are effectively situated in independent sub-networks and clusters.
Internally, each cluster is represented by a number.
Clusters allow us to group entities and are very useful in multithreaded environment: since the clusters are completely independent we can use different threads to solve each cluster as a separate subproblem.
Material flows in the network have a direction. This creates a sense of direction in our network which is expressed by the level concept.
An operation consumes and produces material, as defined by the flow entities (aka bill of material or recipe).
In this context the level is a number that is defined such that the level of a consumed material buffer is always higher than the level of the produced material buffer. The demand is normally (but not exclusively!) placed on the material buffers with level 0, and the level number increases as we recurse through the different levels in the bill of material.
Raw materials have the highest level number.
The level and cluster number are helpful for the various solver algorithms. They provide valuable information about the structure of the network.

The algorithm used to compute the level and cluster information is based on a walk through the network: We select an unmarked operation and recurse through the loads and flows to find all connected entities, updating the cluster and level information as we progress.
For efficiency, the algorithm is implemented as a lazy function, i.e. the information is only computed when the user is retrieving the value of a level or cluster field. The algorithm is not incremental (yet), but computes the information for the complete network in a single pass: a change to a single entity will trigger re-computation of all level and cluster information for all entities.
Note: An updated algorithm has been designed for the cluster computation. Its advantage compared to the current implementation is a much better effiency in the case of frequent model updates. The computation will be completely incremental, compared to the single pass for all entities in the current implementation.
The detailed flow of the algorithm is as follows:
// Initialisation
Lock the function
Reset the level and cluster to -1 on all resources, operations and buffers
Reset the total number of clusters
// Main loop
Loop through all operations
-
Push the operation on the stack, level -1Set the cluster of the operation
// Catch buffers missed by the main loop
Loop through all buffers which don’t have any flow at all.
// Catch resources missed by the main loop
Loop through all resources which don’t have any load at all.
// Finalization
Unlock the function