From 1083112473ef985d03b3120a73cac85354d22b52 Mon Sep 17 00:00:00 2001 From: Tasio Mendez Date: Thu, 3 May 2018 19:49:51 +0200 Subject: [PATCH] TerroristNetworkModel improved --- TerroristNetworkModel.py | 20 +++++++++++++------- TerroristNetworkModel.yml | 6 +++--- templates/js/socket.js | 2 +- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/TerroristNetworkModel.py b/TerroristNetworkModel.py index 9290ae6..182726d 100644 --- a/TerroristNetworkModel.py +++ b/TerroristNetworkModel.py @@ -186,16 +186,22 @@ class HavenModel(BaseAgent): self.max_vulnerability = environment.environment_params['max_vulnerability'] def step(self): - if self.count_neighboring_agents(state_id=0) == 0: - 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: + civilian_haven = False + if self.state['id'] == 0: + for neighbour_agent in self.get_neighboring_agents(): + if isinstance(neighbour_agent, TerroristSpreadModel) and neighbour_agent.state['id'] == 0: + civilian_haven = True + + if 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.haven_influence ) + else: + 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): @@ -234,7 +240,7 @@ class TerroristNetworkModel(TerroristSpreadModel): social_distance = 1 / self.shortest_path_length(self.global_topology, self.id, agent.id) spatial_proximity = ( 1 - self.get_distance(self.global_topology, self.id, agent.id) ) prob_new_interaction = self.weight_social_distance * social_distance + self.weight_link_distance * spatial_proximity - if random.random() < prob_new_interaction: + if agent.state['id'] == 0 and random.random() < prob_new_interaction: self.add_edge(self.global_topology, self, agent) break diff --git a/TerroristNetworkModel.yml b/TerroristNetworkModel.yml index 702fc20..fad080d 100644 --- a/TerroristNetworkModel.yml +++ b/TerroristNetworkModel.yml @@ -1,13 +1,13 @@ name: TerroristNetworkModel_sim load_module: TerroristNetworkModel -max_time: 500 +max_time: 200 num_trials: 1 network_params: generator: random_geometric_graph radius: 0.2 # generator: geographical_threshold_graph # theta: 20 - n: 150 + n: 100 network_agents: - agent_type: TerroristNetworkModel weight: 0.8 @@ -30,7 +30,7 @@ environment_params: # TerroristSpreadModel information_spread_intensity: 0.7 terrorist_additional_influence: 0.035 - max_vulnerability: 0.6 + max_vulnerability: 0.7 prob_interaction: 0.5 # TrainingAreaModel and HavenModel diff --git a/templates/js/socket.js b/templates/js/socket.js index 94e0005..a490116 100755 --- a/templates/js/socket.js +++ b/templates/js/socket.js @@ -271,7 +271,7 @@ var set_timeline = function(graph) { .attr('width', d3.select('svg #root > image').node().getBBox().width) .attr('height', d3.select('svg #root > image').node().getBBox().height); } - }, 500); + }, 1000); }); // 'Speed' slider