How we can add a chart based on parameter or color of agent in anylogic? (without agents state) - anylogic

I want to create some charts in anylogic. I know at first we should add some condition in the "statistic". we should use "item.instate". But I do not want to use statechart. I want to use a parameter or color of agents for that.
for example I have 100 agent with different opinion. the opinion is parameter for agents. Also, I changed the the color of agent by their opinion. I want to create the chart that demonestrate the number of agent with "totally Agreed" opiniin.
how can do it?
in the following picture, what I should write in the condition?
enter image description here

You can simply type item.myOpinion == "I like x", assuming your agent's opinion parameter is called myOpinion and you want to count those that have that opinion.
If your opinion is actually a color, it would be item.myOpinion.equals(Color.red) but your myOpinion would need to be of type Color.
However, there are many things garbled in your question. If you agents change their opinion, it should not be a parameter but a variable, for example...

Related

How to set TimeMeasureStart dynamically?

I have a model of a supply chain in which my agents "Product" pass through blocks in some agents (i.e. "Vendor", "Factory", "Wholesaler", and "Retailer") and I have a flowchart block in which the said agents in the supply chain use it. I would like to measure the time my agent "Product" spent, which its TimeMeasureStart is in for example its "Vendor" page and its following TimeMeasureEnd is in the said flowchart block like this. Now I have difficulty defining TimeMeasureStart in the TimeMeasureEnd block in the flowchart block.
I tried to use getRootAgent() but this way I couldn't access the timeMeasureStart block of the root agent so I couldn't try this.
Also tried to define a variable in the flowchart block page like this (and I know this way is wrong but I have no idea how to define a variable to suit TimeMeasureStart)
and then use it to define the corresponding TimeMeasureBlock the "Product" had passed: timeMeasureEnd Properties
but it gave me these 2 errors:
Type mismatch: cannot convert from TimeMeasureStart[] to TimeMeasureStart.
Variable must provide either dimension expressions or an array initializer.
Also tried set_startObjects but I didn't understand how to work with it and couldn't find the documentation in AnyLogic Help.
I really would appreciate any help.
(Also so sorry if the images are blurry, I don't know why their quality gets like this when I upload them.)
Either use
((Main)getRootAgent()).timeMeasureStart()
Or simply use
main.timeMeasureStart
Both take you back to Main. The former uses type casting, the latter is a direct link created by AnyLogic (assumes your timemeasureStart is in an agent embedded in Main)

Is there a way to force "Categorized" symbolization to use attributes in the table for e.g. color definition?

I have a map with a couple of dozen of different "categories" of polygons and would like to symbolize them using the "Categorized" symbolization in QGIS. Every category already has its color defined in a "fill_color" attribute within the table.
I would like the symbolization to honor that color definition instead of assigning some color of its own to the categories.
Is there a way to do this, without manually going through every category and changing its color?
I'm not a Python programmer, so if there is a possibility of programming this, it's beyond me.
The software itself does not offer the option to do what I need in "Categorized" symbolization, although you can do it in "Single Symbol". If you try it in "Categorized" it will let you do the same steps, but the program will nevertheless use colors of its own choosing.
Of course, if I go the "Single Symbol" way, I can't generate a proper legend of map units in Layout.

AnyLogic - make many edit boxes visible depending on variable

Here is a simplified example of my problem:
I want to make the edit box 1 or 2 visible, depending on whether a checkbox of box 1 or box 2 is checked. The variables "variableCheckbox1" and "variableCheckbox2" are connected to the respective ceckboxes.
I have written a function as shown in the picture. The function is called from the EditBox 1 ("Enabled"). This is a possible solution for ONE box each.
Does anyone have an idea if there is a more elegant way to do this for a very high number of checkboxes / edit boxes?
A possible solution would be to write a function with a switch case for each variable in my model, called from each box. A very inelegant solution would be to make a single function for each box, but I don't consider that a good way.
If you want this for a large number, turn the entire setup into its own agent type: Checkbox and editbox. Instantiate as needed, you can add a parameter to specify what this is about exactly...
This would be the most generic and powerful approach...
if this works for you, you can use replications for checkboxes and editboxes and associate them together through the index... and then just add the code in the visible field of the edit box... Of course you will have to determine their positions programatically

How to position Canvas with agents in classical Agent-Based Modeling in AnyLogic

I'm new to AnyLogic and trying to figure out how Agent-based models should be set there. There is a famous Epidemic model, which I'm trying to reproduce. Most tutorials on classical ABM deal with old GUI settings.
For example, in version 8.5+, which is actual now, the Environment object (that was used for positioning of layouts) has been deprecated.
Now I see that new object Canvas is used to put the layout with agents on the page. But the structure of source code file is a bit unclear for me and I've failed to find relevant description how Canvas can be set for the purpose. (Besides I'm not sure that this is recommended way of doing this task.)
Question: I would love to learn the right way to arbitrary position the area with agents on the page. Below you may see what I get by default.
After some playing around, the 'minimalistic' functionality is as follows.
One should create some population with arbitrary name Person (population name people adds automatically).
The following structure of the Project is to be reproduced (arbitrary names are marked with yellow).
Comment: after adding a Canvas called mapCanvas one adds the function setCanvasCellColor with following body:
mapCanvas.fillCircle(person.getX(), person.getY(), 3, color);
It is clear that former two arguments stand for coordinates of a given point, then its size (i.e. 3) and color. Do not forget to add two arguments used in the body, namely, person as Person and color as Color.
From Entry Action of the statechart named state call the just made function. I've put black color here just for the sake of demonstration; chartreuse constant gets used instead in the Epidemic example.
main.setCanvasCellColor(this, black);
Finally, you may run the model to get the following picture.
Note
If one is reluctant to bother with Canvas, use Main - Presentation - xxx_presentation and click Draw agent with offset to this position checkbox.

How to select output in Anylogic by agent parameter?

So, I'm pretty new with Anylogic, but have done a lot of tutorials and I have programming experience in Java. For my thesis I'm modelling a vehicle flow as a process. In the source block, I create custom agents (vehicles) with some parameters from the database. This works fine. Then I want to assign an electric parameter with randomTrue(0.5). For this, I call a setupTaxi-function, where electric ist set. The parameter for the randomTrue-function should be changeable, so I set it as an extra paramter anteilEtaxis (0.5).
After that, I want the vehicles to do different things depending on the value of electric using SelectOutput. I selected the Condition and test on agent.electric.
I basically did the exact same thing as described in the Anylogic help. And yet the framework always chooses the true Output port, no matter if the parameter ist set to true or false.
See the image for setup and parameters. I tested this via console (the first line is a println-call in source, the second a println-call in selectOutput.). Plus you can see that the parameter is set to different values, because the 3D visualisation model depends on it:
enter image description here
Also, I tried a few different combinations of setting the parameters, reading them etc... The only thing that will work is putting randomTrue(0.5) directly in the Condition box. This is not what I want though. So if you have an idea, what is wrong, please tell me.
This is a typical beginners problem.
I will assume you are calling the setupTaxi-function in your source in the "on exit" action... If you are doing that, then it's too late and the agent already made its decision on where it will go after the select output block.
You have to call your setupTaxi-function in 2 possible places:
1) In your source on the "on at exit" action
2) In your vehicle agent on the "on startup" action
Or even.. just make electric variable have a default value of randomTrue(main.anteilEtaxis)... that will also work.