将另一只的 ID 添加到另一只的属性中

  • 本文关键字:一只 属性 ID 添加 netlogo
  • 更新时间 :
  • 英文 :


在下面的模型中,银行只能为信用评分与其acceptable_scores属性中的评分相匹配的客户提供资金。如果它不符合任何银行的acceptable_scores,它将被拒绝。

globals [
scores
]
breed [ customers customer ]
breed [ banks bank ]
customers-own [
loan_amount
credit_score
status
]
banks-own [
acceptable_scores
list_of_customers
]
to setup
clear-all
ask patches [ set pcolor 8 ]
set scores n-values 10 [random 900 + 10]
create-customers 100 [
set loan_amount random-exponential 20000
set credit_score one-of scores
set status "applied"
]
create-banks 10 [
set acceptable_scores n-of (random 3 + 1) scores
set list_of_customers []
]
reset-ticks
end
to go
ask one-of banks [
fund-loan
reject-loan
]
tick
end
to fund-loan
let person one-of customers-here with [
(member? credit_score [acceptable_scores] of myself)
]
if person != nobody  [
ask person [ 
set status "funded"
]
set list_of_customers lput person list_of_customers
]
end
to reject-loan
let person one-of customers-here with [
(not member? credit_score [acceptable_scores] of myself)
]
if person != nobody  [
ask person [ 
set status "funded"
]
set list_of_customers lput person list_of_customers
output-print list_of_customers
]
end

我想在这里将每个资助的客户添加到资助后的list_of_customers中:

set list_of_customers lput person list_of_customers

,但是打印出来的时候列表总是空的。将另一只海龟的id添加到另一只海龟的属性的正确方法是什么?一般来说,这是处理资助和拒绝程序的最佳方式吗?它能在一个函数中完成吗?

这是使用agentsets的模型的简化版本。银行的行为可能不完全是你想要的,但它应该让你开始。

globals [
scores
]
breed [ customers customer ]
breed [ banks bank ]
customers-own [
loan_amount
credit_score
status
]
banks-own [
acceptable_scores
my_customers
]
to setup
clear-all
ask patches [ set pcolor 8 ]
set scores n-values 10 [random 900 + 10]
create-customers 100 [
set loan_amount random-exponential 20000
set credit_score one-of scores
set status "applied"
]
create-banks 10 [
set acceptable_scores n-of (random 3 + 1) scores
set my_customers no-turtles
]
reset-ticks
end
to go
ask banks [
fund-loan
]

ask banks [ show my_customers ]
tick
end
to fund-loan
let person one-of customers-here 
ifelse (member? [credit_score] of person acceptable_scores) and ([status] of person != "funded")  [
ask person [
set status "funded"
]
set my_customers (turtle-set person my_customers)
]
[
ask person [
set status "rejected"
]
]
end

最新更新