Search code examples
nestedargumentsreportnetlogo

Netlogo: Nested to-report, ask, and argument


Recently I've been writing a Netlogo v6 code that:

  • Changes an agent's influence in a certain behavior based on the total of their peer's influence, which is weighted by the peer's reputation
  • The reputation of a peer is based on their cooperative behavior and their visibility in meetings

Now, I've been learning much about to-report and I find it helps me much in structuring my code, so I'm using it quite a lot.

However, I seem to keep getting the following type of error:

this code can't be run by a turtle, only a link error while link 14 9 running CALCULATE_CURRENT_REPUTATION called by procedure CALCULATE_REPUTATION called by procedure HORIZONTAL_INTERACT called by procedure GO_TO_MEETING called by procedure GO called by Button 'go'

I was wondering whether someone can see what's wrong?

I've been trying to see whether the problem is with the to-reports, but that doesn't seem to be the issue. Because, when I combine all to-reports into a singular function, I get a similar link/turtle asking issue.

My hunch is the issue lies with the fact that I somehow didn't ask properly, but how should I change it then?

The code of the to-report version:

to go_to_meeting
  ask members [

    ; if go_to_meeting and meeting_organised both report true, the member goes to the meeting (which is on the belowmentioned patch-set)
    if go_to_meeting? and meeting_organised? [
      move-to one-of (patch-set patch 0 0 ([neighbors] of patch 0 0 ))
      set meetings_attended meetings_attended + 1]

  ; the members at the meeting check whether their links are also there, if so, they interact with them
  ask members-on one-of (patch-set patch 0 0 ([neighbors] of patch 0 0 )) [
    if link_at_meeting? [horizontal_interact]
  ]
  ]
end

[ irrelevant code of link_at_meeting? and meeting_organised? is ommitted]

;;;;;;;;;;;;;;AT THE MEETING;;;;;;;;;;;;;;

to horizontal_interact
  set subjective_norm_list []
  set links_at_meeting my-out-links with [[patch-here] of other-end = (one-of (patch-set patch 0 0 ([neighbors] of patch 0 0 )))]
  if any? links_at_meeting [
    repeat number_of_interactions_per_meeting [
      ask one-of links_at_meeting [
        set influence_given ( calculate_reputation end2 end1 ) * [attitude] of end2 * [intrinsic_trust] of end1
        set number_of_encounters number_of_encounters + 1
         ask myself [set subjective_norm_list lput [influence_given] of myself subjective_norm_list]
         ]
    ]
  set subjective_norm sum subjective_norm_list
  print subjective_norm_list
  print subjective_norm
  ]
end

; a = end 2
; b = end 1
to-report calculate_reputation[a b]
 set reputation_now calculate_current_reputation
   ;reputation history is the cooperative behavior and visibility history of the link
   set reputation_h lput reputation_now reputation_h

    ifelse length reputation_h < ([memory] of b)
     ;if the links have encountered less than a member's memory, that is, the member recounts every memory, take the link's reputation to be the mean of every coop_b in the reputation history
     [let reputations sum reputation_h
     set reputation_total (reputations / (length reputation_h))]

     ;else, go so far as memory stretches and take the mean cooperative behavior in the reputation history as the link's reputation
     [let reputations sum sublist reputation_h (length reputation_h - ([memory] of b)) (length reputation_h)
      set reputation_total (reputations / ([memory] of b))]

  report reputation_total
end

to-report calculate_current_reputation
  report ((100 - behavioral_transparency) / 100 * calculate_visibility + behavioral_transparency * calculate_coop_b)
end


to-report calculate_visibility
  report number_of_encounters / ([meetings_attended] of end1)
end

to-report calculate_coop_b
  ask end1 [
    set shares_bought_total sum [shares_bought] of my-out-links
    set energy_gap_total ( sum [energy_consumed] of my-out-links - sum [energy_generated] of my-out-links)
  ]
  report  ([shares_bought] of end2 / [shares_bought_total] of end1 + [energy_gap] of end2 / [energy_gap_total] of end1 )
end

Solution

  • I've come upon the problem myself, so here's the solution and the issue explained for those having a similar issue:

    It was a syntax problem in the function calculate_coop_b. The problem was I asked variable [shares bought] of my-out-links, but I actually meant to ask [shares bought] of out-link-neighbors.

    THe correct code for this function:

    to-report calculate_coop_b
      ask end1 [
        set shares_bought_total sum [shares_bought] of out-link-neighbors
        set energy_gap_total ( sum [energy_consumed] of out-link-neighbors - sum [energy_generated] of out-link-neighbors)
      ]
      report  ([shares_bought] of end2 / [shares_bought_total] of end1 + [energy_gap] of end2 / [energy_gap_total] of end1 )
    end
    

    I hope this page still illustrates to others how a nested to-report function can be used, even though that didn't turn out to be causing the problem for me in the end.

    Thanks for reading, bye!