I move a batch of agents to a node, where they are unbatched. Once the unbatched agents occupy this node, the node is not available for other batches of agents to move there, so I remove that node from a collection of available nodes, AvailableNodes.(There are about 50 nodes total). Each unbatched agent has a parameter that is the node it has been moved to. The question is how to add back a node to AvailableNodes once all unbatched agents have been moved from that node. Do I have a variable associated with each node that I increment or decrement as agents enter/exit the node? If so, how do I associate a unique variable with a node? Or is there a better way?
1 Answers
Oh you are walking in muddy waters with bad practices... your nodes should belong to a resourcepool, meaning that instead of a node, you should have an agent with a node in it... That way you don't need any collection at all.
Another option is to create a small class that will have the node and the availability... and maybe the number of agents currently present in that node. Just create a new class, and add these 3 variables. Then on the start of the model you add instances of that class to the collection availableNodes and you can then just do theClass.numberOfAgents+=1 or -=1 depending on wether agents are being added to the node. To find an available agent you can then do TheClass x=findFirst(availableNodes, a->a.numberOfAgents==0); and then you can send your agents to x.node;
There is also a possibility continuing to do what you are doing... but I won't even go there because it will be a mess.