在执行此代码期间,模型将运行在对象中报告的错误中。在以前的模型中,可变土地可持续性设定为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

[问问我自己[设定从食物中获利的总和[食物销售价格*(((食物产量)^(阿尔法))*(((水位)^(1- Gamma ))* *(( land -sustainability)^(gamma))))]]

最佳答案

如果a ^ b为负且a为分数,那么b将产生此错误消息,例如,如果您尝试采用-1的平方根:

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

尝试在show land-sustainability行之前添加show gammaset profit-from-food ...,以查看您要求幂的错误值的确切含义。然后,您将需要进行一些调试,以找出这些不良值来自何处。
可能是让land-sustainability变为负数。

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

10-10 14:54