将另一只海龟的 id 添加到另一只海龟的属性
add another turtle's id to another turtle's attribute
在下面的模型中,银行只能为信用评分与其 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 添加到另一只乌龟的属性的正确方法是什么?一般来说,这是处理资助和拒绝程序的最佳方式吗?可以在一个函数中完成吗?
这是使用代理集的模型的 pared-down 版本。银行行为可能不是您想要的,但它应该让您入门。
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
在下面的模型中,银行只能为信用评分与其 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 添加到另一只乌龟的属性的正确方法是什么?一般来说,这是处理资助和拒绝程序的最佳方式吗?可以在一个函数中完成吗?
这是使用代理集的模型的 pared-down 版本。银行行为可能不是您想要的,但它应该让您入门。
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