在执行此代码期间,模型在对象中报告的错误中运行。在以前的模型中,可变土地可持续性从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
[问自己[设定食物来源的总和[食品销售价格*(((food-yeld)^(alfa))*(((水位)^(1 - gamma))*( (土地可持续性)^(gamma))))]农场
答案 0 :(得分:0)
a ^ b
为否定且a
为小数,则 b
会产生此错误消息,例如,如果您尝试取-1的平方根:
observer> show -1 ^ 0.5
ERROR: Runtime error: math operation produced a non-number
尝试在show land-sustainability
行之前添加show gamma
和set profit-from-food ...
,以查看您正在尝试取幂的错误值。然后,您将进行一些调试,以确定这些不良值的来源。
可能你让land-sustainability
成为负面的。