How do I organize different Agents together in anylogic? - anylogic

Through my model, I have 3 types of agents. Currently, I can only know the total number of A in Source. But my purpose is to know the number of A, B, and C respectively through Source. So logically, I need to put Agent of A, B and C together and then count their number separately. However, I cannot find a way to achieved it?

Depending on how the agents are generated, but a good approach would be to have a separate source for each agent (A, B and C) and count number of agents emitted from each source. This can be done by calling source.out.count(), where source is a Source object, out is the exit port and count() is a counter that shows the number of agents as a small blue number.

Related

AnyLogic: free specific agents from wait block

I have equipped my agent with a parameter barcode. Input is an Excel with different barcodes as arrival in the source.
There are four different types of parts in my model. Part 1 is multiplied in the model by a split block w times, part 2 x times, part 3 y times and part 4 z times.
The parts run different paths through my model. That means they have different times and therefore do not arrive back in the sink at the same time. Because I want all parts to end up in the sink at the same time, I want to work with a wait block.
When the parts are multiplied, they keep their unique barcode.
Example: Part 3 is multiplied y times. So there are y many part 1 with the same barcode. So in the wait block I want all agents (parts) to wait until ALL multiplied parts of this part arrive in the wait block just before the sink.
My approach is: a switch case within the wait block after Part 1, Part 2 ect.
And then inside the case a code like: if w agents with the same barcode are inside the wait block, free them. But not all other agents. So you could say that this wait block is like a sorting station.
I would approach this differently. Instead of Wait block, I would keep it as Queue. Then join it to a Pickup block. Inside Pickup, select While condition is true and type below the condition (assuming your total number should be 7) (agent.barcode==container.barcode) && (count(queue, q-> q.barcode==agent.barcode)==7 )
.
Whenever a new barcode enters the system, create a dummy agent with agent.barcode set to that value and send the dummy agent to enter1 with code like enter1.take(agent). Then this dummy agent will wait in queue2, once the count is reached, it will pick up exactly that number of agents and depart to sink. If you want, you can put a Dropoff block and then Sink.

How can I create a finite calling population model?

I am trying to simulate a finite calling population model in AnyLogic. My population consists of 10 agents and I want them to come back to the Source node after they have been served.
I thought about making conditioning with the SelectOutput node but the Source node does not have any input. The best thing that I came up with is to just limit the number of customers arrivals to 10. However, in this case, the model stops running after 10 arrivals which is not an appropriate result.
What can I do to be able to simulate such a type of model in AnyLogic?
EDIT: I thought that making agents come back to the Source node could be a solution to building the finite calling population model. The main purpose of my question is to understand how can I build such type of model in AnyLogic. Here is the description of the concept of the model.
You cannot send them back to a Source element, as it only acts to create agents.
However, you can send them back to blocks that come after the source as below:
Here, all agents created by the Source block will infinitely loop through the Queue and Delay blocks.

Creating a specific Number of agents with a determined parameter value out of 3 values

I need to create an agent with a parameter "Class" that has 3 possible values. I need to be able to determine the number of agents with each class value at the Simulation screen before the simulation starts, by using a slider that determines the number of Agents.Class=="A", Agents.Class=="B" and so on.
I've tried creating an action chart that uses RandomTrue to assign the class.
The inputs for this action chart are:
A parameter sums the output of the 3 sliders to determine the total n of agents
Another parameter computes the percentage of agents.class=="A" from the total n of agents
A third parameter computes the percentage of the agents.class="B" from the remaining n of agents (n-agents.class=="A")
I'm not allowed to post pictures yet, but see action chart Here .
The issue with this is that when using percentages, it will round here or there and the actual number of agents with desired class may have one more or one less.
How can I make this with an exact number of agents created with each class?
This does not make sense mathematically. If you create 10 agents and the random number splits it using 0.66 and 0.33, then you cannot create 6.66 agents.
So some rounding must happen, unless you create infinite agents.
However, you can decide to round the random number. If you know you will create 100 agents, you could use Math.ceil(uniform(0, randomA)*100.) or similar. If randomA would be 0.66666, you would get 67 as a result.
(Math.floor would give you 66)
It isn't clear to me why you're converting the number to %-ages at all? Are you going to create N agents in total? If so you can just use amounts for class 'A' and class 'B' agents in two separate Source objects (one for each class) to create the agents at the start.

Determine number of clusters for different datasets

I performed a clustering analysis of the media usage of different users in order to find different groups that use a specific set of media (e.g. group 1 use media A, B and C and group 2 use media B, C and D). Then I divided the datset in different groups, since the users belong to a specific group (as a consequence the original dataset and the new datasets have a different size). Within in this groups I like to cluster again which different media sets are used.
How can I determine the number of clusters to guarantee that the results are comparable?
Thank you in advance!
Don't rely on clustering to be stable.
It's a hypothesis generation tool.
You clustered, and now you have the hypothesis that there are groups ABCD of media usage. You should first evaluate if this hypothesis is adequate. Now what you want to do in your next step is to assign the labels to subsets of the data. First of all, you should be able to simply subset this from the previous labels. But if this really is different data, you can label new data, for example using the most similar record (nearest neighbor classification). But that is classification now, because your classes are fixed.

compare a network with multi value of a variable

I have a network and simulate it in netlogo.In my network i have n nodes with a random data from [0.1,2,...,19].
at the beginning one random node became sink and 3 random nodes start to send its data to sink.i declare a variable named gamma.after nodes send their data to sink,sink decide to whether store that data in its memory space or not base on gamma.after 0.5s this process repeat.at each time some nodes are sink and want some data.this is the way i distribute data in my network.
after all i have to change gamma from 0 to 1 to determine best value for that. and each time run my code to plot count of something.i mean:first run my code with gamma=1 and after run it again with gamma=0.98 and ...
if Entropy <= gamma
[
do something
]
If i press the setup button each time i change gamma my network setup change and i can not compare the same network with another gamma.
How can i compare my network with multi value of gammas??
I mean is that possible to save all my process and run it exaclly the same again?
You can use random-seed to always create the same network and then use a new seed (created and set with random-seed new-seed) to generate the random numbers and ask order etc for your processing. The tool BehaviorSpace will allow you to do many runs with different values of gamma.
Using this approach will guarantee you the same network. However, just because a particular value of gamma is best for one network, does not make it the best for other networks. So you could create multiple networks with different seeds and have NetLogo select each network (as #David suggests) or you could simply allow NetLogo to create the different networks and run many simulations so that you have a more robust answer that works over an 'average' network.
It is possible if you design some tests first, when you put random data each time you press setup the previous graph is not the same as the new one, thus you'll need to load the same data everytime you want to test.
An idea:
Make text files with the node data and the value of gamma. For 4 nodes you'd have something like:
dat1.txt
1 3 2 9
1
dat2.txt
1 3 2 9
0.98
dat3.txt
1 3 2 9
0.96
And so on...
You can genereate this files with a procedure and an specific seed (see random-numbers), this means that if you want to generate 30 tests (30 sets of 4 nodes in the above example), you'll need 30 different seeds.