Jane Aminato
Jane Aminato

Reputation: 23

NetLogo - How to give memory to agents

Here I give you my problem and my code.

Problem: Each agent i attaches to each position m (each m has a fixed amount of food, but some are worse, some are better) a score U_im that is updated in the course of time. Initially the scores are set to zero. Every time a player is chosen to access resources, with probability epsilon he choses a position at random, otherwise he choses positions sequentially in order of the highest score registered so far. For every position visited, the score is updated as U_im -> U_im - c (the cost) if the position is found occupied and U_im -> U_im + u_mi if it is found free.

How can I create this array u_mi? (that saves the best resources (=the ones with more food) that I have visited so far)

EDIT//: Ok, I did it!

If anyone needs this kind of code, feel free to contact me :)

Upvotes: 1

Views: 381

Answers (1)

JenB
JenB

Reputation: 17678

that's very impressive code for one day's experience !

yes, the list of payoff-memory as a nomads_own variable is how I would do it. But you will have to keep both the position and the payoff or you won't be able to sort them. You may want to limit the memory (eg only last 5 or best 5 or similar) if it starts slowing down too much because you are basically asking every turtle to keep a list of all patches.

On the question of 'not doing anything' - it is possible your while loop is stuck if there aren't any available locations. Try doing it this way (which is likely better anyway as it only has to select once):

to move-to-empty-one-of [locations]  ;; nomads procedure
  let candidates locations with [not any? nomads-here]
  if any? candidates [ move-to one-of candidates ]
end

NOTE: not tested

Upvotes: 1

Related Questions