【发布时间】:2020-11-06 22:20:05
【问题描述】:
我正在编写一个关于房地产市场及其政治影响的 NetLogo 模型。模型中有两个品种:家庭和房屋。在我的开发中,我遇到困难的一个早期步骤是让家庭通过嵌套条件语句定义的两种类型的链接(拥有或租用)之一与房屋匹配。这导致了我至今无法克服的两个困难。
- 在命令
setup-market命令中,我试图为每个家庭定义一组可能购买的房屋,如果满足一组条件,则家庭购买(并创建link)。如果它买不起,它就会尝试租用。如果租不起的家庭会die。
我的代码不断导致以下错误:
IFELSE expected input to be a TRUE/FALSE but got the turtle (house XXX) instead.
- 我在后面的代码中也遇到了另一个问题(在用“;”注释掉的两行中),我尝试将变量
owner-occupied和renter设置为1,基于存在适当的链接(它们应保持为 0,如果保持未链接,则该家庭应死亡)。
完整的代码如下。带有“;; 这是给我带来麻烦的行”的行表示错误似乎发生在哪里。
更新:
代码已使用 JenB 的解决方案进行了更新。产生的错误现在是:
CREATE-LINK-WITH expected input to be a turtle but got NOBODY instead. 出现在以下行:create-link-with one-of potentialHomes [ set color red
undirected-link-breed [own-links own-link]
undirected-link-breed [rent-links rent-link]
breed [city-centers city-center]
breed [households household]
households-own
[
age
money
income
monthly-income
consumption
monthly-consumption
hh-size race
preference
net-income
net-monthly-income
myHouse
]
breed [houses house]
houses-own
[
cost
down-payment
mortgage-payment
rent
rent-premium
rooms
onMarket
owner-occupied
rental
onMarket?
]
patches-own [
seed? ;;district seed
district ;;district number
full? ;;is the district at capacity?
quadrant
]
to setup
clear-all
reset-ticks
setup-patches
set-default-shape households "person"
create-households num-households [ setxy random-xcor random-ycor ]
set-default-shape houses "house"
create-houses num-houses [ setxy random-xcor random-ycor ]
setup-households
setup-houses
setup-market
generate-cities
end
to generate-cities
let center-x random-xcor / 1.5 ;;keep cities away from edges
let center-y random-ycor / 1.5
end
to setup-patches
ask patches with [pxcor > 0 and pycor > 0] [set quadrant 1 set pcolor 19 ]
ask patches with [pxcor > 0 and pycor < 0] [set quadrant 2 set pcolor 49 ]
ask patches with [pxcor < 0 and pycor < 0] [set quadrant 3 set pcolor 139 ]
ask patches with [pxcor < 0 and pycor > 0] [set quadrant 4 set pcolor 89 ]
end
to setup-households
ask households
[ set age random-poisson 38
set money random-exponential 30600
set income random-exponential 64324
set monthly-income income / 12
set consumption .5 * income
set monthly-consumption consumption / 12
set hh-size random 6 + 1
set net-income income - consumption
set net-monthly-income monthly-income - monthly-consumption
]
end
to setup-houses
ask houses
[ set cost random-normal 300000 50000
set down-payment cost * down-payment-rate
set mortgage-payment (cost - down-payment) / 360
set rooms random-exponential 3
set onMarket 1
set rent mortgage-payment + mortgage-payment * .25
set owner-occupied 0
set rental 0
]
end
to setup-market
ask houses
[ set onMarket? TRUE ]
ask households
[ ifelse any? houses with [ [money] of myself > down-payment and [net-monthly-income] of myself > mortgage-payment ]
[ let potentialHomes houses with [[money] of myself > cost and onMarket? ]
create-link-with one-of potentialHomes [
set color red
]
]
[
ifelse any? houses with [ [net-monthly-income] of myself > rent]
[ let potentialRentals houses with [ [net-monthly-income] of myself > rent and onMarket? ]
create-link-with one-of potentialRentals [ set color blue ]
]
[ die ]
]
]
ask houses
[ if any? link-neighbors [set onMarket FALSE ]
;if any? link-neighbors and color red [ set owner-occupied 1 ]
;if any? link-neighbors and color blue [ set rental 1 ]
]
end
to go
move-households
tick
end
to move-households
ask households [
move-to myHouse
]
end
【问题讨论】:
标签: netlogo agent-based-modeling