There are a number of situations where you might want to rank the members (instances) of a population submodel in order, according to some criterion.
For example, you might want to select the three fattest pigs to send off to market. One way to do this is to define an association between pairs of instances, which holds true when the first member of the pair has a greater value for some attribute than the second. Then, the fattest pig will have no instances of this association (since there are no pigs with a greater value for fatness than itself). If there are (say) eleven pigs in the population at some point in time, then the middle pig will have five instances of this association, while the smallest pig will have ten instances. All that you then need to do is to count up, for each pig, the number of instances of this association that it is linked to, and use this rank value to kill off the individual.
Equations in submodel 'individual'
attribute = rand_const(0,100)
rank = count({one_role2})+1
where: {one_role1} = ../ranking/one (to individual in role1)
creation: initial number = 10
Equations in submodel 'ranking'
condition = (attribute_role1>attribute_role2)
where:
attribute_role1 = ../individual/attribute (from individual in role1)
attribute_role2 = ../individual/attribute (from individual in role2)]
one = 1
Attachment | Size |
---|---|
ranking1.sml | 43.73 KB |