Communicating data between agents when they are in common scope in Netlogo

StackOverflow https://stackoverflow.com/questions/22707368

  •  23-06-2023
  •  | 
  •  

Вопрос

I am developing a model in Netlogo. I have many agents in my model. each agents must have a radio scope. Two agents can communicate with each other and transfer some critical data When they place in a common scope area.

Imagine that i have 100 agents with 5px scope and 200 agents with 3px scope. I have also 1 master agents that move around in the word. This master agent have a scope too(for example 7px) . Agents can communicate with each other when they place in common scope area. When they communicate they can transfer some of their data. At first just master agent have this critical data and just master agent can transfer this important data. But after he transfer its data to the other agents, those other agents that have this data can transfer this data too. The important condition is being in the common scope.

How can I do this?

Thank you

Это было полезно?

Решение

You just gave a very general statement of your problem. You will get better answers if you make the effort to actually start implementing something and ask about more specific difficulties that you are facing.

That being said, I made a small model that more or less fits with your description. Perhaps it could be useful for you as a starting point and you can ask separate (more precise) follow up questions if you have some.

turtles-own [ scope data ]

to setup
  clear-all
  ; make a big world so agents don't
  ; bump into one another right away:
  resize-world -100 100 -100 100
  set-patch-size 3
  ; create turtles and distribute them around:
  crt 100 [ set scope 5 set data "" ]
  crt 200 [ set scope 3 set data "" ]
  crt   1 [ set scope 7 set data "important data" ]
  ask turtles [
    set size 3
    setxy random-xcor random-ycor
    recolor
  ]
end

to go
  ask turtles [ travel ]
  ask turtles with [ not empty? data ] [ share-info ]
  ask turtles [ recolor ]
end

to travel
  ; you haven't specified how turtles should move
  ; so here's a classic "wiggle":
  rt random 30
  lt random 30
  fd 1
end

to share-info
  ask other turtles in-radius scope with [ empty? data and distance myself < scope ] [
    set data [ data ] of myself
  ]
end

to recolor
  set color ifelse-value empty? data [ grey ] [ red ]
end

Edit:

Following Seth's comment that my first version probably didn't capture the idea of a common scope, I've added and distance myself < scope. This way, only turtles that can see each other can share information.

I've also added a with [ not empty? data ] clause when asking turtles to share info, because there is no use in having turtles with empty data share it.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top