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

Agents FSM

This commit is contained in:
Tasio Mendez 2018-05-18 15:38:25 +02:00
parent a0613f8a58
commit 125b7fad42
2 changed files with 23 additions and 22 deletions

View File

@ -1,6 +1,6 @@
import random import random
import networkx as nx import networkx as nx
from soil.agents import BaseAgent, FSM, state from soil.agents import BaseAgent, FSM, state, default_state
from scipy.spatial import cKDTree as KDTree from scipy.spatial import cKDTree as KDTree
global betweenness_centrality_global global betweenness_centrality_global
@ -133,7 +133,7 @@ class TerroristSpreadModel(FSM):
return [ G.nodes()[index]['agent'] for index in nodes ] return [ G.nodes()[index]['agent'] for index in nodes ]
class TrainingAreaModel(BaseAgent): class TrainingAreaModel(FSM):
""" """
Settings: Settings:
training_influence training_influence
@ -150,13 +150,15 @@ class TrainingAreaModel(BaseAgent):
self.min_vulnerability = environment.environment_params['min_vulnerability'] self.min_vulnerability = environment.environment_params['min_vulnerability']
else: self.min_vulnerability = 0 else: self.min_vulnerability = 0
def step(self): @default_state
@state
def terrorist(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(FSM):
""" """
Settings: Settings:
haven_influence haven_influence
@ -176,23 +178,22 @@ class HavenModel(BaseAgent):
else: self.min_vulnerability = 0 else: self.min_vulnerability = 0
self.max_vulnerability = environment.environment_params['max_vulnerability'] self.max_vulnerability = environment.environment_params['max_vulnerability']
def step(self): @state
civilian_haven = False def civilian(self):
if self.state['id'] == 0: for neighbour_agent in self.get_neighboring_agents():
for neighbour_agent in self.get_neighboring_agents(): if isinstance(neighbour_agent, TerroristSpreadModel) and neighbour_agent['id'] == neighbour_agent.civilian.id:
if isinstance(neighbour_agent, TerroristSpreadModel) and neighbour_agent['id'] == neighbor_agent.civilian.id: for neighbour in self.get_neighboring_agents():
civilian_haven = True if isinstance(neighbour, TerroristSpreadModel) and neighbour.vulnerability > self.min_vulnerability:
neighbour.vulnerability = neighbour.vulnerability * ( 1 - self.haven_influence )
return self.civilian
return self.terrorist
if civilian_haven: @state
self.state['id'] = 0 # Civilian Haven def terrorist(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.max_vulnerability:
neighbour.vulnerability = neighbour.vulnerability * ( 1 - self.haven_influence ) neighbour.vulnerability = neighbour.vulnerability ** ( 1 - self.haven_influence )
else: return self.terrorist
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 )
class TerroristNetworkModel(TerroristSpreadModel): class TerroristNetworkModel(TerroristSpreadModel):

View File

@ -1,6 +1,6 @@
name: TerroristNetworkModel_sim name: TerroristNetworkModel_sim
load_module: TerroristNetworkModel load_module: TerroristNetworkModel
max_time: 100 max_time: 100
num_trials: 1 num_trials: 1
network_params: network_params:
generator: random_geometric_graph generator: random_geometric_graph