我正在开发一个模拟草在不同季节生长的模型。
假设模拟中的一年有 368 天(刻度)。一年有四个季节:冬、春、夏、秋。我想要两种不同的场景:1)每个季节同样长的场景:368 天/4 个季节 = 每个季节 92 天; 2)用户可以选择每个季节的长度的场景。
对于第一个场景,我将其编码到模型中如下(参见“go”过程):
globals [
;; Climate related global variables
current-season
current-season-name
;; Time related global variables
days-per-tick
number-of-season
simulation-time
season-days
;; Grass related global variables
kmax
]
patches-own [
grass-height
r
]
to setup
clear-all
resize-world 0 (set-x-size - 1) 0 (set-y-size - 1)
setup-globals
setup-grassland
reset-ticks
end
to setup-globals
set days-per-tick 1
set number-of-season 0
set current-season-name ["winter" "spring" "summer" "fall"]
set simulation-time 0
set kmax [5 20 15 10]
set current-season initial-season
end
to setup-grassland
ask patches [
set grass-height initial-grass-height
ifelse grass-height < 2
[set pcolor 37]
[set pcolor scale-color green grass-height 23 0]
set r 0.002
]
end
to go
if season-days >= 92 [set number-of-season number-of-season + 1 ;; the season change and duration is determined in this line
ifelse current-season = 0
[set current-season 1]
[ifelse current-season = 1
[set current-season 2]
[ifelse current-season = 2
[set current-season 3]
[set current-season 0]
]
]
]
set simulation-time simulation-time + days-per-tick
set season-days season-days + days-per-tick
if season-days >= 93 [set season-days 1]
grow-grass
tick
end
to grow-grass
ask patches [
set grass-height ((item current-season kmax / (1 + ((((item current-season kmax) - (grass-height)) / (grass-height)) * (e ^ (- r * simulation-time))))))
ifelse grass-height < 2
[set pcolor 37]
[set pcolor scale-color green grass-height 23 0]
]
end
to-report season-report
report item current-season current-season-name
end
我的问题是在实施第二种情况时。我想在界面上添加四个滑块,允许用户更改每个季节的长度(从最小 0 天到最大 368 天。重要的是四个季节的总和为 368。例如, 是用户设置 winter-length = 368 天, 剩余季节的长度应为 0)。例如,假设每个季节的持续时间设置如下:
冬长122天
春长62天
夏季122天
秋季长度 62 天
(总计:368天)
有什么想法可以在代码中实现类似的东西吗?