1
0
mirror of https://github.com/gsi-upm/soil synced 2024-11-22 19:22:29 +00:00

Bug havens fixed

This commit is contained in:
Tasio Mendez 2018-05-03 18:58:49 +02:00
parent b73b82a04a
commit 9004fa16ea

View File

@ -162,7 +162,7 @@ class TrainingAreaModel(BaseAgent):
def step(self): def step(self):
for neighbour in self.get_neighboring_agents(): for neighbour in self.get_neighboring_agents():
if isinstance(neighbour, TerroristSpreadModel) and neighbour.vulnerability > self.min_vulnerability: if isinstance(neighbour, TerroristSpreadModel) and neighbour.vulnerability > self.min_vulnerability:
neighbour.vulnerability = neighbour.vulnerability * ( 1 - self.training_influence ) neighbour.vulnerability = neighbour.vulnerability ** ( 1 - self.training_influence )
class HavenModel(BaseAgent): class HavenModel(BaseAgent):
@ -170,6 +170,8 @@ class HavenModel(BaseAgent):
Settings: Settings:
haven_influence haven_influence
min_vulnerability
max_vulnerability max_vulnerability
Requires TerroristSpreadModel. Requires TerroristSpreadModel.
@ -178,19 +180,24 @@ class HavenModel(BaseAgent):
def __init__(self, environment=None, agent_id=0, state=()): def __init__(self, environment=None, agent_id=0, state=()):
super().__init__(environment=environment, agent_id=agent_id, state=state) super().__init__(environment=environment, agent_id=agent_id, state=state)
self.haven_influence = environment.environment_params['haven_influence'] self.haven_influence = environment.environment_params['haven_influence']
if 'min_vulnerability' in environment.environment_params:
self.min_vulnerability = environment.environment_params['min_vulnerability']
else: self.min_vulnerability = 0
self.max_vulnerability = environment.environment_params['max_vulnerability'] self.max_vulnerability = environment.environment_params['max_vulnerability']
def step(self): def step(self):
if self.count_neighboring_agents(state_id=0) == 0: if self.count_neighboring_agents(state_id=0) == 0:
self.state['id'] = 1 # Terrorism Haven self.state['id'] = 1 # Terrorism Haven
for neighbour in self.get_neighboring_agents():
if isinstance(neighbour, TerroristSpreadModel) and neighbour.vulnerability < self.max_vulnerability:
neighbour.vulnerability = neighbour.vulnerability ** ( 1 - self.haven_influence )
else: else:
self.state['id'] = 0 # Civilian Haven self.state['id'] = 0 # Civilian Haven
for neighbour in self.get_neighboring_agents():
if isinstance(neighbour, TerroristSpreadModel) and neighbour.vulnerability > self.min_vulnerability:
neighbour.vulnerability = neighbour.vulnerability * ( 1 - self.training_influence )
for neighbour in self.get_neighboring_agents():
if isinstance(neighbour, TerroristSpreadModel) and neighbour.vulnerability < self.max_vulnerability:
neighbour.vulnerability = neighbour.vulnerability ** ( 1 - self.haven_influence )
class TerroristNetworkModel(TerroristSpreadModel): class TerroristNetworkModel(TerroristSpreadModel):
""" """
Settings: Settings: