gpt4 book ai didi

runtime-error - 求幂时出错 : “math operation produced a non-number”

转载 作者:行者123 更新时间:2023-12-02 03:35:52 25 4
gpt4 key购买 nike

在执行此代码期间,模型在对象中报告的错误中运行。在之前的模型中,变量土地可持续性设置为 1 到 6 I 没有招致这种错误。我列出了下面的代码,报告了最后被错误高亮显示的代码部分:

 turtles-own  [
profit-from-fuel
profit-from-food
expected-fuel-sell-price
expected-food-sell-price
profit
farm
farm-size
]


patches-own [
fuel-yeld
food-yeld
land-sustainability
water-level
belongs-to
food
fuel

]

globals [
fuel-sell-price
food-sell-price
governs
]


to setup
clear-all
clear-all-plots
create-farmers
setup-land
reset-ticks

ask turtles
[ set-farm-in-radius farm-size ]

set fuel-sell-price 184 + random 55 + random -55
set food-sell-price 184 + random 55 + random -55

end


to create-farmers


create-turtles 30

[
set shape "person farmer"
setxy random-pxcor random-pycor
set profit-from-fuel 0 ; indicizzazione del profitto iniziale a 0
set profit-from-food 0 ; indicizzazione del profitto iniziale a 0

set farm-size random 5 + 1
set label farm-size
]
end


to setup-land

ask patches [set belongs-to nobody]

ask patches
[

set pcolor 3
set food-yeld 13000
set fuel-yeld 13000
set land-sustainability random-float 0.9 + 0.1 ; per creare un moltiplicatore che vada da 0.1 a 1
set water-level random 3 * 1000
if water-level = 0 [set water-level 1000]
]

end


to set-farm-in-radius [d]
move-to one-of patches with [not any? other patches in-radius d with [belongs-to != nobody]]
set farm patches in-radius farm-size
ask farm [set belongs-to myself]
let c random 6 + 61
ask farm [set pcolor c]
end


to set-farm-distance [d]
move-to one-of patches with [not any? other patches with [belongs-to != nobody and distance myself < d]]
set farm patches with [distance myself < d]
ask farm [set belongs-to myself]
let c random 6 + 61
ask farm [set pcolor c]
end



to go



ask turtles [

set expected-fuel-sell-price fuel-sell-price + random 5 + random -5
if expected-fuel-sell-price < 0 [set expected-fuel-sell-price 1]
set expected-food-sell-price food-sell-price + random 5 + random -5
if expected-food-sell-price < 0 [set expected-food-sell-price 1]
set profit profit-from-fuel + profit-from-food
if profit = 0 [ set profit 1 ]
]

ask turtles [

cultivate
ask farm [recolor-farm]
set profit profit-from-food + profit-from-fuel
]



set fuel-sell-price fuel-sell-price + random 55 + random -55
if fuel-sell-price < 126 [set fuel-sell-price 126 ]
if fuel-sell-price > 245 [set fuel-sell-price 245] ; è corretta come assunzione? su un arco di 30 anni è ragionevole suppore che il limite massimo del prezzo
set food-sell-price food-sell-price + random 55 + random -55 ; sia di soli 5 euro più alto rispetto al massimo delgi ultimi 10 anni
if food-sell-price < 126 [set food-sell-price 126]
if food-sell-price > 245 [set food-sell-price 245]

if ticks = Duration [ stop ]
if ticks > Duration [stop]

ask patches
[ set food 0
set fuel 0
if land-sustainability < 0.1 [set land-sustainability 0.1] ; all'interno del modello la land susitability varia in base alle colture utilizzate
if land-sustainability > 1 [set land-sustainability 1 ] ; ma questa non può comunque essere inferiore a 0.1 o maggiore di 1
]

tick

end

to cultivate
let r risk-attitude
let e-f expected-fuel-sell-price
let e-food expected-food-sell-price

ask farm [
ifelse land-sustainability < 0.35 or water-level < 1100 ; 0.35 è un valore arbitrario che può essere modificato vedere i documenti FAO
[ ask myself [set profit-from-food sum [food-sell-price * (((food-yeld ) ^ (alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma))))] of farm
]
set food 2
set fuel 0
set land-sustainability land-sustainability + 0.1 ; la scelta di coltivare prodotti destinati alla produzione di cibo incrementa il livello l-s del terreno così coltivato
set pcolor 52.5
]

[

if land-sustainability >= 0.35 or water-level = 0
[

let utility-from-food e-food * ((food-yeld ) ^ (alfa)) * ((water-level) ^ (gamma)) * ((land-sustainability) ^ (beta)) ; da riscrivere la nuova formula con l'utilità di
let utility-from-fuel e-f *(( fuel-yeld) ^ (alfa) * ((water-level) ^ (1 - gamma) * (land-sustainability) ^ (gamma) ))


ifelse utility-from-food < utility-from-fuel
[
ask myself [set profit-from-fuel sum [fuel-sell-price * (((fuel-yeld ) ^ (alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma))))] of farm ] ; ricominciare da qui cobb-douglas
set fuel 1
set food 0
set land-sustainability land-sustainability - 1
]
[ ask myself [set profit-from-food sum [food-sell-price * (((food-yeld ) ^ (alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma))))] of farm ]
set food 1
set fuel 0
set land-sustainability land-sustainability + 0.5

]

]
]


]
end

to recolor-farm
if (food = 1 and fuel = 0 ) [set pcolor green ]
if (fuel = 1 and food = 0 )[set pcolor yellow]
if (fuel = 1 and food = 1) [set pcolor pink] ; check
if (fuel = 0 and food = 0) [set pcolor blue] ; check
end

[ 问自己 [设定食品利润总和 [食品销售价格 * (((食品产量) ^ (alfa)) * (((水位) ^ (1 - Gamma )) * ( (land-sustainability) ^ (gamma))))] of farm

最佳答案

a ^ b 将在 a 为负数且 b 为小数时产生此错误消息,例如,如果您尝试取-1 的平方根:

observer> show -1 ^ 0.5
ERROR: Runtime error: math operation produced a non-number

尝试在 set profit-from-food ... 行之前添加 show land-sustainabilityshow gamma,看看错误的值正是您要指数化的值。然后,您需要进行一些调试以找出这些不良值的来源。可能您让 land-sustainability 变得消极。

关于runtime-error - 求幂时出错 : “math operation produced a non-number” ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23528776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com