Last active
March 14, 2020 20:04
-
-
Save lifedispenser/3a9a3433551a324097829e9bedc1132a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person extends IdyllModel | |
belongs_to :working_population | |
define_attribute :stress, type: integer, min: 0, max: 100, init: random | |
define_attribute :environment, type: enum, ['high income', 'low income', 'normal'] | |
define_attribute :group, type: classification, |model| => { case model.stress; when 50..100: "high risk"; when 0..49: "low risk" } | |
def next_step | |
self.stress += 5 if self.environment == "high income" | |
self.stress -= 5 if self.environment == "low income" | |
end | |
end | |
class WorkingPopulation extends IdyllPopulation | |
populate_with :persons, amount: 100 | |
is_step_function step_unit: "years" | |
def next_step | |
persons.each do |p| | |
p.environment = "normal" if chance(.03) | |
p.environment = "high income" if chance(.01) | |
end | |
end | |
end | |
@base_model = new WorkingPopulation() | |
@base_model.render |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment