Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions BoltzmannWealth/Agents/BolzmannWealth.jl
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions BoltzmannWealth/Mesa/BoltzmannWealth.py
Original file line number Diff line number Diff line change
@@ -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()
Loading