anylogic

Set Quantity Expected at Assembler Block with Variable


I would like to update the fields "quantity 1", "quantity 2", "quantity 3", etc. in my assembly block with a variable. I have set up a user control screen in the simulation window and let the user control a slider to change each quantity.

I am doing this by:

  1. Setting a parameter in Main equal to a variable in Simulation
  2. Using a function in Main to update several variables based on the value of the parameter
  3. Setting the "quantity" fields to the variable values.

When I run the analysis, the variables do successfully update, but the assembler doesn't accept any agents. I believe the issue is that the variables initial value of 0 is getting initialized before the users selection takes effect.

How can I update quantities in an assembler based on user slider controls?


Solution

  • I believe the issue is that the variables initial value of 0 is getting initialized before the users selection takes effect.

    Correct. You can verify this by understanding the little icons next to properties. For your assembler, the "=" sign tells you: "I am set at the start and do not check for changes myself ever again":

    assembler in AnyLogic

    Also see this help article.

    How can I update quantities in an assembler based on user slider controls?

    Use code-complete on the block to find "updater" functions. In this case: funcs to use

    It is your responsibility to call these when the actual qty values would change, so you can easily do that in your function that does the computations anyway. You can then also discard those variables, you do not need them anymore.