Reputation: 1
I have an issue concerning the agent location in one of my Anylogic simulations. I want to set a condition that defines which path an agent will take in the visualization of my simulation.
In a delay block in the main agent I wrote
if(agent.previousStation==1){
path01;
}
else {
path21;
}
into the agent location field.
When building the model anylogic presents me with these errors:
Description: Syntax error, insert "VariableDeclarators" to complete LocalVariableDeclaration. Location: FVMMerkmale/shopfloor/wegzeit1 - Delay
and
Description: Syntax error on token(s), misplaced construct(s). Location: FVMMerkmale/shopfloor - Agent Type
writing "return" in front of the path does not help either and gives different errors:
Description: Syntax error on token(s), misplaced construct(s). Location: FVMMerkmale/shopfloor - Agent Type
Description: path21 cannot be resolved to a variable. Location: FVMMerkmale/shopfloor/wegzeit1 - Delay
Description: Void methods cannot return a value. Location: FVMMerkmale/shopfloor/wegzeit1 - Delay
Description: agent cannot be resolved to a variable. Location: FVMMerkmale/shopfloor/wegzeit1 - Delay
The path-elements are in the main agent. Using the value editor to choose the correct path will work.
According to the anylogic help, it is possible to bind the agent location to a condition:
Otherwise, if you want to set different nodes for agents here, you can write a Java expression that will return different nodes depending on some conditions. https://help.anylogic.com/index.jsp?topic=%2Fcom.anylogic.help%2Fhtml%2Fagentbased%2FContinuous_Layouts.html
How do I write a condition that defines a path or node as the agent location?
Upvotes: 0
Views: 1259
Reputation: 9421
This is the correct code, which is the compressed version of the if statement using ? and : operators (without using semicollon)
agent.previousStation==1 ? path01 : path21
More info about these operators here: http://www.cafeaulait.org/course/week2/43.html
Upvotes: 0