Skip to content

Commit

Permalink
Merge branch 'new_spaces' of https://github.com/quaquel/mesa-examples
Browse files Browse the repository at this point in the history
…into new_spaces
  • Loading branch information
quaquel committed Oct 7, 2024
2 parents 65fc178 + 322023b commit 8e9ed05
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions examples/hotelling_law/hotelling_law/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,15 @@ def determine_preferred_store(self):
for store in stores:
# Calculate score based on consumer preference
if consumer_preference == "proximity":
score = self.euclidean_distance(self.cell.coordinate, store.cell.coordinate)
score = self.euclidean_distance(
self.cell.coordinate, store.cell.coordinate
)
elif consumer_preference == "price":
score = store.price
else: # Default case includes both proximity and price
score = store.price + self.euclidean_distance(self.cell.coordinate, store.cell.coordinate)
score = store.price + self.euclidean_distance(
self.cell.coordinate, store.cell.coordinate
)

# Update the list of best stores if a new minimum score is found
if score < min_score:
Expand Down
4 changes: 2 additions & 2 deletions examples/hotelling_law/hotelling_law/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def _initialize_agents(self):
# Randomly place agents on the grid for a grid environment.
x = self.random.randrange(self.grid.dimensions[0])
y = self.random.randrange(self.grid.dimensions[1])
agent.cell = self.grid[(x,y)]
agent.cell = self.grid[(x, y)]

# Place consumer agents
for _ in range(self.num_consumers):
Expand All @@ -200,7 +200,7 @@ def _initialize_agents(self):
# Place consumer randomly on the grid
x = self.random.randrange(self.grid.dimensions[0])
y = self.random.randrange(self.grid.dimensions[1])
consumer.cell = self.grid[(x,y)]
consumer.cell = self.grid[(x, y)]

# Method to advance the simulation by one step.
def step(self):
Expand Down

0 comments on commit 8e9ed05

Please sign in to comment.