I have an agent type Household, and its group households. They have a string variable identity, which will be dynamically assigned value at runtime, such as "Volunteer", "Initiator", and more.
Now I want to establish some special connections between the households. One of them is neibNet, which makes volunteers look for their nearest initiator. Then I want to read the number of neibNet connections existing on each initiator.
When I run the model, the problem is like [this](https://i.stack.imgur.com/HI8eO.png). The connections have been applied successfully, the number of neibNet connections of each Initiator has been recorded and displayed, but I cannot reference this number to calculate raisedDonation.
I have tried following methods to get the value, they all returned 0:
// test 1, told by AI that it's the overall neibNet links rather than one agent
raisedDonation = this.neibNet.getConnectionsNumber() + 1;
// test 2
raisedDonation = this.neibNet.getConnections().size() +1;
// test 3
raisedDonation = this.neibNet.size() + 1;
// test 4
raisedDonation = 1;
for (int i = 0; i < main.households.size(); i++) {
if (main.households.get(i).identity == "Volunteer") {
int ii = i;
Household raised = findFirst(main.households, h -> h.householdid == ii);
if (raised.neibNet.isConnectedTo(this) == true) raisedDonation++;
}
}
I solved my problem. The function
neibNet.getConnections().size()or other similar methods CAN be used to read the number of special connections linking to a specific agent. However, I read the value while forming the connections, so the function has no time to catch a value. It is my logic fault.