Skip to content

Commit

Permalink
DFlee Flood rules for move chances implemented. #81
Browse files Browse the repository at this point in the history
  • Loading branch information
djgroen committed Aug 27, 2023
1 parent 3e9437e commit 6b9d147
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion flee/SimulationSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,25 @@ def ReadFromYML(ymlfile: str):
for a in ["ChildrenAvoidHazards", "BoysTakeRisk", "MatchCampEthnicity", "MatchTownEthnicity", "MatchConflictEthnicity"]:
SimulationSettings.move_rules[a] = bool(fetchss(dpr,a,False))


# DFlee Flood Location Move rules
dpf = fetchss(dp, "flood_rules", None)
if dpf is not None:
SimulationSettings.move_rules["FloodRulesEnabled"] = True
SimulationSettings.spawn_rules["MaxFloodLevel"] = int(fetchss(dpf,"max_flood_level", -1))

# Move rules
# FloodMovechances *override* move chances when flood level is higher than 0.
SimulationSettings.move_rules["FloodMovechances"] = fetchss(dps,"flood_movechances", None) # Expect an array or dict
print("Flood Movechances set to:", SimulationSettings.spawn_rules["FloodMovechances"], file=sys.stderr)

# FloodLocWeights *multiply* existing location weights when flood level is higher than 0.
SimulationSettings.move_rules["FloodLocWeights"] = fetchss(dps,"flood_loc_weights", None) # Expect an array or dict
print("Flood Location Weights set to:", SimulationSettings.spawn_rules["FloodLocWeights"], file=sys.stderr)

# FloodLinkWeights *multiply* existing link weights when flood level is higher than 0.
SimulationSettings.move_rules["FloodLinkWeights"] = fetchss(dps,"flood_link_weights", None) # Expect an array or dict
print("Flood Link Weights set to:", SimulationSettings.spawn_rules["FloodLinkWeights"], file=sys.stderr)
print("Note: Flood Link Weights are not supported yet in this version of DFlee.")

#TODO: Add verification code.

Expand Down
7 changes: 7 additions & 0 deletions flee/moving.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,15 @@ def calculateMoveChance(a, ForceTownMove: bool) -> float:
return 1.0
else: # called first time in loop
movechance = a.location.movechance
# Population-based scaling
movechance *= (float(max(a.location.pop, a.location.capacity)) / SimulationSettings.move_rules["MovechancePopBase"])**SimulationSettings.move_rules["MovechancePopScaleFactor"]

# DFlee Flood Location Movechance implementation
if SimulationSettings.move_rules["FloodRulesEnabled"] is True:
flood_level = a.location.attributes.get("flood_level",0)
if flood_level > 0:
return float(SimulationSettings.move_rules["FloodMovechances"][flood_level])

return movechance


Expand Down
2 changes: 1 addition & 1 deletion tests/test_dflee.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_flood_level_location_attribute():
flee.SimulationSettings.ReadFromYML("empty.yml")
flee.SimulationSettings.move_rules["FloodRulesEnabled"] = True
flee.SimulationSettings.move_rules["FloodLocWeights"] = [0.0,1.0,1.0,1.0,1.0]
flee.SimulationSettings.move_rules["FloodMoveChances"] = [0.0,1.0,1.0,1.0,1.0]
flee.SimulationSettings.move_rules["FloodMovechances"] = [0.0,1.0,1.0,1.0,1.0]

e = flee.Ecosystem()

Expand Down

0 comments on commit 6b9d147

Please sign in to comment.