Skip to content

Commit

Permalink
Fix to UpdateLocationAttributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
djgroen committed Nov 23, 2023
1 parent b19115c commit 66b7b59
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion flee/InputGeography.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def ReadAttributeInputCSV(self, attribute_name: str, attribute_type: str, csv_na
self.attributes[attribute_name][headers[i]] = []
else:
for i in range(1, len(row)): # field 0 is day.
# print(row[0])
#print("RAICSV", row[0], row[i], file=sys.stderr)
if attribute_type == "int":
self.attributes[attribute_name][headers[i]].append(int(row[i].strip()))
elif attribute_type == "float":
Expand Down Expand Up @@ -325,6 +325,8 @@ def StoreInputGeographyInEcosystem(self, e):
location_type = "town"

attributes = {}

# Loading of static attributes.
if len(loc) > 8:
for i in range(8, len(loc)):
attributes[self.columns[i]] = loc[i]
Expand Down Expand Up @@ -420,6 +422,10 @@ def UpdateLocationAttributes(self, e, attribute_name: str, time: int) -> None:
loc_name = e.locations[i].name
if loc_name in attrlist:
e.locations[i].attributes[attribute_name] = attrlist[loc_name][time]
print(e.time, loc_name, e.locations[i].attributes, attrlist[loc_name][time], file=sys.stderr)
else:
e.locations[i].attributes[attribute_name] = 0
print(e.time, loc_name, e.locations[i].attributes, file=sys.stderr)


@check_args_type
Expand Down
2 changes: 2 additions & 0 deletions flee/moving.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def getEndPointScore(agent, link) -> float:
# DFlee Flood Location Weight implementation
if SimulationSettings.move_rules["FloodRulesEnabled"] is True:
flood_level = link.endpoint.attributes.get("flood_level",0)
#print("Link:", link.endpoint.name, link.endpoint.attributes, file=sys.stderr)
if flood_level > 0:
base *= float(SimulationSettings.move_rules["FloodLocWeights"][flood_level])

Expand Down Expand Up @@ -260,6 +261,7 @@ def calculateMoveChance(a, ForceTownMove: bool) -> float:
# DFlee Flood Location Movechance implementation
if SimulationSettings.move_rules["FloodRulesEnabled"] is True:
flood_level = a.location.attributes.get("flood_level",0)
#print(a.location.name, a.location.attributes, file=sys.stderr)
if flood_level > 0:
return float(SimulationSettings.move_rules["FloodMovechances"][flood_level])

Expand Down
3 changes: 1 addition & 2 deletions flee/spawning.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,8 @@ def spawn_daily_displaced(e, t, d):
for i in range(0, len(e.locations)):

num_spawned = 0

print(e.locations[i].attributes, file=sys.stderr)
flood_level = e.locations[i].attributes.get("flood_level",0)
#print(e.time, e.locations[i].name, e.locations[i].attributes, file=sys.stderr)
if flood_level > 0:
## BASE RATES
if SimulationSettings.spawn_rules["flood_spawn_mode"] == "constant":
Expand Down

0 comments on commit 66b7b59

Please sign in to comment.