diff --git a/.github/setup.sh b/.github/setup.sh index 4fb70ff..bea6f2f 100755 --- a/.github/setup.sh +++ b/.github/setup.sh @@ -20,7 +20,7 @@ julia --project=@. -e 'using Pkg; Pkg.instantiate()' # install mesa sudo apt install python3-pip -pip install mesa==2.1.4 +pip install mesa==2.4.0 # install netlogo sudo wget http://ccl.northwestern.edu/netlogo/6.4.0/NetLogo-6.4.0-64.tgz diff --git a/BoltzmannWealth/Agents/BolzmannWealth.jl b/BoltzmannWealth/Agents/BolzmannWealth.jl new file mode 100644 index 0000000..5ef9979 --- /dev/null +++ b/BoltzmannWealth/Agents/BolzmannWealth.jl @@ -0,0 +1,21 @@ +using Agents + + +@agent struct WealthAgent(NoSpaceAgent) + wealth::Int +end + +function wealth_model(; numagents = 100, initwealth = 1) + model = ABM(WealthAgent; agent_step!, scheduler = Schedulers.Randomly(), + rng = Xoshiro(42), container = Vector) + for _ in 1:numagents + add_agent!(model, initwealth) + end + return model +end + +function agent_step!(agent, model) + agent.wealth <= 0 && return + agent.wealth -= 1 + random_agent(model).wealth += 1 +end diff --git a/BoltzmannWealth/Mesa/BoltzmannWealth.py b/BoltzmannWealth/Mesa/BoltzmannWealth.py new file mode 100644 index 0000000..6fd7456 --- /dev/null +++ b/BoltzmannWealth/Mesa/BoltzmannWealth.py @@ -0,0 +1,38 @@ + + +class MoneyAgent(mesa.Agent): + """An agent with fixed initial wealth.""" + + def __init__(self, unique_id, model): + # Pass the parameters to the parent class. + super().__init__(unique_id, model) + + # Create the agent's variable and set the initial values. + self.wealth = 1 + + def step(self): + # Verify agent has some wealth + if self.wealth > 0: + other_agent = self.random.choice(self.model.agents) + other_agent.wealth += 1 + self.wealth -= 1 + + +class MoneyModel(mesa.Model): + """A model with some number of agents.""" + + def __init__(self, N): + super().__init__() + self.num_agents = N + # Create scheduler and assign it to the model + self.agents = [MoneyAgent(i, self) for i in range(self.num_agents)] + + def step(self): + """Advance the model by one step.""" + self.random.shuffle(self.agents) + for agent in self.agents: + agent.step() + + def run_model(self, n_steps) -> None: + for _ in range(n_steps): + self.step()