'Values are set randomly and not as specified by the code
I am trying to specify a variable based on the value of another variable. However, the line of coding shown below, it is not working correctly. The values of "price-sensitivity" are set randomly, and not as specified by the code.
I don't know where I have gone wrong. Please help!
breed[households household]
links-own [strength
]
households-own [income
price-sensitivity
]
to setup
clear-all
create-households 1000
create-income
create-sensitivity
end
to create-income ; Three main categories <20'000, 20'000 - 40'000, >40'000
ask n-of (0.3 * 1000) households [set income 1001 + random 19000]
ask n-of (0.5 * 1000) households [set income 20001 + random 20000]
ask n-of (0.2 * 1000) households [set income 40001 + random 60000]
ask households [if any? households with [income = 0] [set income 1001 + random 90000]]
end
to create-sensitivity ; Low Sensitivity=-10 High Sensitivity=10
ask households [if income <= 20000 [set price-sensitivity (1 + random 10)]
if income > 20000 or income <= 40000 [set price-sensitivity (-8 + random 10)]
if income > 40000 [set price-sensitivity (3 + random -13)]]
ask households [if price-sensitivity = 0 [set price-sensitivity (-1 + random -9)]]
end
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
