我一直在为我的研究论文编写模拟欧盟新的 CSDDD 政策的代码。但代码无法正常运行,并且总是出现一些错误。我解决了其中一些问题,但又出现了一个新问题。我是 Netlogo 新手,如果有人能帮助我,我将不胜感激。谢谢!
问题:我在 netlogo 界面上创建的绘图没有随视觉效果更新。我改了很多次代码,但还是不行。这是更新后的代码:
globals [compliance-threshold-level penalty-rate num-compliant]
turtles-own [sustainability-score is-company? inspected]
to setup
clear-all
set-default-shape turtles "circle"
;; Create companies
create-turtles num-companies [
set is-company? true
set color blue
setxy random-xcor random-ycor
]
;; Create suppliers
create-turtles num-suppliers [
set is-company? false
set sustainability-score random 101
set color green
setxy random-xcor random-ycor
]
;; Set parameters
set compliance-threshold-level 70
set penalty-rate 10
set num-compliant 0
reset-ticks
end
to go
ask turtles with [is-company?] [
inspect-suppliers
check-compliance
]
update-visuals
tick
end
to update-visuals
;; Update the compliance plot
set-current-plot "Compliance Over Time"
clear-plot
plot num-compliant
;; Update the average sustainability score plot
set-current-plot "Average Sustainability Score"
clear-plot
let total-score sum [sustainability-score] of turtles with [not is-company?]
let total-suppliers count turtles with [not is-company?]
let average-score ifelse-value (total-suppliers > 0) [total-score / total-suppliers] [0]
plot average-score
;; Update the supplier score distribution histogram
set-current-plot "Supplier Score Distribution"
clear-plot
histogram [sustainability-score] of turtles with [not is-company?]
end
to inspect-suppliers
let suppliers turtles with [not is-company?]
let num-suppliers count suppliers
;; Determine how many suppliers to inspect
let num-to-inspect min (list 5 num-suppliers)
if num-to-inspect > 0 [
let to-inspect n-of num-to-inspect suppliers
ask to-inspect [
set inspected true
]
]
end
to check-compliance
let inspected-suppliers turtles with [inspected = true and not is-company?]
if any? inspected-suppliers [
let total-score sum [sustainability-score] of inspected-suppliers
let count-inspected count inspected-suppliers
;; Calculate average score
let average-score ifelse-value (count-inspected > 0) [total-score / count-inspected] [0]
;; Compliance check
if average-score >= compliance-threshold-level [
set num-compliant num-compliant + 1
ask turtles with [is-company?] [set color green]
]
if average-score < compliance-threshold-level [
ask turtles with [is-company?] [set color red]
;; Apply penalty ensuring sustainability score doesn't go below 0
ask inspected-suppliers [
set sustainability-score max (list 0 (sustainability-score - penalty-rate))
]
]
;; Reset inspected flag
ask inspected-suppliers [
set inspected false
]
]
end
我认为你的问题不是,绘图没有被更新,而是你在每个刻度中使用
clear-plot
,从而删除了先前刻度的数据。如果您想随时间绘制指标,请省略 clear-plot
!