If the SOBA package is not yet installed, we must first do so. To install SOBA the best option is to use the package management system PIP. For this, we execute the following command.
$ pip install soba
In case of error, this other command should be used, ensuring to have installed python 3 and pip 3.
$ pip3 install soba
SEBA enables the performance of the simulations in two modes:
In the tutorials, the small modifications required to use each posibility are reflected.
In addition, two added mechanisms are provided to interact with the simulation:
In [1]:
from soba.models.continuousModel import ContinuousModel
import soba.visualization.ramen.mapGenerator as ramen
import soba.run
from collections import OrderedDict
import json
import sys
from model import SEBAModel
from visualization.back import Visualization
import datetime as dt
strategies = ['nearest', 'safest', 'uncrowded']
today = dt.date.today()
timeHazard = dt.datetime(today.year, today.month, 1, 8, 30, 0, 0)
families = []
family1 = {'N': 3, 'child': 1, 'adult': 2} #Only two are really neccesary
family2 = {'N': 3, 'child': 2, 'adult': 1}
# Uncomment to consider families
#families.append(family1)
#families.append(family2)
sebaConfiguration = {'families': families, 'hazard': timeHazard}
#JSON to store all the informacion.
jsonsOccupants = []
#Number of occupants
N = 4
#Definition of the states
states = OrderedDict([('Leaving','out'), ('Resting', 'sofa'), ('Working in my laboratory', 'wp')])
#Definition of the schedule
schedule = {'t1': "08:01:00", 't2': "08:10:00", 't3': "08:20:00"}
#Possible Variation on the schedule
variation = {'t1': "00:01:00", 't2': "00:01:00", 't3': "00:01:00"}
#Probability of state change associated with the Markovian chain as a function of the temporal period
markovActivity = {
'-t1': [[100, 0, 0], [0, 0, 0], [0, 0, 0]],
't1-t2': [[0, 0, 100], [0, 50, 50], [0, 50, 50]],
't2-t3': [[100, 0, 0], [0, 50, 50], [0, 50, 50]],
't3-': [[0, 0, 100], [0, 100, 0], [0, 100, 0]]
}
#Time associated to each state (minutes)
timeActivity = {
'-t1': [3, 0, 0], 't1-t2': [3, 3, 3], 't2-t3': [3, 3, 3], 't3-': [3, 3, 3]
}
#Time variation associated to each state (minutes)
timeActivityVariation = {
'-t1': [1, 0, 0], 't1-t2': [1, 1, 1], 't2-t3': [1, 1, 1], 't3-': [1, 1, 1]
}
#Store the information
jsonOccupant = {'type': 'example' , 'N': N, 'states': states , 'schedule': schedule, 'variation': variation,
'markovActivity': markovActivity, 'timeActivity': timeActivity, 'timeActivityVariation': timeActivityVariation,
'strategy': 'nearest'}
cellW = 20
cellH = 20
jsonsOccupants.append(jsonOccupant)
2.- We define the building plan or the distribution of the space.
In [2]:
import soba.visualization.ramen.mapGenerator as ramen
with open('auxiliarFiles/labgsi.blueprint3d') as data_file:
jsonMap = ramen.returnMap(data_file)
3.- We call the execution methods.
3.1-With visual representation.
In [3]:
sys.argv = []
sys.argv.append("-1")
sys.argv.append("-v")
back = Visualization(cellW, cellH)
parameters = {'width': cellW, 'height': cellH, 'jsonMap': jsonMap, 'jsonsOccupants': jsonsOccupants, 'sebaConfiguration': sebaConfiguration}
soba.run.run(SEBAModel, parameters, visualJS="visualization/front.js", back=back)
3.1- Bacth mode.
In [ ]:
import soba.run
import sys
#Fixed parameters during iterations
fixed_params = {"width": cellW, "height": cellH, "jsonMap": jsonMap, "jsonsOccupants": jsonsOccupants, 'sebaConfiguration': sebaConfiguration}
#Variable parameters to each iteration
variable_params = {"seed": range(10, 500, 10)}
sys.argv = []
sys.argv.append("-1")
sys.argv.append("-b")
soba.run.run(SEBAModel, fixed_params, variable_params)
In [ ]: