Creation of a flexible but on variables depending hierarchical structure in Netlogo - structure

i am trying to model the following hierarchical structur in Netlogo:
Imagine a typical company or a a brach of public administration. There is one boss (turtle) on top and a number of employees (turtles) below him/her. There are two variables: span-of-control soc (how many employees can one Boss overwatch) and depth-of-control doc (how many hierarchical levels do exist in the structure). The total number of employees equals soc^doc. The total number of turtles equals 1+soc^doc (1 is the boss).
There are two Choosers in the Netlogo-Interface: soc and doc (ranging from 1 to 4).
What I imagine to code: Depending on the Variables chosen, the structure should arrange itself automatically by the following rule: Create as many links to employees as there have been employees on the higher hierarchical level until the doc is reached.
Example: doc:3 soc:3 1 Boss (always 1 so it can be used like an anchor)
1. Level: 3 links (1*3)
2. Level: 9 Links (3*3)
3. Level: 27 Links (9*3)
4. Level: Over as doc is reached
To realise this, I need to make the turtles kind of read the doc and soc variables and make them create links accordingly but I dont know how.
Here is my code so far:
globals [
information
]
undirected-link-breed [ Informationflows Informationflow ]
breed [ Employees Employee ]
breed [ tasks task ]
breed [ Bosses Boss ]
;#########SETUP########
to setup
clear-all
create-Bosses 1 [ set color red
set size 2 ]
set-default-shape Bosses "person"
ask Bosses [ setxy 0 15 ]
ask patches [ set pcolor white ]
set-default-shape Employees "person"
create-Employees ( span-of-control ^ depth-of-control) [set color blue
set size 2 ] ; absolute Number of Employees
;ask Boss 0 [ create-Informationflow-with random Employee 8] ; IDEA
;ask Employees [ create-Informationflow-with one-of other Employees] ; IDEA
;ask Employees [ create-Informationflow-with Boss 0 ] ; IDEA
repeat 100 [ layout ]
ask Employees [
setxy 0.95 * xcor 0.95 * ycor ]
end
to-report value-of-span-of-control? ; Just an idea
report span-of-control
end
;##########LAYOUT##########
to layout
; layout-radial Employees Informationflows (Boss 0) ;Problem: Boss is fixed in the Center
layout-spring Employees Informationflows 0 10 2
end
If anybody could hint me in the right direction, I would be very thankful.
Kind regards,
Jon

Okay, general coding advice first - do ONE thing, test it and fix it before moving on to the next thing.
Your question about how to 'read' the doc and soc variables makes me think you are very new to NetLogo. If so, please go and do the tutorials that are at the NetLogo site. Creating a chooser with the name 'XYZ' creates a global variable named 'XYZ', there is no additional step to read it. Since you are choosing numbers, you might want to use a slider instead of a chooser.
Try replacing your commented out ask Boss line with this:
ask one-of Boss [ create-Informationflow-with n-of soc Employees ]
It's generally bad practice to use who numbers because turtles can die or be generated in a different order because you change some code and then the who numbers are different. So I used one-of to randomly select any boss (of which there is only one anyway). I similarly used n-of to select Employees to create links with and specified the number n in the n-of to be the value from the soc variable.

Related

Netlogo - Turtles on more than one Patch - Item vs Who

How are you? I guess there is no way to visually represent in the Netlogo Interface a system with a "many-to-many" relationship, where turtles belong to more than one patch, and of course patches host more than one turtle. Correct?
I have a model where Banks (my turtles) operate on more than one Country (my patches). So I think my only option is to have two breeds of turtles, i.e. Banks and Countries, and connect Banks to Countries with link agents. Correct?
(I will also need interbank links, so I will need to set up a different breed of links. Correct?)
Now: I need to identify countries by name (i.e. Italy, France, Spain, etc.). I am reading a CSV file with country names and feeding it into a Netlogo list, but I am not sure how to have a country agent "be" a name. I created a country breed-specific variable called "country-name", and I am trying to use "item" to sequentially access each next name in the list of country names and assign it to the country-name variable of the next country agent in the Countries breed. However, I cannot relate "item" to "who" here, because "who" is not breed-specific. So I am thinking of setting up a separate breed-specific numbered index, but something like this has been asked in a previous question (trying to create a sequential ID variable for breeds in netlogo) and it was strongly suggested NOT to do so. Any suggestions on how to proceed?
I agree with the comment by Matteo. That said,
You don't ever need to use "who". Identify your banks and your countries with a "name" field that the breed owns. For example
banks-own [ name ]
counties-own [ name ]
;; then somewhere in your loop as you read them in...
create-banks 1 [ set name "Chase" ... ]
create-countries 1 [ set name "England" ...]
Below I use 'one-of' but there will only be one hit.
This makes the syntax work converting a list item to a specific turtle.
You never should need to know or care about the "who" value of a bank
or country.
to make-branches
;; read this list in from a csv file, etc. or hard code it
set branchlist [[ "Lloyds" "England"] ["Lloyds" "France"] [ "Chase" "USA"]["Chase" "France" ]]
;; then work the list. Again, you never need "who".
foreach branchlist [
z -> ask one-of banks with [name = item 0 z ]
[ create-link-with one-of countries with [ name = item 1 z ]]
]
end

Moving parameters for variable to set up - model behaviour changes

This one stumping me...
I have an ABM which generates new patients arriving to a hospital unit by random-poisson on a single patch (spout procedure). Each patient is assigned an area to go to and a time to spend in the unit according to the area and other assigned variables. When I created this with the distributions embedded in the procedures or reporters it worked fine every time, but when I code the random variables into the set up to make it easier to manipulate it regularly generates grossly abnormally low/high values (ranges not seen when run in original format) and sometimes the creation of new patients doesn't happen at all though the model still ticks on... The only things changed are the placement of the variables in set up and and not in the body of the code.
I can't figure out why it would randomly have no patients entering the system which makes me mistrusting of anything else it generates. Is this just a formatting style that Netlogo doesn't like? Or am I missing something?
Thanks for any advice/help in solving this one
original code:
if ticks = 1000 [stop]
ask arrivals
[
assess
crowding-check
relocate
]
end
to assess
sprout-patients random-poisson 1.5
[set time_arrived ticks
set condition random-float 1.0
set NEWS2 random-float 7.0
set shape "person"
]
end
to-report AEC_treatment_time ;; gamma dist
let result random-gamma 3.478 0.525
if result < 2 [ report 2 ]
if result > 20 [ report 20]
report result
end
to-report AMU_treatment_time ; gamma dist
let result random-gamma 5.7716 0.3
if result < 4 [ report 4]
if result > 48 [ report 48]
report result
end
new code:
ca
set new-patients random-poisson 1.5
set AEC-los random-gamma 3.478 0.525
set AMU-los random-gamma 5.7716 0.3
reset-ticks
end
to go
if ticks = 1000 [stop]
ask arrivals
[
sprout-patients new-patients
assess
crowding-check
relocate
]
end
to assess
ask patients-here
[set time_arrived ticks
set condition random-float 1.0
set NEWS2 random-float 7.0
set shape "person"
]
end
...
to-report AEC_treatment_time ;; gamma dist
let los-AEC AEC-los
if los-AEC < 2 [ report 2 ]
if los-AEC > 20 [ report 20]
report los-AEC
end
to-report AMU_treatment_time ; gamma dist ;; reports treatment time for patients in AMU
let los-AMU AMU-los
if los-AMU < 4 [ report 4]
if los-AMU > 48 [ report 48]
report los-AMU
end
ps trying multiple iterations, it seems to be the random-poisson change that is the one causing the issues
It's pretty hard to see without the full code as it looks to be a problem with the way procedures connect, but your new structure has ask patients-here (at the start of the assess procedure) inside a loop through ask arrivals (go procedure). Is arrivals a breed?
Generally it is a bad thing to have nested ask turtles type structures because each turtle ask all turtles that satisfy the conditions so you can get subtle errors. Anyway, this will probably get you back to what you were doing before:
to go
if ticks = 1000 [stop]
ask arrivals
[ sprout-patients new-patients [assess]
crowding-check
relocate
]
end
to assess
set time_arrived ticks
set condition random-float 1.0
set NEWS2 random-float 7.0
set shape "person"
end
This structure makes the assess procedure into a procedure that runs from the turtle's perspective (or context) and has it run immediately as the turtle calling it is created.

NETLOGO: Distribution of variable on my-links

I have network with number of nodes connected with links. I need to set variable (lets call it "trust") to links so that sum of variables from links from one agent to others makes 100. Example: Agent have 3 links to another agents. Their variables are "34 13 53" or "23 61 16" or " 37 16 47". Sum is always 100. Hope it makes sense. Is there some easy way to do it netlogo?
Just give them the values then normalise. Something like (not tested) ask agents [ ask my-links [ set trust [ 100 * trust / sum [ trust ] of my-links ] ]
The problem you are going to have is that the value will need to be different each way. For example, if A and B have a link between them, then trust might need to be 25 at A's end (because the other links total 75) and 50 at B's end. So you actually need the link to have two values - how much A trusts B and how much B trusts A.

How to move to another agent with the highest value?

my agents set trade_Price than when they trade and they save their profit to their payoff variable. in ai process I have to code that my agents have to look around and choose the neighbor agent with the highest payoff. and than the agent has to give his decision value to this agent. I asked it before and got this code:
ask buyers [
let current-buyer self
ask sellers [
let current-seller self
let how-much 1
set decision ;some number
ask current-buyer [
set decision ;some number
]]]
but got something else what i wanted. Than I code it myself so:
ask sellers
[ let partner one-of buyers-here if partner != nobody
[ move-to one-of partner with-max [decision] of buyers]]
But there are also mistakes, could you give a tip or at least which code is the right way?
Revised in response to comment:
ask sellers [
let candidates (buyers-on neighbors)
ifelse any? candidates [
let partner one-of (candidates with-max [decision])
move-to partner
][
die ;; or whatever you want to do in this case
]
]

Need a help to call a code appropriately in GAP

I have the following input in GAP's environment:
I wanted to check whether a certain element of my Free group is in the group or not, so I used the code:
> a in e;
and expected to get
[ true
But it didn't work:
[ false
But when I eliminated the long green [ in above pic on the right by hand, the answer got clear:
May I ask a help not to do it by hand? Thanks.
Edit: Here is the codes I did for a Free group for two generators. Look at the results at the end.
Indeed, GAP behaves correctly here: a is an element of f and not of w. If you want to access generators of the newly created finitely presented group, use GeneratorsOfGroup(w) to get their list.
An example based on the original question, but also demonstrating how to use ParseRelators to simplify input:
gap> f:=FreeGroup("a","b");
<free group on the generators [ a, b ]>
gap> w:=f/ParseRelators(f,"a^2,b^3,(ab)^4");
<fp group on the generators [ a, b ]>
gap> Size(w);
24
gap> e:=Elements(w);
[ <identity ...>, a*b*a*b^-1*a*b, b, (a*b)^2, b*a*b^-1*a*b, a*b^-1*a*b*a,
b^-1*a*b^-1, a, b^-1, a*b^-1*a, a*b*a*b^-1, (a*b^-1)^2, a*b*a*b^-1*a,
b*a*b^-1, b^-1*a, b*a*b, b*a*b^-1*a, a*b^-1*a*b, b^-1*a*b*a, a*b^-1, b*a,
a*b, a*b*a, b^-1*a*b ]
gap> gens:=GeneratorsOfGroup(w);
[ a, b ]
gap> a:=gens[1];
a
gap> a in e;
true
Now quite technical detail: indeed, a from f and a from w belong to different families:
gap> FamilyObj(GeneratorsOfGroup(f)[1]) = FamilyObj(GeneratorsOfGroup(w)[1]);
false
This is why you were getting false in your examples.