1
0
mirror of https://github.com/gsi-upm/soil synced 2024-12-22 08:18:13 +00:00

All settings as JSON and documentation updated

This commit is contained in:
Tasio Mendez 2017-05-16 14:02:50 +02:00
parent 23fc9671c3
commit a643735ddb
20 changed files with 90 additions and 81 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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
=============

View File

@ -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 <https://gephi.org/users/download/>`__.

View File

@ -51,7 +51,7 @@
In practice, a model consists of at least two parts:</p>
<ul class="simple">
<li>Python module: the actual code that describes the behaviour.</li>
<li>Setting up the variables in the Simulation Settings JSON file.</li>
<li>Setting up the variables in the Settings JSON file.</li>
</ul>
<p>This separation allows us to run the simulation with different agents.</p>
</div>
@ -63,10 +63,10 @@ In practice, a model consists of at least two parts:</p>
<span class="n">networkStatus</span> <span class="o">=</span> <span class="p">{}</span> <span class="c1"># Dict that will contain the status of every agent in the network</span>
<span class="n">sentimentCorrelationNodeArray</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">settings</span><span class="o">.</span><span class="n">number_of_nodes</span><span class="p">):</span>
<span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">settings</span><span class="o">.</span><span class="n">network_params</span><span class="p">[</span><span class="s2">&quot;number_of_nodes&quot;</span><span class="p">]):</span>
<span class="n">sentimentCorrelationNodeArray</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s1">&#39;id&#39;</span><span class="p">:</span> <span class="n">x</span><span class="p">})</span>
<span class="c1"># Initialize agent states. Let&#39;s assume everyone is normal.</span>
<span class="n">init_states</span> <span class="o">=</span> <span class="p">[{</span><span class="s1">&#39;id&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="p">}</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">settings</span><span class="o">.</span><span class="n">number_of_nodes</span><span class="p">)]</span>
<span class="n">init_states</span> <span class="o">=</span> <span class="p">[{</span><span class="s1">&#39;id&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="p">}</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">settings</span><span class="o">.</span><span class="n">network_params</span><span class="p">[</span><span class="s2">&quot;number_of_nodes&quot;</span><span class="p">])]</span>
<span class="c1"># add keys as as necessary, but &quot;id&quot; must always refer to that state category</span>
</pre></div>
</div>
@ -114,7 +114,7 @@ passed as a parameter to the simulation.</p>
</pre></div>
</div>
<p>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 <a class="reference internal" href="usage.html"><span class="doc">Usage</span></a>.</p>
The simulation returns one result for each model, executing each model separately. For the usage, see <a class="reference internal" href="usage.html"><span class="doc">Usage</span></a>.</p>
</div>
<div class="section" id="example-model">
<h2>Example Model<a class="headerlink" href="#example-model" title="Permalink to this headline"></a></h2>

View File

@ -1 +1 @@
Search.setIndex({docnames:["index","usage"],envversion:51,filenames:["index.rst","usage.rst"],objects:{},objnames:{},objtypes:{},terms:{"class":[],"default":1,"import":[],"new":0,"return":1,"super":[],For:1,The:1,There:1,__init__:[],abl:1,about:0,actual:[],add:1,added:1,after:1,agent:[0,1],agent_id:[],all:1,allow:[],also:1,alwai:[],analysi:[],anger:[],anger_prob:[],append:[],assess:[],assum:[],barabasi_albert_graph:1,base:0,basebehaviour:[],basic:[],been:1,befor:1,behaviour:[],can:1,categori:[],clone:[],cluster:[],code:0,complete_graph:1,configur:1,consist:[],contain:[],content:[],content_discont:1,content_neutr:1,controlmodelm2:1,correl:[],could:1,def:[],defin:1,describ:[],develop:0,dict:[],differ:1,discontent_cont:1,discontent_neutr:1,disgust:[],disgust_prob:[],dit:[],doc:[],document:1,dynam:1,each:1,effect:[],env:[],environ:[],environment_param:[],everi:[],everyon:[],exampl:0,execut:1,fail:1,file:1,fill:[],find:1,first:1,from:[],gephi:1,gexf:1,git:[],gitlab:[],going:1,graph:1,gsi:[],has:1,have:1,here:1,how:[],http:[],implement:1,includ:[],index:[],inherit:[],init_st:[],initi:[0,1],instal:[0,1],instruct:1,joi:[],joy_prob:[],json:1,kei:[],lab:[],latest:[],learn:0,least:[],let:[],like:[],look:[],main:[],mani:1,margulis_gabber_galil_graph:1,max_tim:1,method:[],model:0,modifi:1,modul:[],more:[0,1],must:[],necessari:[],need:1,network:0,network_typ:1,networkstatu:[],neutral_content_infected_prob:1,neutral_content_spon_prob:1,neutral_discontent_infected_prob:1,neutral_discontent_spon_prob:1,next:1,none:1,normal:[],now:[],num_trial:1,number_of_nod:1,onc:1,one:1,outside_effects_prob:[],over:[],packag:1,page:[],paramet:1,part:[],pass:[],pictur:1,plugin:[],png:1,practic:[],prob_cured_healing_infect:1,prob_cured_vaccinate_neutr:1,prob_generate_anti_rumor:1,prob_infect:1,prob_neutral_making_deni:1,prob_vaccinated_healing_infect:1,prob_vaccinated_vaccinate_neutr:1,provid:1,python:[0,1],rang:[],refer:[],requir:1,result:[],run:0,sad:[],sadness_prob:[],same:[],search:[],section:[],see:1,self:[],sentiment:[],sentimentcorrelationmodel:[],sentimentcorrelationnodearrai:[],separ:[],set:0,simul:0,sisamodel:1,social:0,soil:1,standard_vari:1,state:[],statu:[],step:1,system:[],them:[],thi:1,three:1,through:[],time:[],time_awar:[],timeout:1,two:[],type:0,upm:[],usag:0,used:[],user:[],valid:1,variabl:[0,1],variance_c_d:1,variance_d_c:1,version:[],view:[],visual:1,want:1,what:0,which:1,whole:[],without:1,would:[],you:1},titles:["Welcome to Soil&#8217;s documentation!","Usage"],titleterms:{"new":[],code:[],develop:[],document:0,exampl:[],indic:[],initi:[],instal:[],model:1,network:1,run:1,set:1,simul:1,soil:0,tabl:[],type:1,usag:1,variabl:[],welcom:0,what:[]}})
Search.setIndex({docnames:["index","models","usage"],envversion:51,filenames:["index.rst","models.rst","usage.rst"],objects:{},objnames:{},objtypes:{},terms:{"class":1,"default":2,"import":1,"new":0,"return":[1,2],"super":1,For:[1,2],The:[1,2],There:[1,2],__init__:1,abl:2,about:0,actual:1,add:[1,2],added:2,after:2,again:2,agent:[0,1,2],agent_id:1,all:[1,2],allow:1,also:[1,2],alwai:1,analysi:1,anger:1,anger_prob:1,append:1,assess:1,assum:1,barabasi_albert_graph:2,base:0,basebehaviour:1,basic:1,been:2,befor:2,behaviour:1,can:[1,2],categori:1,clone:[],cluster:[],code:0,complete_graph:2,configur:2,consist:1,contain:1,content:[],content_discont:[1,2],content_neutr:[1,2],controlmodelm2:[1,2],correl:1,could:2,def:1,defin:[1,2],describ:1,develop:0,dict:1,differ:[1,2],discontent_cont:[1,2],discontent_neutr:[1,2],disgust:1,disgust_prob:1,dit:[],doc:[],document:[1,2],dynam:2,each:[1,2],effect:1,env:1,environ:1,environment_param:1,everi:1,everyon:1,exampl:0,execut:[1,2],fail:2,file:[1,2],fill:[],find:2,first:2,from:1,gephi:2,gexf:2,git:[],gitlab:[],going:[1,2],graph:2,gsi:[],has:2,have:[1,2],here:2,how:1,http:[],implement:[1,2],includ:1,index:[],inherit:1,init_st:1,initi:[0,2],instal:[0,2],instruct:2,joi:1,joy_prob:1,json:[1,2],kei:1,lab:[],latest:[],learn:0,least:1,let:1,like:1,look:1,main:1,mani:[1,2],margulis_gabber_galil_graph:2,max_tim:2,method:1,model:0,modifi:[1,2],modul:1,more:[0,2],must:1,necessari:1,need:2,network:[0,1],network_param:1,network_typ:2,networkstatu:1,neutral_content_infected_prob:[1,2],neutral_content_spon_prob:[1,2],neutral_discontent_infected_prob:[1,2],neutral_discontent_spon_prob:[1,2],next:2,none:[1,2],normal:1,now:1,num_trial:2,number_of_nod:[1,2],onc:2,one:[1,2],outside_effects_prob:1,over:1,packag:2,page:[],paramet:[1,2],part:1,pass:1,pictur:2,plugin:[],png:2,practic:1,prob_cured_healing_infect:[1,2],prob_cured_vaccinate_neutr:[1,2],prob_generate_anti_rumor:[1,2],prob_infect:[1,2],prob_neutral_making_deni:[1,2],prob_vaccinated_healing_infect:[1,2],prob_vaccinated_vaccinate_neutr:[1,2],provid:2,python3:2,python:[0,1],rang:1,refer:1,requir:2,result:1,run:[0,1],sad:1,sadness_prob:1,same:1,search:[],section:1,see:[1,2],self:1,sentiment:1,sentimentcorrelationmodel:1,sentimentcorrelationnodearrai:1,separ:[1,2],set:[0,1],simul:[0,1],sisamodel:[1,2],social:0,soil:2,standard_vari:[1,2],state:1,statu:1,step:[1,2],system:1,them:1,thi:[1,2],three:2,through:[],time:1,time_awar:1,timeout:2,two:1,type:0,upm:[],usag:[0,1],used:1,user:1,valid:2,variabl:[0,2],variance_c_d:[1,2],variance_d_c:[1,2],version:[],view:1,visual:2,want:[1,2],what:0,which:[1,2],whole:1,without:2,would:1,you:[1,2]},titles:["Welcome to Soil&#8217;s documentation!","Developing new models","Usage"],titleterms:{"new":1,code:1,develop:1,document:0,exampl:1,indic:[],initi:1,instal:[],model:[1,2],network:2,run:2,set:2,simul:2,soil:0,tabl:[],type:2,usag:2,variabl:1,welcom:0,what:1}})

View File

@ -50,17 +50,18 @@
<h2>Simulation Settings<a class="headerlink" href="#simulation-settings" title="Permalink to this headline"></a></h2>
<p>Once installed, before running a simulation, you need to configure it.</p>
<ul>
<li><p class="first">In the settings.py file you will find the configuration of the network.</p>
<div class="code python highlight-default"><div class="highlight"><pre><span></span><span class="c1"># Network settings</span>
<span class="n">network_type</span> <span class="o">=</span> <span class="mi">1</span>
<span class="n">number_of_nodes</span> <span class="o">=</span> <span class="mi">1000</span>
<span class="n">max_time</span> <span class="o">=</span> <span class="mi">50</span>
<span class="n">num_trials</span> <span class="o">=</span> <span class="mi">1</span>
<span class="n">timeout</span> <span class="o">=</span> <span class="mi">2</span>
<li><p class="first">In the Settings JSON file you will find the configuration of the network.</p>
<div class="code python highlight-default"><div class="highlight"><pre><span></span><span class="p">{</span>
<span class="s2">&quot;network_type&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
<span class="s2">&quot;number_of_nodes&quot;</span><span class="p">:</span> <span class="mi">1000</span><span class="p">,</span>
<span class="s2">&quot;max_time&quot;</span><span class="p">:</span> <span class="mi">50</span><span class="p">,</span>
<span class="s2">&quot;num_trials&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
<span class="s2">&quot;timeout&quot;</span><span class="p">:</span> <span class="mi">2</span>
<span class="p">}</span>
</pre></div>
</div>
</li>
<li><p class="first">In the Simulation Settings JSON file, you will find the configuration of the models.</p>
<li><p class="first">In the Settings JSON file, you will also find the configuration of the models.</p>
</li>
</ul>
</div>
@ -80,7 +81,7 @@
<div class="section" id="models-settings">
<h2>Models Settings<a class="headerlink" href="#models-settings" title="Permalink to this headline"></a></h2>
<p>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.</p>
For this, you will need to modify the Settings JSON file again.</p>
<div class="code json highlight-default"><div class="highlight"><pre><span></span><span class="p">{</span>
<span class="s2">&quot;agent&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;SISaModel&quot;</span><span class="p">,</span><span class="s2">&quot;ControlModelM2&quot;</span><span class="p">],</span>
@ -114,7 +115,7 @@ For this, you will need to modify the Simulation Settings JSON file.</p>
</pre></div>
</div>
<p>In this file you will define the different models you are going to simulate. You can simulate as many models
as you want.</p>
as you want. Each model will be simulated separately.</p>
<p>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.</p>
<p>Parameter validation will fail if a required parameter without a default has not been provided.</p>
@ -122,7 +123,7 @@ in the documentation of each model.</p>
<div class="section" id="running-the-simulation">
<h2>Running the Simulation<a class="headerlink" href="#running-the-simulation" title="Permalink to this headline"></a></h2>
<p>After setting all the configuration, you will be able to run the simulation. All you need to do is execute:</p>
<div class="code bash highlight-default"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">soil</span><span class="o">.</span><span class="n">py</span>
<div class="code bash highlight-default"><div class="highlight"><pre><span></span><span class="n">python3</span> <span class="n">soil</span><span class="o">.</span><span class="n">py</span>
</pre></div>
</div>
<p>The simulation will return a dynamic graph .gexf file which could be visualized with

View File

@ -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
=============

View File

@ -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 <https://gephi.org/users/download/>`__.

View File

@ -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()

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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
}
}
]

View File

@ -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]
'''

30
soil.py
View File

@ -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))