比较列表中的值
我是 stackoverflow 新手,但对我的模型有疑问。
我的模型由两种代理(渔民和加工者)组成。目前我有两个渔民和两个加工商。这两个品种都有一个特定的价格感知变量,称为:价格感知渔民和价格感知处理器。渔民外出捕鱼,一旦船满了(捕获量 = 750),他们就会返回到其中一个加工商处。这是通过以下函数完成的:
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
我想做的是将渔民的价格感知与渔民访问的处理器的价格感知进行比较。
目前我尝试通过创建两个列表来做到这一点;一是加工者的价格认知,一是渔民的价格认知。我使用 list-transactions (map > list-of-fishers-price-perceptions list-of-processors-price-perceptions) 来比较它们,
它的作用是迭代两个列表并比较中的值名单。然而问题是这些值是随机比较的,我希望渔民将他自己的价格与他访问的处理器的价格进行比较。如果渔民的价格感知高于渔民的价格感知处理器,渔民就会转移到另一个处理器,否则他们将执行交易
我的模型中的示例如下:
海龟的变量初始化如下:
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
当渔民随机移动时对于其中一个处理器,两个渔民都可以移动到处理器 2。那么预期输出将是:
渔民 0 (12.5) 移动到处理器 2 (10) 并且当 12.5 >= 10 时,该值应该是 true
渔民 1 (15) 移动到处理器 2 (15) 并且当 15 >= 15 时,该值应该是 true
但是我得到这个输出,因为列表不明白渔民已经移动到处理器 2,因此他们将价格感知渔民 0 与价格感知处理器 3 进行比较,而在本例中我想要比较价格感知渔民 0 与价格感知处理器 3。
[15 12.5] ; fishers price perceptions
[10 15] ; processors price perceptions
[true false]
有办法做到这一点吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你把它弄得太复杂了:只需让每只乌龟直接查看该处理器的价格感知即可。无需考虑所有海龟和所有处理器的值。
有几种方法可以做到这一点。
如果从结构上绝对确定每个补丁永远不会有多个处理器,您可以这样做:
processors-here
报告器(请参阅此处)报告代理集。如果您确定每个补丁不能有多个处理器,则意味着此处的一个处理器将不可避免地报告渔民正在访问的处理器,因为它将是唯一填充的处理器processors-here
代理集。如果您希望避免这种方法,因为当您知道只想引用特定代理时不喜欢使用代理集,则可以采用其他方法添加渔民自己的变量:
这样,
current-如果每个补丁有多个处理器,处理器将避免任何歧义,甚至从逻辑角度来看,它也将是一个专门用于识别代理(而不是代理集)的变量。
当然,如果执行了
find-another-processor
,您需要记住将新处理器分配给current-processor
。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:
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 thatone-of processors-here
will inevitably report the processor that the fisher is visiting, because it would be the only one populating theprocessors-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:
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 tocurrent-processor
.