比较列表中的值

发布于 2025-01-13 08:37:35 字数 1430 浏览 3 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄居者 2025-01-20 08:37:35

你把它弄得太复杂了:只需让每只乌龟直接查看该处理器的价格感知即可。无需考虑所有海龟和所有处理器的值。

有几种方法可以做到这一点。

如果从结构上绝对确定每个补丁永远不会有多个处理器,您可以这样做:

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

processors-here 报告器(请参阅此处)报告代理集。如果您确定每个补丁不能有多个处理器,则意味着此处的一个处理器将不可避免地报告渔民正在访问的处理器,因为它将是唯一填充的处理器processors-here 代理集。

如果您希望避免这种方法,因为当您知道只想引用特定代理时不喜欢使用代理集,则可以采用其他方法添加渔民自己的变量:

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

这样,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:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文