I tried to define constraints in the optimization experiments using root.
( I did this to access top level agent in the constraints expression field).
I have the variable in the top agent
I tried this with functions, parameters, and variables, and all return the same problem
When I use root
in requirements there will be no error
However, I got the following error when using root in the constraints expression:
According to https://anylogic.help/anylogic/experiments/optimization.html#:~:text=A%20constraint%20is%20a%20well,%2C%20e.g.%20parameter1%20%3E%3D%2010.
I should be able to use root in the constraints expression. See the following in the above link:
3 Specify the constraint in the Expression, Type, and Bound cells of the row. In the Expression field the top level agent is available as root.
Then, why is AnyLogic returning this error when root
is used in the constraints expression?
Did you face a similar problem? What do you think is the reason?
To be honest, I think the help is wrong. Constraints are checked BEFORE a model is even created, so access to root
does not make sense. I think they copied the description from the "Requirements". Those are checked after a model is instantiated.
So either use requirements or change your constraints so they do not need access to root
.
This is confirmed by a quick check on the code boxes. For requirements, you can see the lightbulb:
But for constraints, there is no lightbulb:
More lightbulb info here :)