Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
'''
Create a test non-toroidal grid and populate it with Mock Agents
'''
width = 3
height = 5
self.grid = MultiGrid(width, height, self.torus)
self.agents = []
counter = 0
for x in range(width):
for y in range(height):
for i in range(TEST_MULTIGRID[x][y]):
counter += 1
# Create and place the mock agent
a = MockAgent(counter, None)
self.agents.append(a)
self.grid.place_agent(a, (x, y))
def __init__(self, height, width, agent_count):
'''
Create a new WalkerWorld.
Args:
height, width: World size.
agent_count: How many agents to create.
'''
self.height = height
self.width = width
self.grid = MultiGrid(self.height, self.width, torus=True)
self.agent_count = agent_count
self.schedule = RandomActivation(self)
# Create agents
for i in range(self.agent_count):
x = self.random.randrange(self.width)
y = self.random.randrange(self.height)
a = WalkerAgent((x, y), self, True)
self.schedule.add(a)
self.grid.place_agent(a, (x, y))
def __init__(self, num_agents, x_size, y_size):
abce.Simulation.__init__(self,
name='ABCE and MESA integrated',
rounds=300,
processes=1)
# initialization of the base class. MESA integration requires
# single processing
self.grid = MultiGrid(x_size, y_size, True)
self.agents = self.build_agents(MoneyAgent, 'MoneyAgent', num_agents,
parameters={'grid': self.grid})
# ABCE agents must inherit the MESA grid
self.running = True
# MESA requires this
self.datacollector = DataCollector(
model_reporters={"Gini": compute_gini})
# The data collector collects a certain aggregate value so the graphical
# components can access them
self.wealths = [0 for _ in range(num_agents)]
def project_reward(self, width, height):
global treasury
if treasury > 6:
self.grid = MultiGrid(height, width, True)
x = random.randint(0, self.grid.width-1)
y = random.randint(0, self.grid.height-1)
print("------EMPTY------- = ", self.model.grid.is_cell_empty([x,y]))
if self.model.grid.is_cell_empty([x,y]) == False:
position = (x,y)
print("RECEIVER POSITION = ", position)
potential_receivers = self.model.grid.get_cell_list_contents(position)
receiver = random.choice(potential_receivers)
print("BEFORE REWARD: I OWN THIS MUCH =", receiver.wealth)
receiver.wealth += 2
treasury -= 2
print("AFTER REWARD: I OWN THIS MUCH =", receiver.wealth)
def project_reward(self, width, height):
global treasury
global project_participation
treasury_c = 6
if treasury > treasury_c:
self.grid = MultiGrid(height, width, True)
x = random.randint(0, self.grid.width)
y = random.randint(0, self.grid.height)
#print("EMPTY = ", self.model.grid.is_cell_empty([x,y]))
if self.model.grid.is_cell_empty([x,y]) == False:
position = (x,y)
potential_receivers = self.model.grid.get_cell_list_contents(position)
receiver = random.choice(potential_receivers)
reward_c = 2
receiver.wealth += reward_c
treasury -= reward_c
project_participation += 1
#print("After reward, I own this much =", receiver.wealth)
print("TOTAL PARTICIPANTS = ", project_participation)
def __init__(self, N, width, height):
self.num_agents = N
self.running = True
self.grid = MultiGrid(height, width, True)
self.schedule = RandomActivation(self)
self.datacollector = DataCollector(
model_reporters={"Gini": compute_gini},
agent_reporters={"Wealth": lambda a: a.wealth}
)
# Create agents
for i in range(self.num_agents):
a = WealthAgent(i, self)
self.schedule.add(a)
# Add the agent to a random grid cell
x = random.randrange(self.grid.width)
y = random.randrange(self.grid.height)
self.grid.place_agent(a, (x, y))
def __init__(self, height=50, width=50,
initial_population=100):
'''
Create a new Constant Growback model with the given parameters.
Args:
initial_population: Number of population to start with
'''
# Set parameters
self.height = height
self.width = width
self.initial_population = initial_population
self.schedule = RandomActivationByBreed(self)
self.grid = MultiGrid(self.height, self.width, torus=False)
self.datacollector = DataCollector({"SsAgent": lambda m: m.schedule.get_breed_count(SsAgent), })
# Create sugar
import numpy as np
sugar_distribution = np.genfromtxt("sugarscape_cg/sugar-map.txt")
for _, x, y in self.grid.coord_iter():
max_sugar = sugar_distribution[x, y]
sugar = Sugar((x, y), self, max_sugar)
self.grid.place_agent(sugar, (x, y))
self.schedule.add(sugar)
# Create agent:
for i in range(self.initial_population):
x = random.randrange(self.width)
y = random.randrange(self.height)
sugar = random.randrange(6, 25)
def __init__(self, N, width, height):
self.num_agents = N
self.running = True
self.grid = MultiGrid(height, width, True)
self.schedule = RandomActivation(self)
self.datacollector = DataCollector(
model_reporters={"Gini": compute_gini},
agent_reporters={"Wealth": lambda a: a.wealth}
)
# Create agents
for i in range(self.num_agents):
a = WealthAgent(i, self)
self.schedule.add(a)
# Add the agent to a random grid cell
x = random.randrange(self.grid.width)
y = random.randrange(self.grid.height)
self.grid.place_agent(a, (x, y))