Define agent population which is dispersed in specific areas or divided in groups? - anylogic

I have one agent (100 population) in main. Is it possible to divide this population into several groups, separated from each other but still connected?
There was a solution where we can define this population in another agent (containing square fields), but we need not have this dependency over another agent. I hope there will be a solution.
Thank you for help.

Sure. Many different options, depends on what you want to do with them.
Easiest is to use a parameter within your Agent type, maybe "gender". Create an OptionList "availableGenders" with entries like "FEMALE" and "MALE".
Then, when creating your agents, you can assign each a gender via that parameter.
Now, you have 1 population of humans but you can easily filter them by gender (using findAll(myPopulation, a -> a.gender.equals(MALE)) or similar)
Lots of example models use this approach, please check them to understand how it is done.

Related

Modelling agent behaviour, where single agent operates under two conditions simultaneously

Any tips on how to model agent behaviour in an environment where two sets of rules apply simultaneously.
Specifically, what I am looking to simulate is a situation where an Agent operates under a specific set of rules, such as an employee-employer relationship, but at the same time, operates on perhaps different "informal" rules, such as an employee-employee relationship. Effectively there are two network structures in place, but the agent operates in both structures.
Any example models out there that I could take a look at?
(This is a model design question, not programming, so it probably belongs on the NetLogo user group instead of here.)
My colleague and I wrote a book on modeling decisions that are tradeoffs between competing objectives, in ABMs. It's focus is on ecology but the concepts could be useful for you.
The basic idea is to come up with an objective function that includes both "sets of rules" as you call them. Perhaps something like maximizing your relations with fellow employees without getting fired by the employer. Then build very simple models of how decisions affect the mechanisms that drive co-worker relations, probability of getting fired, etc. It's not simple, but it's very powerful and flexible. You won't find a simple approach that's very general.
The fun part is trying different variations and comparing how they work.
https://press.princeton.edu/books/paperback/9780691195285/modeling-populations-of-adaptive-individuals
Maybe I’m under-thinking this, but..I would encode both (all) sets of rules, and have the agent execute those rules as appropriate.
So, how to choose and execute rules?
Per social interaction:
Execute one behavior randomly based on which relationships are present
Choose one or more behaviors, as #1 and execute all of them in a specific order
As above, but execute behaviors in random order
For all possible behaviors, assign a probability based on whatever factors (number of role-members present, utility, consequence, etc l) Choose and execute one behavior randomly based on that probability (roulettes-wheel selection)
Choose more than one… execute in fixed or random order
Proportionate to the value of a “social-competence” property, Select a number of possible behaviors as #4. Then randomly select one of those to execute.
Here’s a code-segment example of #6
;; list of possible reactions
;; these are variables or reporters that report
;; an anonymous command that executes the behavior
Let action-list (list
boss-action
employee-action
coworker-action
peer-action
)
;; measure social situation
;; list of values from reporters
;; these are reporters that return a value
;; based on, for example, how many of that type of
;; relationship are present.
Let choice-list ( list
( probability-of-doing-boss-behavior )
( probability-of-employee-behavior )
( probability-of-coworker-behavior )
( probability-of-peers-behavior )
)
;; think about situation, choose possible actions,
;; as many times as social-competence allows.
;; roulette-wheel should return the index of the selected action
Let reaction-list (n-values social-competence
[ -> roulette-wheel choice-list ] )
;; choose an action from those options
Let action-index one-of reaction-list
;; execute that action
Run item action-index action-list
The same result as a single combined objective function might be a physics type model where the result of any single set of rules is a vector of some strength pushing ("nudging"?) the agent in some direction. Then you could have as many sets of rules as you want, each contributing it's own vector of force, and the final result would be a resultant combined net force and subsequent Newtonian F=m*a or rearranging acceleration = ( vector sum of forces )/mass.
I'm trying to imagine how I respond when the expectations of different groups I belong to clash, and whether a linear sum vector model describes it. I recall in college when I couldn't resolve Catholic support for the Vietnam War and "Kill for Christ" was a tongue-in-cheek slogan. I think in that case the "forces" didn't cancel out -- they resulted in ABANDONING membership in one of the groups to reduce cognitive dissonance. So, not a linear sum of zero in that case.
Another unstable human approach might be to keep going back and forth when two forces attempting to dominate behavior conflict -- first going with one a few steps then feeling guilty and going the other way a few steps. So which one dominates at any given step might depend on one's recent path and history and which one you "owed" something to. Or imagine being married to two people and trying to keep both of them happy. Maybe you partition space and Monday-Tuesday-Wednesday you keep one happy and Thursday-Friday-Saturday you keep the other happy and Sunday you go fishing.

How to set service/delay time based on different source and parameter

I am modeling a scenario where say my source is incoming orders, but order may have different characteristics, such as lines, units # of SKUs on the orders. Based on different characteristics, my service/delay time my differ. For example, my service time may be 1slines+ 5sunits+30s*SKUs. How can I set up my source and delay block to model this scenario?
Create an agent type for orders, add parameters for #SKUs etc.
In your delay block's duration field, use agent.numSKU to refer to a parameter numSKU in your agent type Order.
In your source, make sure it creates Order agents (not the default agents).
Lots of example models do this, please follow some of the basic tutorials and check the example models :)

Agent Inheritance and Population Grouping

I am digging deeper into Agent Inheritance and I am still at the exploration level so my question will not be specific to an example but rather conceptual.
My objective is to create a model with an Agent Type called Machine. However, there will be different types of Machines and some may have different statecharts or different parameters. So, initially I thought it would be a good idea to create an Agent Type called Machine and then, using Agent inheritance, create Agent Types that extend from it (e.g. Machine 1, Machine 2, etc.).
The result is that if I have one machine of each type, the Machine Agent Type population will be empty, while Machine 1 and Machine 2 each will have a population of 1. I understand AnyLogic is designed that way, but ideally, I would like to see the population of the Machine Agent Type with a population of 2, one of type Machine 1 and the other of type Machine 2.
Agent inheritance might not be the answer, but I was hoping I could find a solution to this problem where I can have one main population with different sub-types.
You may ask why would that be needed. The answer is that all machines should have a similar behavior. Comparing this to DES, it's like having different Resources. All will have similar behavior (e.g. can be seize, released, attached, etc.) but each can be unique.
Your thoughts/suggestions would be appreciated.
Thanks!
If you want to use agent inheritance, then you would need to have 2 different populations. A population of type Machine will have agents of type Machine, not their child agent types. I typically deal with this by having the populations for the child agents, and then storing all agents in a list (i.e., array list - allMachines).
You mention different state charts, which is a good reason to use inheritance. Many people will try to inherit because one delay block takes X minutes, while another is Y. In those cases, just parametrize your one agent type. If the logical differences between these machines is small, I would consider just 1 class, with a few extra decides/branches to get the behavior you want. It can sometimes be tricky in AL to have process blocks/visual elements in a parent connect to areas in a child - not impossible, but not as easy as pure Java code where you can override and call super.function().

Moving agents with other agents using Pickup/Dropoff from PML in Anylogic without duplicate code

Info: The question was updated with more explanation
I want to transport a agent (e.g. bananas) with a moving agent (e.g. truck) from place A to place B, where, for example, place A is where the bananas where plucked and place B is some storage for the bananas. So the bananas are simply being transported by the truck. Especially, the agent to be moved (the bananas) are not a resource (in the sense of Anylogic PLM) and have no upper amount limit.
There are various ways to solve this problem, but most of them either require some element in the model that I don't need or want (for example, a rack/pallet system in the case of the block 'Rack Store') or require the agents to be Anylogic resources.
As described in this answer, it kinda makes sense to use pickup and dropoff for this task. The problem is that the agent to be moved is not being transported, so that answer does not solve my question. To explain further, when the agent to be moved (the bananas) are being dropped off at the target location (place B), they simply re-appear at their original location (place A), even though the truck which picked them up via the pickup block has moved to place B.
I made a minimal example of this here.
As I described, the 'transportation' only works if I add the separate 'moveTo1' block for the dropped off agents.
Is there any simple and obvious way to handle this rather simple task of transportation in Anylogic without having multiple move blocks or other workarounds? I know there is 'ResourceAttach', but that requires the agent to be moved to be resources, and there is 'RackStore', which requires a rack/pallet system, which I don't need or want in my model.
What I want to know is what the 'standard' Anylogic way would be to do this.
Thanks a lot in advance!
Now I understand what your problem is...
When you use dropoff, the block that comes after it needs to define the new location of the agents, otherwise they stay in the same place.. You can use the moveTo block with a jump so the agents are teleported to the location you want them to be:
In almost all the blocks of the PML you can define the agent location in the properties, and this is a case where using that property is necessary.
You can set the position of the bananas to the position of the truck.
e.g. using agent.setXY(container.getX(), container.getY()) in the "On dropoff" field.
It seems to work for a simple test model.

Is it possible to connect two separate nodes by two links?

I am wondering if it is possible to do this as I am trying to build a traffic simulation model and may need to utilise this feature , should it exist, in my model.
There two, and only two, conditions under which a pair of turtles may be connected by more than one link:
If the links are directed, you can have two links, going in opposite directions.
If the links are different breeds.
You might consider alternatives like having a single link but adding a links-own variable to the links containing a weight, count, or other information.