mirror of
https://github.com/gsi-upm/soil
synced 2024-11-14 15:32:29 +00:00
Agents FSM
This commit is contained in:
parent
a0613f8a58
commit
125b7fad42
@ -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):
|
||||||
|
Loading…
Reference in New Issue
Block a user