Skip to content

Commit

Permalink
Fixed bug that slowed down spawning.
Browse files Browse the repository at this point in the history
  • Loading branch information
djgroen committed Oct 12, 2023
1 parent a2fb083 commit b27429b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
18 changes: 3 additions & 15 deletions flee/flee.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,20 +1212,6 @@ def set_conflict_intensity(self, name: str, conflict_intensity: float, change_mo
self.add_conflict_zone(name, conflict_intensity, change_movechance)


@check_args_type
def pick_spawn_location(self):
"""
Summary
!!! warning
this function is now deprecated as of ruleset 2.0.
Please use `pick_spawn_locations()` instead in your scripts
Returns:
Location: Description
"""
return self.pick_spawn_locations(1)[0]

@check_args_type
def pick_spawn_locations(self, number: int = 1) -> list:
"""
Expand All @@ -1243,8 +1229,10 @@ def pick_spawn_locations(self, number: int = 1) -> list:

assert spawn_weight_total > 0

wgt = self.spawn_weights / spawn_weight_total

return np.random.choice(
self.locations, number, p=self.spawn_weights / spawn_weight_total
self.locations, number, p=wgt
).tolist()


Expand Down
6 changes: 3 additions & 3 deletions flee/spawning.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ def spawn_daily_displaced(e, t, d):
__refugee_debt = 0

#Insert refugee agents
locs = e.pick_spawn_locations(new_refs)
for i in range(0, new_refs):
loc = e.pick_spawn_location()
attributes = draw_samples(e, loc)
e.addAgent(location=loc, attributes=attributes) # Parallelization is incorporated *inside* the addAgent function.
attributes = draw_samples(e, locs[i])
e.addAgent(location=locs[i], attributes=attributes) # Parallelization is incorporated *inside* the addAgent function.

return new_refs, __refugees_raw, __refugee_debt

Expand Down

0 comments on commit b27429b

Please sign in to comment.