Anylogic - New Beginner: Action charts How to return visable the variables? - charts

I am new to anylogic and need to create an actionchart for my master thesis. I know how to set it up and all but I don't know how I can see if the algorithm worked. I tried to use statistics where I choose my used variables but this shows me always the initial value.
This is what I tried to do: Just a first easy algorithm. I have a variable "test" with initial value 0. I have created an action chart with a "for loop" (for i=0;i<10;i++). And in the loop I have placed a code-block with test=test+1;.
And I have placed outside of the loop a return-block where I return "test".
So this action chart should just add 1 for every loop to my variable test. At a result the value should be 10.
When I am running this there are no errors but also no results. The Statistic block only shows the value 0. And now I don't know what I am doing wrong. Is the error in the action chart or at the statistics?
I have searched in Google and read "anylogic in three days" and was searching at the anylogic help.pages... I havn't found a solution so I thought that maybe someone knows what I am doing wrong.

I rebuilt the example you describe, and I am getting an action chart that returns the value 10. I also added a statistics block and associated it with the value of test, and it shows a value of 10. Is it possible that you are just never calling the action chart (analogous to calling a function), therefore it never executes?
In general, I would avoid action charts, as I have found it is just easier to write and maintain code in the AnyLogic functions or Advanced Java area.

Related

Writing custom QGIS function in Python - is there a difference between "feature" and "$currentfeature"

I wrote the following custom qgsfunction:
#qgsfunction(args='auto', group='Custom', referenced_columns=[])
def f1(currentfeature, feature, parent):
return "%s\n%s" % (repr(currentfeature),repr(feature))
In the config for the label I enter the following expression:
f1($currentfeature)
And here is the result:
I always believed that the $currentfeature would hold the same value as the implicitly passed argument feature, but they appear to be separate objects.
Can someone please either
confirm that they should be the same value, or
explain the difference between the two
(I also experience other odd things when executing my own custom functions, and I suspect something is not behaving as it should. Sometimes the addresss of the object changes when I zoom in or out, the address seems to cycle between af few values, and simply takes the next value in the cycle when I do any kind of zoom action. And the reason why I got to experiment with this in the first place is because I did not get the expected/correct attribute values back)

Cyclic Timeout Event Double Looping

I am trying to use a cyclic event countdown to trigger certain functions. However, the problem I am facing is that the event in my model seems to double run at each trigger. An example is shown in the screenshot, where at each trigger, the model time is printed twice instead of once. I tried creating this on a totally new model, but the occurrence cannot be replicated. Is there any settings in AnyLogic that I may have edited that is causing this?
you can't replicate it because that's not the root cause of your problem...
click ctrl+F to find a string on your project
write down "traceln" to find everywhere where you are using the traceln function
It is certain that you are using it somewhere else to print the time...

How to get the dataset for text from Main and run in parameter variation experiment using anylogic?

I am working on an evacuation process project and would like to know if its possible to acquire a dataset for text or a variable from main and run in parameter variation experiment (for 100 runs) while storing/saving it after every iteration. This text keeps changing every time the simulation runs because the number of people able to escape during evacuation is different. An alarm (event) goes off and it triggers another event (event1), this then updates the text that counts the number of people in the building.
stopCounting of type boolean is false and peopleRemaining of type long
getPeopleInsideCount() comes from my function
The code I tried using in After experiment run for parameter variation experiment is
iteration3++;
dataset2.add(iteration3,(double)Long.parseLong(root.text2.getText()));
I understand that this code is unable to read the text from the main as a dataset. I have run the simulation in main and the text updates while also noticing that the peopleRemaining variable follows the number in text. Maybe it is possible to obtain variable in a dataset?
please learn to use the AnyLogic help as well. There, you will learn that a Dataset object only stores numbers. Also, a text object has only text as a String. They are not compatible.
You will want to store your evacuation number in a variable of type Int, name it myEvacNumber. So in addition of showing it in your text, you must manually store it in that variable. Best do that at the end of your evacuation ;-)
Then in your experiment in the "after simulation run" codebox, you can access it and store it into your dataset using
dataset.add(root.myEvacNumber);
Note that this will store the value that was in that variable at the very end of each simulation run!

minisat randomize variable selection is not working on gcloud

I want to get different solution every time I run minisat on the same problem. I can do that with using "rnd-seed" parameter of minisat. It simply randomize the variable selection so each time I can get different solution. Even though this parameter works perfectly on my machine (Ubuntu16) it does not work on gcloud (Google Cloud) running on Ubuntu machine.
I think I am missing a small part but I can not figure out what that is.
Note: I do not want to feed negotation of a solution to minisat to get different solution. I actually need to randomize the variable selection.
Edit: Let me explain why I need randomized solution. I solve lots of SAT problems and usually these SAT problems look like each other a lot. So, if I can not randomized variable selection, I get most of the time very similar solutions which I do not want. Therefore, I actually do not run minisat on the same problem.
Edit-2: #sascha wanted me to explain what I mean by "works" and "not works". When I run a cnf file on my PC, each time I get different solution. However, when I run the same cnf file on gcloud machine, I get always same solution.
The option -rnd-seed doesn't randomize branch variable selection. Rather, it allows you to set a seed for the pseudo-random number generator that Minisat uses.
Variable selection for branching does not involve randomness unless the -rnd-freq option is used. Pass in a floating point value between 0 and 1. 0 means no randomness, 1 means try to use a random variable every branch. The code only makes one attempt to choose a variable randomly, presumably because searching for an unset variable in an arbitrarily large priority queue can get pretty expensive. If that one attempt fails, Minisat branches using the normal priority queue.

A Grid of Clones

My goal is to build a 5x5 grid of images. In the following code, row, col and rowcol were created as variables local to the sprite, and newcol, newrow and cats are global. (By the way, is it possible to tell which variables are local and which are global? It's easy to forget or make mistakes.)
The result is a 5x1 grid only, as seen here.
I am unclear as to the order of execution of these statements. Does when I start as a clone get called before or after add_cat gets called the second time? My tentative conclusion is that it gets called afterwards, yet the clone's global variables seem to contain their values from beforehand instead.
When I attempted to debug it with ask and say and wait commands, the results varied wildly. Adding such pauses in some places fixed the problem completely, resulting in a 5x5 grid. In other places, they caused a 1x5 grid.
The main question is: How to fix this so that it produces a 5x5 grid?
Explanation
Unfortunately, the execution order in Scratch is a little bizarre. Whenever you edit a script (by adding or removing blocks, editing inputs, or dragging the entire script to a new location in the editor), it gets placed at the bottom of the list (so it runs last).
A good way to test this out is to create a blank project with the following scripts:
When you click the green flag, the sprite will either say "script one" or "script two", depending on which runs first. Try clicking and dragging one of the when green flag clicked blocks. The next time you click the green flag, the sprite will say whichever message corresponds to the script you just dragged.
This crazy order can make execution incredibly unpredictable, especially when using clones.
The solution
The only real solution is to write code that has a definite execution order built-in (rather than relying on the whims of the editor). For simpler scripts, this generally means utilizing the broadcast and wait block to run particular events in the necessary order.
For your specific project, I see two main solutions:
Procedural Solution
This is the most straightforward script, and it's probably what I would choose to go with:
(row and col are both sprite-only variables)
Because clones inherit all sprite-only variable values when they are created, each clone will be guaranteed to have the correct row and col when it is created.
Recursive Solution
This solution is a bit harder to understand than the first, so I would probably avoid it unless you're just looking for the novelty: