Sub-breeds in NetLogo - netlogo

I am new to NetLogo and I have some questions about the following piece of code:
people-own [
walker-type ;; can be "cautious", "adaptive" or "reckless"
walked-through-red?
own-profit
adaptive-threshold-time-gained
adaptive-threshold-time-gained-people-crossing
adaptive-gone-reckless
cooldown
]
With an OO background, I see this as some kind of enumeration of the properties of an object (the people breed). You can clearly see that there are three types of people: cautious walkers, adaptive walkers and reckless walkers. Also, the properties beginning with adaptive (adaptive-threshold-time-gained and such) have only meaning when the current person is adaptive.
I would expect that there is some way to express this more elegantly. In an OO programming language you would use inheritance to create three subclasses (one for each walker-type), but for so far I know that doesn't exist in NetLogo.
What is the recommended way of expressing this?

Lack of inheritance (perhaps as sub-breeds) is a serious limitation of NetLogo, although in the end it has only occasionally mattered to me. There are a couple possible work-arounds, depending on the application.
If you just want some different data attributes, and the related types are the only turtles in the simulation, you can have turtles-own the common characteristics and have breeds-own only the type specific characteristics.
If the data attributes are all shared but the behavior differs, you can create your own agentsets (in your case, subsets of people) and call different procedures on each agent set (or write procedures that branch on a member? test). Unfortunately, these agentsets will have to be explicitly augmented if any new members are created, so you lose that nice "special agentset" feature of breeds.
hth.

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.

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().

Translating a State Transition System to properties LTL formulae

In the context of bounded model checking, one describes the system as a State Transition System and the properties that need to be checked.
When one needs to provide multiple system descriptions and properties to the Model Checker Tool, it can become tedious to write the property by hand. In my case, I use some temporal logic.
How does one automate the process of translating/parsing the system description and deriving verifiable properties from it (ideally, a set of Initial states, Transitions, Set of States).
For example, consider the Microwave Example given here Given such a system description, how can I arrive at the specifications in an efficient manner?
There is no such open source tool that I know of, that can do this. Any approaches in terms of ideas, theories are welcome.
You can't automatically derive LTL formulae from automata as you suggest, because automata are more expressive than LTL formulae.
That leaves you with mainly two options: 1. find a verification tool which accepts specifications that are directly expressed as automata (I'm not sure which ones do, but I suspect it is worth checking SPIN and NuSMV for this feature.), or 2. use a meta-specification language that makes the writing of specifications easier; for example, https://www.isp.uni-luebeck.de/salt (doi: 10.1007/11901433_41) or IEE1850/PSL. While PSL is more a language definition for tool-implementors, SALT already offers a web front-end that translates your input straight into LTL.
(By the way, I find your approach methodologically challenging though: you're not supposed to derive formulae from your model, but from your initial system description as it is this very model which you're going to verify. But I am not a 100% sure, if I understood this point in your question correctly.)
I think properties of a system, e.g. Microwave system, come from technical and common sense expectation and requirements, not the model. E.g. microwave is supposed to cook the food. But it is not supposed to cook with door open. Nevertheless a repository of typical LTL pattern can be useful to define properties. It also lists properties along with more familiar regex and automata properties.
If you certain you still want to translate automata to LTL automatically check
https://mathoverflow.net/questions/96963/translate-a-buchi-automaton-to-ltl
Kansas Specification Property Repository
http://patterns.projects.cs.ksu.edu/documentation/patterns.shtml

Which agent executes a command given to an agentset first?

If I switch to turtle/patch context and do something like "set pcolor green", in what order do they execute the commands? I tested it out with a wait in there to see if there was an obvious pattern, but couldn't notice any. Is there any difference between that and ask?
I doubt it's completely random, though. How's it actually being handled behind the stage?
It's random--about as random as things get in computer programming, I believe. The NetLogo User Manual says:
An agentset is not in any particular order. In fact, it's always in a random order. And every time you use it, the agentset is in a different random order. This helps you keep your model from treating any particular turtles, patches or links differently from any others (unless you want them to be). Since the order is random every time, no one agent always gets to go first.
I just looked quickly at AgentSet.java in the source code for a recent version of NetLogo (5.0.2), it and looks to me like the order is randomized using a Mersenne Twister algorithm, which is usually considered to be quite good for randomization.
If you want the turtles/patches/links in a particular order, you can use sort, or select elements using e.g. with, or convert the agentset into a list using [self] of <agentset>, for example.

Design strategy advice for defining machine system functionality

This question relates to project design. The project takes an electrical system and defines it function programatically. Now that I'm knee-deep in defining the system, I'm incorporating a significant amount of interaction which causes the system to configure itself appropriately. Example: the system opens and closes electrical contactors when certain events occur. Because this system is on an airplane, it relies on air/ground logic and thus incorporates two different behaviors depending on where it is.
I give all of this explanation to demonstrate the level of complexity that this application contains. As I have continued in my design, I have employed the use of if/else constructs as a means of extrapolating the proper configurations in this electrical system. However, the deeper I get into the coding, the more if/else constructs are required. I feel that I have reached a point where I am inefficiently programing this system.
For those who tackled projects like this before, I ask: Am I treading a well-known path (when it comes to defining EVERY possible scenario that could occur) and I should continue to persevere... or can I employ some other strategies to accomplish the task of defining a real-world system's behavior.
At this point, I have little to no experience using delegates, but I wonder if I could utilize some observers or other "cocoa-ey" goodness for checking scenarios in lieu of endless if/else blocks.
Since you are trying to model a real world system, I would suggest creating a concrete object oriented design that well defines the is-a and a has-a relationships and apply good old fashioned object oriented design and apply it into breaking the real world system into a functional decomposition.
I would suggest you look into defining protocols that handle the generic case, and using them on specific cases.
For example, you can have many types of events adhering to an ElectricalEvent protocol and depending on the type you can better decide how an ElectricalContactor discriminates on a GeneralElectricEvent versus a SpecializedElectricEvent using the isKindOfClass selector.
If you can define all the states in advance, you're best of implementing this as a finite state machine. This allows you to define the state-dependent logic clearly in one central place.
There are some implementations that you could look into:
SCM allows you to generate state machine code for Objective-C
OFC implements them as DFSM
Of course you can also roll your own customized implementation if that suits you better.