Error - can not use root. in the constraints expression - AnyLogic - anylogic

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 :)

Related

Timescale missing on the module as other modules have it Verilator error

I am trying to add an accelerator to the rocket chip framework through the MMIO peripheral. I went through the GCD example and was able to build the basic GCD code. I then replaced the GCD with an accelerator which has it's own Config, Parameters and Field information. Now when I try to pass this information to the rocket chip there is a name clash with the freechips.rocketchip.config.{Parameters, Field, Config}. I tried specifying the whole path i.e; accelerator.util.conig.Parameters to distinguish it from freechips.rocketchip.config.Parameters but it still gave me the same error. When I remove my accelerator configs and parameters and pass simple hand made parameters the build is successful, however, when I add my config I get %Error-TIMESCALEMOD and this error is in the generated file which I am not modifying. I tried a work around by altering my verilator options but that goes down a rabbit hole of errors. I have narrowed down the problem to the fact that this is being caused because I am using two different configs both of which have their own Config.scala file shown here Is there a way to fix this problem? I have attached the error with this question.
The problem was with a blackbox, not sure why it was giving me that error, but yes we can mix two different configs having different util.config files. We just have to specify them explicitly.

AnyLogic (systems dynamics) Square root function

im simply trying to find the square root of a dynamic (changing) variable but no matter how many different ways i feed it into the equation bar i get a syntax error or "the method SQRT(double) is undefined for the type main". im having this issue with a flow.
I think the problem is more fundamental than your use of sqrt, which works fine in a simple model mimicking what you say you've done (dynamic variable taking value from a stock and then a flow taking the sqrt of that dynamic variable); see screenshot below. I think you need to provide more detail (e.g., screenshots of your model) and/or try to reproduce the problem in a simple-as-possible model.
with IV=0
What does that mean?
"the method SQRT(double) is undefined for the type main"
Method names are case sensitive. You should use sqrt() not SQRT()
PS: If this works, ignore my other answer
**EDIT: see my other answer first, it is more likely your problem
"the method SQRT(double) is undefined for the type main"
For some reason it is looking in "main" for a square root method. The only way I could imagine this happening is if you used self.sqrt() instead of sqrt()
If sqrt() on its own doesn't fix it you could specify the actual location of the method
Math.sqrt()
Or to be even more explicit;
java.lang.Math.sqrt()

Simulink & Masks: Dynamic access to parameters "evaluate" and "tunable"

First of all, matlab version is 2011b, so I cannot use Simulink.MaskParameters class.
I have one simulink mask and some parameters inside. I need to determine in my function for each parameter if it is "evaluable" or "tunable".
Those two things are two checkboxes in the mask parameters dialog which you can select for any parameter.
For "tunable", there's the MaskTunableValues property. For "enable", there's the "MaskEnables" property.
Do you know if there's a way to programmatically access the same property but for "evaluate" ?
Thanks
#Phil Goddard's answer shows you how to find the parameter. To complete the answer, the actual parameter is MaskVariables. Evaluate flag is embedded into the MaskVariables string. It is not straightforward to modify this. For example for two parameters MaskVariables string contains something like this:
"a=#1;b=&2;"
In this string the # sign indicates evaluation. Based on that, parameter a is evaluated and parameter b is not. If you want to change the evaluate flag, you need to set this string for MaskVariables parameter exactly how it was except for # or & signs.
For more information see R2011b documentation for mask parameters at https://www.mathworks.com/help/releases/R2011b/toolbox/simulink/slref/f23-18517.html. Towards the bottom of the page there is more detail about MaskVariables parameter.
You're using too old a release for most people to be able to give you an exact solution, however, I'm sure (from memory) that this parameter is available.
If you click on the mask to select the block, then go to the MATLAB command line and type
get_param(gcb,'ObjectParameters')
you'll get a list of all the block properties. (You may already know that since you're aware of MaskTunableValues and MaskEnables.) Near the bottom of that list are all of the properties related to the mask.
Now manually look at each/all of those properties, e.g.
get_param(gcb,'MaskTunableValues')
and you'll find that one of them is a structure that contains the information that you're looking for. (You may need to dig down into the structure to find the specific info.)
Answer for versions > 2011b (tested on 2014b):
Ok found it, actually the matlab documentation is REALLY unclear regarding the Simulink.MaskParameter class and here is how it works:
First, get the Mask class from your block:
mask = Simulink.Mask.get(gcb)
The Mask class is a structure containing all mask parameters:
parameters = mask.Parameters(:)
parameters is a (array of) Simulink.MaskParameter object which will contains all the necessary properties, including Evaluate.

Access to an object's fields is only permitted within its methods in matlab

I need to modify the cluster methods of the phytree object in matlab. After modifying it, I change the name to cluster_second. Then, when I run the function, I got the error saying that
Access to an object's fields is only permitted within its methods.
I understand what is going on here. Because I need to use tr.tree, and it is a field of the phytree object which can only be accessed within that phytree object's method. Obviously, cluster_second does not satisfy that condition. Can anyone help me out with this? Many thanks.
If you want your cluster_second method to be a method of phytree, put the file cluster_second.m into the directory \toolbox\bioinfo\bioinfo\#phytree. All phytree objects will then have an additional method cluster_second (as well as the original cluster method).
It's possible that you may also be able to put it into a different folder named #phytree, as long this #phytree folder is on your path. I'm afraid I don't have Bioinformatics Toolbox on my current machine to test that, though.

Loading Variable-Based Parameters in Behavior Search

I am using Behavior Search to calibrate my NetLogo model for 20 different hospital units. I am using global variables to set the min and max for several sliders in my model, but I think this is causing an error in Behavior Search when I attempt to load the parameter values from the model. However, I don't want to manually enter these parameter ranges manually each time I use Behavior Search.
Is there a way to get around this error? Is there a way to set the min and max for a specific slider to a constant, rather than using global variables?
Thanks for your help!
BehaviorSearch developer here -- if I'm understanding your question correctly, your NetLogo model has a slider which has a min/max constraint that is not set to a constant, but is instead set to a global variable (in the slider settings, accessed from the NetLogo interface).
When I choose such a model using the BehaviorSearch GUI, and then click the "Load parameter ranges from model interface" button, then I get the value of 0 for that constraint. (I don't see any error message -- just the value 0 (if you're getting an error message instead, then I may not be understanding your situation correctly, and perhaps you could post exactly what error message you're seeing?)
This will be true even if you are setting the slider min/max to a global value in the special STARTUP procedure (see: http://ccl.northwestern.edu/netlogo/docs/dict/startup.html), because STARTUP is only run when a model loads in the NetLogo GUI, and not when a model is loaded in headless NetLogo.
Thus, unfortunately, I think the answer to your question is: "no, there isn't a way to get BehaviorSearch to load the parameter ranges from global variables within the model".
Some possible work-arounds:
BehaviorSearch is open-source -- some changes could be made to it -- i.e., maybe adding in a call to "startup" whenever BehaviorSearch GUI loads the parameter ranges would be sufficient for you.
If you're only doing a few searches, I don't see why manually editing the parameter ranges would be particularly onerous. However, if you're generating a lot of different searches with this model, then I can see how it might be an issue. The .bsearch files are just XML text files, so you might consider generating them without the BehaviorSearch GUI, e.g. using a scripting language.