0

I have a sub-routing in my code where each patch is asked to pick its closest & farthest turtle based on certain conditions. I keep getting this error after a couple of ticks

OF expected input to be a turtle agentset or turtle but got NOBODY instead.
error while patch 0 30 running OF
  called by procedure UPDATE-SUPPORT
  called by procedure GO
  called by Button 'Go'

There are two other routines where a turtle dies or is born depending on a few other metrics that are measured. I am not able to debug the code but what i have figured so far is that it happens after a turtle dies or is born.

Below is the code based on which the closest & farthest turtles are assigned at each tick.

to update-support    
  ask patches [ 
    let old-total sum [my-old-size] of parties
    set f-party []
    set h-party []

    set party-list (sort parties)
    set voteshare-list n-values length(party-list) [ (([my-old-size] of party ? ) + 1 ) / ( old-total + 1 ) ] 
    set party-citizen-dist n-values length(party-list) [ ( distance party ? ) ^ 2 ]    
    set f-list n-values length(party-list) [ ( ( 1 / ( item ? voteshare-list ) ) * ( item ? party-citizen-dist ) ) ] 
    set f-index position (min f-list) f-list    
    set h-list n-values length(party-list) [ ( ( item ? voteshare-list ) * ( item ? party-citizen-dist ) ) ]
    set h-index position (max h-list) h-list

    set f ((-1) * (min f-list))
    set h max h-list

    set f-party lput item f-index party-list f-party 
    set h-party lput item h-index party-list h-party
    set closest-party first f-party
    set farthest-party first h-party
    ]

After a turtle dies, when I inspected the patch which was throwing the error, i found the word nobody as an element in the list. The error is highlighted to be in the Party ? section while creating the voteshare-list in the above code

When I inspected the patch throwing the error, Party-list which is the list with all the current parties sorted was showing this:

Party-list: [(party 0) nobody (party 2)]

and my f-party list just had [(nobody)]

Has anyone faced such a situation.?

Below is the death & birth routine:

to party-death
   ask parties [if (fitness < survival-threshold and count parties > 2)
       [  die
       ] update-support
]

to party-birth
  ifelse (endogenous-birth? = true)
    [ ask one-of patches with [distancexy 0 0 < 30]
      [ if (random-float 1 < (kpi * 1000)) [sprout-parties 1 [initialize-party] ]]
    [ create-parties 1 [set heading random-float 360 jump random-float 30 initialize-party] ]
        update-support

end
Raj
  • 1,049
  • 3
  • 16
  • 30
  • Why are you using lists instead of agent sets? You can iterate through an agent set without encountering this problem. – Alan Mar 01 '17 at 03:22
  • @Alan: I am not very proficient in netlogo. While i can create simple agentset, I am not sure how to do the above steps using agentset – Raj Mar 01 '17 at 03:54
  • You can always create `turtle-set` from any collection of turtles. Use local variables when needed (intead of globals). Don't ask all patches to do things that should be done by the observer (at least, that's how it looks from what you posted). Break things up into components that accomplish simple goals, and then ask questions about one component at a time. – Alan Mar 01 '17 at 05:37
  • @Alan: I understand your point and appreciate you taking time to respond. I have managed to recreate some of the `lists` in the above code using `agent-sets` as per your comment but i am still stuck with a few of the steps. Like how do I multiply value1 of turtle 0 from `agentset1` with value2 of the same turtle in `agentset2`. Case in point is the `f-list` in the code above – Raj Mar 01 '17 at 20:57
  • If it is really the same turtle, why do you care about which agent set it is in? Just multiply `value1 * value2`. Note that you can easily produced the intersection of `a1` and `a2` as `a1 with [member? self a2]`, so you can easily restrict your attention to agents in both sets. – Alan Mar 01 '17 at 21:21

0 Answers0