Skip to content

Commit

Permalink
Added support for Flood-driven spawning. No test case yet. #81
Browse files Browse the repository at this point in the history
  • Loading branch information
djgroen committed Aug 26, 2023
1 parent eb13034 commit c7f146f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
11 changes: 6 additions & 5 deletions flee/SimulationSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ def ReadFromYML(ymlfile: str):
SimulationSettings.spawn_rules["camps_are_sinks"] = bool(fetchss(dps, "camps_are_sicks", False)) # Camps can deactivate agents.
SimulationSettings.spawn_rules["read_from_agents_csv_file"] = bool(fetchss(dps, "read_from_agents_csv_file", False)) # Load agents from agents.csv file.


# Setting defaults, to be overwritten right below when needed.
SimulationSettings.spawn_rules["conflict_driven_spawning"] = False # Conflicts provide a direct push factor.
SimulationSettings.spawn_rules["flood_driven_spawning"] = False # Flood provide a direct push factor.

spawn_type = "conflict"
if SimulationSettings.spawn_rules["flood_zone_spawning_only"] is True:
spawn_type = "flood"
Expand All @@ -135,10 +140,8 @@ def ReadFromYML(ymlfile: str):
SimulationSettings.spawn_rules["displaced_per_conflict_day"] = float(fetchss(dpsc,"displaced_per_conflict_day", 0.01))
else:
SimulationSettings.spawn_rules["displaced_per_conflict_day"] = int(fetchss(dpsc,"displaced_per_conflict_day", 500))
else:
SimulationSettings.spawn_rules["conflict_driven_spawning"] = False

elif spawn_type == "flood":
if spawn_type == "flood":
dpsc = fetchss(dps,"flood_driven_spawning",None)
if dpsc is not None:
SimulationSettings.spawn_rules["flood_driven_spawning"] = True # Conflicts provide a direct push factor.
Expand All @@ -149,8 +152,6 @@ def ReadFromYML(ymlfile: str):
SimulationSettings.spawn_rules["displaced_per_flood_day"] = float(fetchss(dpsc,"displaced_per_conflict_day", 0.01))
else:
SimulationSettings.spawn_rules["displaced_per_flood_day"] = int(fetchss(dpsc,"displaced_per_conflict_day", 500))
else:
SimulationSettings.spawn_rules["flood_driven_spawning"] = False


SimulationSettings.spawn_rules["conflict_spawn_decay"] = fetchss(dps,"conflict_spawn_decay", None) # Expect an array or dict
Expand Down
48 changes: 34 additions & 14 deletions flee/spawning.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,28 +143,47 @@ def spawn_daily_displaced(e, t, d, SumFromCamps=False):
"""
new_refs = 0

if SimulationSettings.spawn_rules["conflict_driven_spawning"]:
if SimulationSettings.spawn_rules["conflict_driven_spawning"] is True:

for i in range(0, len(e.locations)):

num_spawned = 0
if e.locations[i].conflict > 0.0:

## BASE RATES
if SimulationSettings.spawn_rules["conflict_spawn_mode"] == "constant":
if e.locations[i].conflict > 0.0:
## BASE RATES
if SimulationSettings.spawn_rules["conflict_spawn_mode"] == "constant":
num_spawned = int(SimulationSettings.spawn_rules["displaced_per_conflict_day"] * e.locations[i].conflict)
else:
num_spawned = 0

elif SimulationSettings.spawn_rules["conflict_spawn_mode"] == "pop_ratio":
if e.locations[i].conflict > 0.0:
elif SimulationSettings.spawn_rules["conflict_spawn_mode"] == "pop_ratio":
num_spawned = int(SimulationSettings.spawn_rules["displaced_per_conflict_day"] * e.locations[i].pop * e.locations[i].conflict)
else:
num_spawned = 0

elif SimulationSettings.spawn_rules["conflict_spawn_mode"].lower() == "Poisson":
if e.locations[i].conflict > 0.0:
elif SimulationSettings.spawn_rules["conflict_spawn_mode"].lower() == "poisson":
num_spawned = np.random.poisson(SimulationSettings.spawn_rules["displaced_per_conflict_day"] * e.locations[i].conflict)

## Doing the actual spawning here.
for j in range(0, num_spawned):
attributes = draw_samples(e, e.locations[i])
e.addAgent(location=e.locations[i], attributes=attributes) # Parallelization is incorporated *inside* the addAgent function.

new_refs = num_spawned


elif SimulationSettings.spawn_rules["flood_driven_spawning"] is True:

for i in range(0, len(e.locations)):

num_spawned = 0

if e.locations[i].attributes["flood_level"] > 0:
## BASE RATES
if SimulationSettings.spawn_rules["flood_spawn_mode"] == "constant":
num_spawned = int(SimulationSettings.spawn_rules["displaced_per_conflict_day"] * e.locations[i].conflict)

elif SimulationSettings.spawn_rules["flood_spawn_mode"] == "pop_ratio":
num_spawned = int(SimulationSettings.spawn_rules["displaced_per_conflict_day"] * e.locations[i].pop * e.locations[i].conflict)

elif SimulationSettings.spawn_rules["flood_spawn_mode"].lower() == "poisson":
num_spawned = np.random.poisson(SimulationSettings.spawn_rules["displaced_per_conflict_day"] * e.locations[i].conflict)
else:
num_spawned = 0

## Doing the actual spawning here.
for j in range(0, num_spawned):
Expand All @@ -173,6 +192,7 @@ def spawn_daily_displaced(e, t, d, SumFromCamps=False):

new_refs = num_spawned


else:

# Determine number of new refugees to insert into the system.
Expand Down

0 comments on commit c7f146f

Please sign in to comment.