diff --git a/__pycache__/clase_base.cpython-34.pyc b/__pycache__/clase_base.cpython-34.pyc
deleted file mode 100644
index 0ea739f..0000000
Binary files a/__pycache__/clase_base.cpython-34.pyc and /dev/null differ
diff --git a/__pycache__/models.cpython-34.pyc b/__pycache__/models.cpython-34.pyc
deleted file mode 100644
index 0aa6cd0..0000000
Binary files a/__pycache__/models.cpython-34.pyc and /dev/null differ
diff --git a/__pycache__/settings.cpython-34.pyc b/__pycache__/settings.cpython-34.pyc
deleted file mode 100644
index b9fc86e..0000000
Binary files a/__pycache__/settings.cpython-34.pyc and /dev/null differ
diff --git a/docs/_build/doctrees/environment.pickle b/docs/_build/doctrees/environment.pickle
index b32a537..b3f8a4c 100644
Binary files a/docs/_build/doctrees/environment.pickle and b/docs/_build/doctrees/environment.pickle differ
diff --git a/docs/_build/doctrees/models.doctree b/docs/_build/doctrees/models.doctree
index 1b705ba..30136fa 100644
Binary files a/docs/_build/doctrees/models.doctree and b/docs/_build/doctrees/models.doctree differ
diff --git a/docs/_build/doctrees/usage.doctree b/docs/_build/doctrees/usage.doctree
index 363cdae..4ef69f3 100644
Binary files a/docs/_build/doctrees/usage.doctree and b/docs/_build/doctrees/usage.doctree differ
diff --git a/docs/_build/html/_sources/models.rst.txt b/docs/_build/html/_sources/models.rst.txt
index 654effb..d179d7b 100644
--- a/docs/_build/html/_sources/models.rst.txt
+++ b/docs/_build/html/_sources/models.rst.txt
@@ -9,7 +9,7 @@ A model defines the behaviour of the agents with a view to assessing their effec
In practice, a model consists of at least two parts:
* Python module: the actual code that describes the behaviour.
-* Setting up the variables in the Simulation Settings JSON file.
+* Setting up the variables in the Settings JSON file.
This separation allows us to run the simulation with different agents.
@@ -25,10 +25,10 @@ All the models are imported to the main file. The initialization look like this:
networkStatus = {} # Dict that will contain the status of every agent in the network
sentimentCorrelationNodeArray = []
- for x in range(0, settings.number_of_nodes):
+ for x in range(0, settings.network_params["number_of_nodes"]):
sentimentCorrelationNodeArray.append({'id': x})
# Initialize agent states. Let's assume everyone is normal.
- init_states = [{'id': 0, } for _ in range(settings.number_of_nodes)]
+ init_states = [{'id': 0, } for _ in range(settings.network_params["number_of_nodes"])]
# add keys as as necessary, but "id" must always refer to that state category
A new model have to inherit the BaseBehaviour class which is in the same module.
@@ -77,7 +77,7 @@ passed as a parameter to the simulation.
}
In this file you will also define the models you are going to simulate. You can simulate as many models as you want.
-The simulation returns one result for each model. For the usage, see :doc:`usage`.
+The simulation returns one result for each model, executing each model separately. For the usage, see :doc:`usage`.
Example Model
=============
diff --git a/docs/_build/html/_sources/usage.rst.txt b/docs/_build/html/_sources/usage.rst.txt
index 4d61fe2..17b3291 100644
--- a/docs/_build/html/_sources/usage.rst.txt
+++ b/docs/_build/html/_sources/usage.rst.txt
@@ -8,18 +8,19 @@ Simulation Settings
Once installed, before running a simulation, you need to configure it.
-* In the settings.py file you will find the configuration of the network.
+* In the Settings JSON file you will find the configuration of the network.
.. code:: python
- # Network settings
- network_type = 1
- number_of_nodes = 1000
- max_time = 50
- num_trials = 1
- timeout = 2
+ {
+ "network_type": 1,
+ "number_of_nodes": 1000,
+ "max_time": 50,
+ "num_trials": 1,
+ "timeout": 2
+ }
-* In the Simulation Settings JSON file, you will find the configuration of the models.
+* In the Settings JSON file, you will also find the configuration of the models.
Network Types
=============
@@ -40,7 +41,7 @@ Models Settings
===============
After having configured the simulation, the next step is setting up the variables of the models.
-For this, you will need to modify the Simulation Settings JSON file.
+For this, you will need to modify the Settings JSON file again.
.. code:: json
@@ -76,7 +77,7 @@ For this, you will need to modify the Simulation Settings JSON file.
}
In this file you will define the different models you are going to simulate. You can simulate as many models
-as you want.
+as you want. Each model will be simulated separately.
After setting up the models, you have to initialize the parameters of each one. You will find the parameters needed
in the documentation of each model.
@@ -90,7 +91,7 @@ After setting all the configuration, you will be able to run the simulation. All
.. code:: bash
- python soil.py
+ python3 soil.py
The simulation will return a dynamic graph .gexf file which could be visualized with
`Gephi
This separation allows us to run the simulation with different agents.
@@ -63,10 +63,10 @@ In practice, a model consists of at least two parts: networkStatus = {} # Dict that will contain the status of every agent in the network sentimentCorrelationNodeArray = [] -for x in range(0, settings.number_of_nodes): +for x in range(0, settings.network_params["number_of_nodes"]): sentimentCorrelationNodeArray.append({'id': x}) # Initialize agent states. Let's assume everyone is normal. -init_states = [{'id': 0, } for _ in range(settings.number_of_nodes)] +init_states = [{'id': 0, } for _ in range(settings.network_params["number_of_nodes"])] # add keys as as necessary, but "id" must always refer to that state category @@ -114,7 +114,7 @@ passed as a parameter to the simulation.In this file you will also define the models you are going to simulate. You can simulate as many models as you want. -The simulation returns one result for each model. For the usage, see Usage.
+The simulation returns one result for each model, executing each model separately. For the usage, see Usage.Once installed, before running a simulation, you need to configure it.
In the settings.py file you will find the configuration of the network.
-# Network settings
-network_type = 1
-number_of_nodes = 1000
-max_time = 50
-num_trials = 1
-timeout = 2
+
In the Settings JSON file you will find the configuration of the network.
+{
+ "network_type": 1,
+ "number_of_nodes": 1000,
+ "max_time": 50,
+ "num_trials": 1,
+ "timeout": 2
+}
In the Simulation Settings JSON file, you will find the configuration of the models.
+In the Settings JSON file, you will also find the configuration of the models.
After having configured the simulation, the next step is setting up the variables of the models. -For this, you will need to modify the Simulation Settings JSON file.
+For this, you will need to modify the Settings JSON file again.{
"agent": ["SISaModel","ControlModelM2"],
@@ -114,7 +115,7 @@ For this, you will need to modify the Simulation Settings JSON file.
In this file you will define the different models you are going to simulate. You can simulate as many models -as you want.
+as you want. Each model will be simulated separately.After setting up the models, you have to initialize the parameters of each one. You will find the parameters needed in the documentation of each model.
Parameter validation will fail if a required parameter without a default has not been provided.
@@ -122,7 +123,7 @@ in the documentation of each model.After setting all the configuration, you will be able to run the simulation. All you need to do is execute:
-python soil.py
+python3 soil.py
The simulation will return a dynamic graph .gexf file which could be visualized with
diff --git a/docs/models.rst b/docs/models.rst
index 654effb..d179d7b 100644
--- a/docs/models.rst
+++ b/docs/models.rst
@@ -9,7 +9,7 @@ A model defines the behaviour of the agents with a view to assessing their effec
In practice, a model consists of at least two parts:
* Python module: the actual code that describes the behaviour.
-* Setting up the variables in the Simulation Settings JSON file.
+* Setting up the variables in the Settings JSON file.
This separation allows us to run the simulation with different agents.
@@ -25,10 +25,10 @@ All the models are imported to the main file. The initialization look like this:
networkStatus = {} # Dict that will contain the status of every agent in the network
sentimentCorrelationNodeArray = []
- for x in range(0, settings.number_of_nodes):
+ for x in range(0, settings.network_params["number_of_nodes"]):
sentimentCorrelationNodeArray.append({'id': x})
# Initialize agent states. Let's assume everyone is normal.
- init_states = [{'id': 0, } for _ in range(settings.number_of_nodes)]
+ init_states = [{'id': 0, } for _ in range(settings.network_params["number_of_nodes"])]
# add keys as as necessary, but "id" must always refer to that state category
A new model have to inherit the BaseBehaviour class which is in the same module.
@@ -77,7 +77,7 @@ passed as a parameter to the simulation.
}
In this file you will also define the models you are going to simulate. You can simulate as many models as you want.
-The simulation returns one result for each model. For the usage, see :doc:`usage`.
+The simulation returns one result for each model, executing each model separately. For the usage, see :doc:`usage`.
Example Model
=============
diff --git a/docs/usage.rst b/docs/usage.rst
index 4d61fe2..17b3291 100644
--- a/docs/usage.rst
+++ b/docs/usage.rst
@@ -8,18 +8,19 @@ Simulation Settings
Once installed, before running a simulation, you need to configure it.
-* In the settings.py file you will find the configuration of the network.
+* In the Settings JSON file you will find the configuration of the network.
.. code:: python
- # Network settings
- network_type = 1
- number_of_nodes = 1000
- max_time = 50
- num_trials = 1
- timeout = 2
+ {
+ "network_type": 1,
+ "number_of_nodes": 1000,
+ "max_time": 50,
+ "num_trials": 1,
+ "timeout": 2
+ }
-* In the Simulation Settings JSON file, you will find the configuration of the models.
+* In the Settings JSON file, you will also find the configuration of the models.
Network Types
=============
@@ -40,7 +41,7 @@ Models Settings
===============
After having configured the simulation, the next step is setting up the variables of the models.
-For this, you will need to modify the Simulation Settings JSON file.
+For this, you will need to modify the Settings JSON file again.
.. code:: json
@@ -76,7 +77,7 @@ For this, you will need to modify the Simulation Settings JSON file.
}
In this file you will define the different models you are going to simulate. You can simulate as many models
-as you want.
+as you want. Each model will be simulated separately.
After setting up the models, you have to initialize the parameters of each one. You will find the parameters needed
in the documentation of each model.
@@ -90,7 +91,7 @@ After setting all the configuration, you will be able to run the simulation. All
.. code:: bash
- python soil.py
+ python3 soil.py
The simulation will return a dynamic graph .gexf file which could be visualized with
`Gephi `__.
diff --git a/models/BaseBehaviour/BaseBehaviour.py b/models/BaseBehaviour/BaseBehaviour.py
index 820658a..aef94b1 100644
--- a/models/BaseBehaviour/BaseBehaviour.py
+++ b/models/BaseBehaviour/BaseBehaviour.py
@@ -23,7 +23,7 @@ class BaseBehaviour(BaseNetworkAgent):
def run(self):
while True:
self.step(self.env.now)
- yield self.env.timeout(settings.timeout)
+ yield self.env.timeout(settings.network_params["timeout"])
def step(self, now):
networkStatus['agent_%s'% self.id] = self.to_json()
diff --git a/models/ModelM2/ControlModelM2.py b/models/ModelM2/ControlModelM2.py
index b8f818b..2a15025 100644
--- a/models/ModelM2/ControlModelM2.py
+++ b/models/ModelM2/ControlModelM2.py
@@ -24,12 +24,12 @@ class ControlModelM2(BaseBehaviour):
"""
# Init infected
- init_states[random.randint(0, settings.number_of_nodes-1)] = {'id': 1}
- init_states[random.randint(0, settings.number_of_nodes-1)] = {'id': 1}
+ init_states[random.randint(0, settings.network_params["number_of_nodes"]-1)] = {'id': 1}
+ init_states[random.randint(0, settings.network_params["number_of_nodes"]-1)] = {'id': 1}
# Init beacons
- init_states[random.randint(0, settings.number_of_nodes-1)] = {'id': 4}
- init_states[random.randint(0, settings.number_of_nodes-1)] = {'id': 4}
+ init_states[random.randint(0, settings.network_params["number_of_nodes"]-1)] = {'id': 4}
+ init_states[random.randint(0, settings.network_params["number_of_nodes"]-1)] = {'id': 4}
def __init__(self, environment=None, agent_id=0, state=()):
super().__init__(environment=environment, agent_id=agent_id, state=state)
diff --git a/models/ModelM2/SpreadModelM2.py b/models/ModelM2/SpreadModelM2.py
index ee3dc09..a7f6b84 100644
--- a/models/ModelM2/SpreadModelM2.py
+++ b/models/ModelM2/SpreadModelM2.py
@@ -23,8 +23,8 @@ class SpreadModelM2(BaseBehaviour):
prob_generate_anti_rumor
"""
- init_states[random.randint(0, settings.number_of_nodes)] = {'id': 1}
- init_states[random.randint(0, settings.number_of_nodes)] = {'id': 1}
+ init_states[random.randint(0, settings.network_params["number_of_nodes"])] = {'id': 1}
+ init_states[random.randint(0, settings.network_params["number_of_nodes"])] = {'id': 1}
def __init__(self, environment=None, agent_id=0, state=()):
super().__init__(environment=environment, agent_id=agent_id, state=state)
diff --git a/models/models.py b/models/models.py
index ab16ec0..5a508fa 100644
--- a/models/models.py
+++ b/models/models.py
@@ -3,8 +3,8 @@ import settings
networkStatus = {} # Dict that will contain the status of every agent in the network
sentimentCorrelationNodeArray = []
-for x in range(0, settings.number_of_nodes):
+for x in range(0, settings.network_params["number_of_nodes"]):
sentimentCorrelationNodeArray.append({'id': x})
# Initialize agent states. Let's assume everyone is normal.
-init_states = [{'id': 0, } for _ in range(settings.number_of_nodes)]
+init_states = [{'id': 0, } for _ in range(settings.network_params["number_of_nodes"])]
# add keys as as necessary, but "id" must always refer to that state category
diff --git a/simulation_settings.json b/settings.json
similarity index 88%
rename from simulation_settings.json
rename to settings.json
index ac9bcd0..ac38187 100644
--- a/simulation_settings.json
+++ b/settings.json
@@ -1,4 +1,13 @@
-{
+[
+ {
+ "network_type": 1,
+ "number_of_nodes": 1000,
+ "max_time": 50,
+ "num_trials": 1,
+ "timeout": 2
+ },
+
+ {
"agent": ["BaseBehaviour","SISaModel","ControlModelM2"],
@@ -19,7 +28,7 @@
"tweet_probability_users": 0.44,
"tweet_relevant_probability": 0.25,
"tweet_probability_about": [0.15, 0.15, 0.15],
- "sentiment_about": [0, 0, 0],
+ "sentiment_about": [0, 0, 0],
"tweet_probability_enterprises": [0.3, 0.3, 0.3],
@@ -49,4 +58,5 @@
"prob_vaccinated_healing_infected": 0.035,
"prob_vaccinated_vaccinate_neutral": 0.035,
"prob_generate_anti_rumor": 0.035
-}
\ No newline at end of file
+ }
+]
\ No newline at end of file
diff --git a/settings.py b/settings.py
index 1b1f531..53f9ca4 100644
--- a/settings.py
+++ b/settings.py
@@ -1,15 +1,11 @@
# General configuration
import json
-# Network settings
-network_type = 1
-number_of_nodes = 1000
-max_time = 50
-num_trials = 1
-timeout = 2
+with open('settings.json', 'r') as f:
+ settings = json.load(f)
-with open('simulation_settings.json', 'r') as f:
- environment_params = json.load(f)
+network_params = settings[0]
+environment_params = settings[1]
'''
diff --git a/soil.py b/soil.py
index 332667a..684233c 100644
--- a/soil.py
+++ b/soil.py
@@ -1,6 +1,6 @@
from models import *
from nxsim import NetworkSimulation
-import numpy
+# import numpy
from matplotlib import pyplot as plt
import networkx as nx
import settings
@@ -15,7 +15,7 @@ import json
def visualization(graph_name):
- for x in range(0, settings.number_of_nodes):
+ for x in range(0, settings.network_params["number_of_nodes"]):
for attribute in models.networkStatus["agent_%s" % x]:
emotionStatusAux = []
for t_step in models.networkStatus["agent_%s" % x][attribute]:
@@ -46,14 +46,14 @@ def results(model_name):
vaccinated_values = []
attribute_plot = 'status'
- for time in range(0, settings.max_time):
+ for time in range(0, settings.network_params["max_time"]):
value_infectados = 0
value_neutral = 0
value_cured = 0
value_vaccinated = 0
- real_time = time * settings.timeout
+ real_time = time * settings.network_params["timeout"]
activity = False
- for x in range(0, settings.number_of_nodes):
+ for x in range(0, settings.network_params["number_of_nodes"]):
if attribute_plot in models.networkStatus["agent_%s" % x]:
if real_time in models.networkStatus["agent_%s" % x][attribute_plot]:
if models.networkStatus["agent_%s" % x][attribute_plot][real_time] == 1: ## Infected
@@ -93,12 +93,12 @@ def results(model_name):
# Network creation #
####################
-if settings.network_type == 0:
- G = nx.complete_graph(settings.number_of_nodes)
-if settings.network_type == 1:
- G = nx.barabasi_albert_graph(settings.number_of_nodes, 10)
-if settings.network_type == 2:
- G = nx.margulis_gabber_galil_graph(settings.number_of_nodes, None)
+if settings.network_params["network_type"] == 0:
+ G = nx.complete_graph(settings.network_params["number_of_nodes"])
+if settings.network_params["network_type"] == 1:
+ G = nx.barabasi_albert_graph(settings.network_params["number_of_nodes"], 10)
+if settings.network_params["network_type"] == 2:
+ G = nx.margulis_gabber_galil_graph(settings.network_params["number_of_nodes"], None)
# More types of networks can be added here
@@ -112,16 +112,16 @@ print("Using Agent(s): {agents}".format(agents=agents))
if len(agents) > 1:
for agent in agents:
- sim = NetworkSimulation(topology=G, states=init_states, agent_type=locals()[agent], max_time=settings.max_time,
- num_trials=settings.num_trials, logging_interval=1.0, **settings.environment_params)
+ sim = NetworkSimulation(topology=G, states=init_states, agent_type=locals()[agent], max_time=settings.network_params["max_time"],
+ num_trials=settings.network_params["num_trials"], logging_interval=1.0, **settings.environment_params)
sim.run_simulation()
print(str(agent))
results(str(agent))
visualization(str(agent))
else:
agent = agents[0]
- sim = NetworkSimulation(topology=G, states=init_states, agent_type=locals()[agent], max_time=settings.max_time,
- num_trials=settings.num_trials, logging_interval=1.0, **settings.environment_params)
+ sim = NetworkSimulation(topology=G, states=init_states, agent_type=locals()[agent], max_time=settings.network_params["max_time"],
+ num_trials=settings.network_params["num_trials"], logging_interval=1.0, **settings.environment_params)
sim.run_simulation()
results(str(agent))
visualization(str(agent))