How to define nodes as arrival points and destination points

Viewed 106

This is probably an easy question but I do not get it. In my model I want to create orders based on real data, in this real data there is a start location , I set those as parameter value of the order agent from the database see pictures below:

Database anylogic

Parameters order agent

Now I want at the source block to let the order arrive at the departement, which is exactly the same name as the string parameter of the order, so I did this:

Source part

But it says, cannot convert from string to Inode, so my question is how do I type the syntax that he converts the string name to the node with exactly the same name, because the departement node also is called Departement1 etc.

Thanks in advance!

1 Answers

I would have liked to put this answer as a comment, as I'm still a relative beginner at AnyLogic and I'm sure there are more elegant approaches, but due to lack of reputation, here it it:

You can get the String value of the name of an INode object with INode.getName(), as documented here : https://anylogic.help/api/com/anylogic/engine/markup/INode.html#getName()

After which it would only be a matter of creating a creating a list that contains your nodes, creating a function that iterates through that list and fills out a Map with the name/node pair.

You can then use another function within your agent to assign the corresponding node to a variable inside your agent, and use that to dynamically define their arrival location.

Assuming you've created a Map of name col_nodeNameMatch, you'd then do something like :

for (INode n : col_nodes) {
    if (n.getName().equals(departement)){
         col_nodeNameMatch.put(departement, n);
         break;
    }
}

Followed by the following every time an agent needs to find its arrival node :

v_arrivalNode = col_nodeNameMatch.get(departement);

Thank you Stuart for the much more efficient suggestion of using a Map.

Related