In the original model, the number of the guests and groups are fixed. To improve it, let’s say a group can be created by any person according to a certain probability. What’s more, an empty group will disappear after a period of time. 2. Rules Set a parameter “independency” to indicate the probability of creating a new group. Set a parameter “tolerance” to indicate the ratio of opposite sex one can bear.
Code: to go
ask turtles with [random 100 < independency * 100 ]
[
set num-‐groups num-‐groups + 1
];; Create a group
if num-‐groups > 0
[
ask one-‐of turtles
[
if group = -‐1
[
let i random num-‐groups
set group i
let j count turtles with [group = ([group] of myself) and color = ([color] of myself)]
ifelse color = blue
[setxy i
j ]
[setxy i
( j + 1 ) * -‐1]
]
let gp group
let samegroup count turtles with [group = ([group] of myself)]
let samesex count turtles with [group = gp and color = [color] of myself]
let ratio (samegroup -‐ samesex) / samegroup
if ratio > tolerance
[
let i random num-‐groups
set group i
let j count turtles with [group = ([group] of myself) and color = ([color] of myself)]
ifelse color = blue
[setxy i j
]
[setxy i ( j + 1 ) * -‐1 ]
]
]
]
update-‐group
update-‐plot end
to update-‐plot ;; to update the diagram