I'm new to stackoverflow but have a question regarding my model.
My model consists of two breeds of agents (fishers and processors). Currently I have two fishers and two processors. Both breeds have a certain price-perception variable called: price-perception-fisher and price-perception-processor. Fishers go out fishing and once the ship is full (catch = 750) they return to one of the processors. This is done by this function:
to return-from-fishing ;; makes fishers return once they have a certain amount of fish
if epi-catch >= 1000 or exp-meso-catch >= 750
[move-to one-of processors
set arrived-at-processor? true
]
end
What I would like to do is compare the price perception of a fisher to the price-perception of the processor that the fisher visits.
Currently I have tried to do this by creating two lists; one for the price perception of processors and one for the price perception of fishers. I compare them using list-transactions (map > list-of-fishers-price-perceptions list-of-processors-price-perceptions)
What this does is iterate through both lists and compare the values in the list. However the problem is that the values are compared randomly and I want the fisher to compare his own price with that of the processor he visits. If the price-perception-fisher is higher to the price-perception-processors the fisher moves to another processor, else they will peform a transaction
An example from my model is as follows:
Variables of turtles are initialised as follows:
set fisher 0 price-perception-fisher 12.5
set fisher 1 price-perception-fisher 15
set processor 2 price-perception-processor 10
set processor 3 price-perception-processor 15
As fishers randomly move to one of the processors, both fishers could move to processor 2. The expected output would then be:
fisher 0 (12.5) moves to processor 2 (10) and as 12.5 >= 10, the value should be true
fisher 1 (15) moves to processor 2 (15) and as 15 >= 15, the value should be true
However I get this output, because the lists don't understand that the fishers have moved to just processor 2 and therefore they compare the price-perception-fisher 0 with price-perception-processor 3, while I want the comparison between price-perception-fisher 0 with price-perception-processor 3 in this case.
[15 12.5] ; fishers price perceptions
[10 15] ; processors price perceptions
[true false]
Would there be a way to do this?
You are overcomplicating it: just make each turtle directly look into that processor's price perception. There is no need to take into account the values from all turtles and all processors.
There are a couple of ways to do this.
If it is absolutely and structurally certain that there will never be more than one processor per patch, you can do:
to check-perceptions
ask fishers with [arrived-at-processor?] [
ifelse (price-perception-fisher < [price-perception-processor] of one-of processors-here)
[perform-transaction]
[find-another-processor]
]
end
The processors-here
reporter (see here) reports an agentset. If you are sure that there cannot be more than one processor per patch, it means that one-of processors-here
will inevitably report the processor that the fisher is visiting, because it would be the only one populating the processors-here
agentset.
If you prefer to avoid this approach because you don't like using an agentset when you know you want to refer only to a specific agent, you can take this other approach adding a fishers-own variable:
fishers-own [
; ...
; Here there are the other fishers-own variables
; ...
current-processor
]
to return-from-fishing
if epi-catch >= 1000 or exp-meso-catch >= 750 [
set current-processor one-of processors
move-to current-processor
set arrived-at-processor? TRUE
]
end
to check-perceptions
ask fishers with [arrived-at-processor?] [
ifelse (price-perception-fisher < [price-perception-processor] of current-processor)
[perform-transaction]
[find-another-processor]
]
end
This way, current-processor
will avoid any ambiguity should there ever be more than one processor per patch, and even from a logical point of view it will be a variable specifically thought for identifying an agent (instead of an agentset).
Of course, in case find-another-processor
is executed, you need to remember to assign the new processor to current-processor
.