Reputation: 11
In the code at the end, during the Link cutting and rewiring process, I encounter the error **"COUNT expected input to be an agentset but got the number 0 instead" at the line "let temporary-link-count count my-temporary-links" while running turtle 1. This error is called by the procedure GO, triggered by the 'go' button. **
Before that, I also tried the following code, but this time I received the error "ANY? expected input to be an agentset but got the number 0 instead" for the line "if any? my-temporary-links [" while running turtle 0. This error is also called by the procedure GO, triggered by the 'go' button.
if any? my-temporary-links [ let selected-link one-of my-temporary-links let other-turtle other [end1] of [selected-link] of selected-link ; Select the agent at the other end of the link let fikir-farki abs(Ai - get-my-link-weight other-turtle) ; External idea difference between agents
I am open to changing the entire code block, so any suggestions are welcome.
globals [
link-weight-threshold
nd
maximum-loop-count
link-weights ; list to store link weights
]
turtles-own [
my-permanent-links ; to store permanent links
my-temporary-links ; to store temporary links
agents-with-majority-external
agents-with-minority-external
]
to-report get-my-link-weight [other-turtle]
; Get the weight of the link on the other end of the given agent
let link-index position other-turtle my-permanent-links
ifelse link-index != false [
report item link-index link-weights
] [
report 0 ; Report 0 as the default if the link weight is not found
]
end
to create-permanent-links
create-links-with n-of nd other turtles
[
ask myself [
set my-permanent-links lput self my-permanent-links ; Create a permanent link with own agent
]
set link-weights lput (random-float 0.5 + 0.5) link-weights ; add the weight to the list between 0.5 and 1
set color red ; Set the color of permanent links to red
]
end
to create-temporary-links-with [other-turtle]
; Initiate a procedure to create a temporary link with the other turtle.
create-link-with other-turtle [
; Create a new link with the other turtle.
set color blue
; Set the color of the new link to blue.
set shape "temp"
; Set the shape of the new link to "temp".
let weight random-float 0.5
; Set the weight of the new link to a random decimal between 0 and 0.5.
;set my-temporary-links lput self my-temporary-links
; Add the new link to the list of temporary links on itself.
]
end
to remove-temporary-link-with [link-to-remove]
ask link-to-remove [
let link-index position self link-weights
if link-index != false [
set link-weights remove-item link-index link-weights ; remove the weight from the list
]
die
]
end
to setup
clear-all
set nd 1 ; Ensure each agent has at least 1 neighbor
set link-weight-threshold 0.5
set maximum-loop-count 50 ; Maximum loop count
set link-weights [] ; create an empty list to store link weights
create-turtles 3 [
setxy random-xcor random-ycor
set shape "person"
set my-permanent-links [] ; create an empty list for each agent's permanent links
set agents-with-majority-external []
set agents-with-minority-external []
]
ask turtles [
create-permanent-links
set color white
]
reset-ticks
end
to go
while [ticks < maximum-loop-count] [
ask turtles [
; Stage 1: Assigning internal opinion (Fixed)
let Ai random-float 2 - 1
; Stage 2: Assigning a random number for external opinion
let Bi random-float 2 - 1
; Updating color and status based on the agent's opinion
ifelse Bi > 0 [
set agents-with-majority-external fput self agents-with-majority-external
set color green
] [
set agents-with-minority-external fput self agents-with-minority-external
set color orange
]
; Updating External Opinion Only via Temporary Links
let β 0.1
let y 0.3
if is-agentset? my-temporary-links and any? my-temporary-links [
ask my-temporary-links [
let other-turtle-link-neighbors link-neighbors
ifelse(count other-turtle-link-neighbors > 0) [
ask other-turtle-link-neighbors [
set Bi Bi + y * abs(Bi - get-my-link-weight myself) + β * abs(get-my-link-weight myself - Bi) ; Update Bi
]
] [
; If there are no link-neighbors, perform the necessary operations
]
]
]
; Link Cutting and Rewiring
let temporary-link-count count my-temporary-links
if temporary-link-count > 0 [
let selected-link one-of my-temporary-links
if is-link? selected-link [
let other-turtle other [end1] of selected-link ; Select the agent at the other end of the link
let opinion-difference abs(Ai - get-my-link-weight other-turtle) ; External opinion difference between agents
let threshold-value 0.2
; If the external opinion difference is small and there is no temporary link between the agents yet, connect the link
if (opinion-difference <= threshold-value) [
; Remove the temporary link
set my-temporary-links (my-temporary-links with [self != selected-link])
; remove the weight from the list
set link-weights remove-item (position selected-link link-weights) link-weights
]
]
]
]
tick
]
end
Upvotes: 1
Views: 43
Reputation: 4168
In general, an error like this occurs because an agent-set, in this case a link-set, has not been initialized as a set. NetLogo initializes all variables to zero, by default, which is likely why you are getting the errors you are. If you initialize each agent's my-temporary-links
to no-links
when you create each agent in setup
, then my-temporary-links
will begin as an empty link-set and count
and any?
should operate properly.
Upvotes: 1