我对堆栈溢出很陌生,但对我的模型有一个问题。
我的模型由两种代理(渔民和处理器)组成。目前我有两个渔民和两个处理器。这两个品种都有一个特定的价格感知变量称为:价格感知-费舍尔和价格感知-处理器。渔民出去钓鱼,一旦船满了(渔获量= 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我想做的是比较费舍尔的价格感知和费舍尔访问的处理器的价格感知。
目前,我试图通过创建两个列表来做到这一点:一个是处理器的价格感知,另一个是渔民的价格感知。我使用列表事务(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。然后,预期的输出将是:
fisher 0 ( 12.5 )移动到处理器2 (10),并且作为12.5 >= 10,这个值应该是真的。
fisher 1 ( 15 )移到处理器2 (15),并且作为15 >= 15,这个值应该是真的。
但是我得到了这个输出,因为列表不明白渔民已经转移到了处理器2,因此他们比较了价格感知-fisher 0和价格感知-处理器3,而我想在这个例子中比较价格感知-fisher 0和价格感知-处理器3。
[15 12.5] ; fishers price perceptions
[10 15] ; processors price perceptions
[true false]有什么办法吗?
发布于 2022-03-11 17:35:21
你把它搞得太复杂了:只要让每只海龟直接观察处理器的价格感知就行了。没有必要考虑到所有海龟和所有处理器的价值。
有几种方法可以做到这一点。
如果绝对和结构上确定每个补丁永远不会有一个以上的处理器,那么您可以这样做:
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]
]
endprocessors-here记者(参见这里)报告一个代理集。如果您确信每个补丁不可能有多个处理器,这意味着one-of 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-processor将避免任何模糊性,甚至从逻辑的角度来看,它也是一个特定的变量,用于标识代理(而不是代理集)。
当然,在执行find-another-processor时,您需要记住将新处理器分配给current-processor。
https://stackoverflow.com/questions/71439718
复制相似问题