0

I have a model with a preferential attachment network connecting one breed of agents. They should influence each other based on one property they own [trust?] and on their neighbors. Thus, if more neighbors have [trust? = true], they should also adopt this property. The code for influence is set as such and works in a normal setting:

to influence

  ; defines sexworkers-trust as the link to trusting sexworkers     
  let sexworkers-trust link-neighbors with [ trust? = true ]

  ; defines total-neighbors as the total link to neighbors    
  let total-neighbors link-neighbors

  ; if mistrusting sex workers are surrounded by more trusting neighbors, they are influenced and start trusting  

  if not trust? and random-float 1.0 <   (neighbors-influence * (count sexworkers-trust / count total-neighbors ) ) [
    set trust? true
    set color green   ]

end

At the moment, I also have an additional option where (if set on "on"), a certain number of sexworkers enter the world every 10 ticks. They are also added to the network. Now, somehow once this enter option is on, the simulation stops after a while with the error message "division by zero". Here below is my enter code, maybe there is a mistake there?

to enter

  ; creates 5 sex workers, randomly trusting/mistrusting  

  create-sexworkers 5 [

    setxy random-xcor random-ycor
    set trust? one-of [ true false ]
    if trust? = TRUE [ set color green ]
    if trust? = FALSE [ set color red ]
    set birth-tick ticks   ]

  ; asks trusting sex workers to create a link to one of the other trusting sex workers
  ask sexworkers with [ trust? = true ]
  [ create-link-with one-of other sexworkers with [ trust? = true ] ]

end

Also, normally trust? = true should be indicated by sex workers turning green, but somehow the enter code also doesn't do that correctly, they seem to not have corresponding colors to their properties. I might have to split this into two questions, but I think this is connected to the enter process that then in turn crashes the influence process.

Thank you so much!

JenB
  • 17,620
  • 2
  • 17
  • 45
Mira Fey
  • 49
  • 5

1 Answers1

1

You have some ordering problems. If a node doesn't have any link-neighbors, then the linkset total-neighbors will be empty and your calculation of the proportion trusted will generate the divide by zero error.

There's not enough code here to give you a full answer. But I think you only have the trusting sexworkers creating links to other trusting sexworkers, so the non-trusting have no links and therefore no link-neighbors.

JenB
  • 17,620
  • 2
  • 17
  • 45
  • thanks, yes I was aware of the first issue, but the second one is only for newly entering turtles, still I think you answered my problem. Once the first generation of turtles with general links died, this issue must have occurred. – Mira Fey Jan 22 '19 at 19:01