process

Class to manage the resources shared by all the traces in the process.

Alt Text

 1'''
 2Class to manage the resources shared by all the traces in the process.
 3
 4<img src="images/process_class.png" alt="Alt Text" width="780">
 5'''
 6import simpy
 7from role_simulator import RoleSimulator
 8import math
 9from parameters import Parameters
10
11
12class SimulationProcess(object):
13
14    def __init__(self, env: simpy.Environment, params: Parameters):
15        self._env = env
16        self._params = params
17        self._date_start = params.START_SIMULATION
18        self._resources = self.define_single_role()
19        self._resource_events = self._define_resource_events(env)
20        self._resource_trace = simpy.Resource(env, math.inf)
21        self._am_parallel = []
22
23    def define_single_role(self):
24        """
25        Definition of a *RoleSimulator* object for each role in the process.
26        """
27        set_resource = list(self._params.ROLE_CAPACITY.keys())
28        dict_role = dict()
29        for res in set_resource:
30            res_simpy = RoleSimulator(self._env, res, self._params.ROLE_CAPACITY[res][0],
31                                      self._params.ROLE_CAPACITY[res][1])
32            dict_role[res] = res_simpy
33        return dict_role
34
35    def get_occupations_single_role(self, resource):
36        """
37        Method to retrieve the specified role occupancy in percentage, as an intercase feature:
38        $\\frac{resources \: occupated \: in \:role}{total\:resources\:in\:role}$.
39        """
40        occup = self._resources[resource]._get_resource().count / self._resources[resource]._capacity
41        return round(occup, 2)
42
43    def get_occupations_all_role(self):
44        """
45        Method to retrieve the occupancy in percentage of all roles, as an intercase feature.
46        """
47        list_occupations = []
48        for res in self._resources:
49            if res != 'TRIGGER_TIMER':
50                occup = round(self._resources[res]._get_resource().count / self._resources[res]._capacity, 2)
51                list_occupations.append(occup)
52        return list_occupations
53
54    def _get_resource(self, resource_label):
55        return self._resources[resource_label]
56
57    def _get_resource_event(self, task):
58        return self._resource_events[task]
59
60    def _get_resource_trace(self):
61        return self._resource_trace
62
63    def _define_resource_events(self, env):
64        resources = dict()
65        for key in self._params.PROCESSING_TIME.keys():
66            resources[key] = simpy.Resource(env, math.inf)
67        return resources
68
69    def _set_single_resource(self, resource_task):
70        return self._resources[resource_task]._get_resources_name()
71
72    def _release_single_resource(self, role, resource):
73        self._resources[role]._release_resource_name(resource)
class SimulationProcess:
13class SimulationProcess(object):
14
15    def __init__(self, env: simpy.Environment, params: Parameters):
16        self._env = env
17        self._params = params
18        self._date_start = params.START_SIMULATION
19        self._resources = self.define_single_role()
20        self._resource_events = self._define_resource_events(env)
21        self._resource_trace = simpy.Resource(env, math.inf)
22        self._am_parallel = []
23
24    def define_single_role(self):
25        """
26        Definition of a *RoleSimulator* object for each role in the process.
27        """
28        set_resource = list(self._params.ROLE_CAPACITY.keys())
29        dict_role = dict()
30        for res in set_resource:
31            res_simpy = RoleSimulator(self._env, res, self._params.ROLE_CAPACITY[res][0],
32                                      self._params.ROLE_CAPACITY[res][1])
33            dict_role[res] = res_simpy
34        return dict_role
35
36    def get_occupations_single_role(self, resource):
37        """
38        Method to retrieve the specified role occupancy in percentage, as an intercase feature:
39        $\\frac{resources \: occupated \: in \:role}{total\:resources\:in\:role}$.
40        """
41        occup = self._resources[resource]._get_resource().count / self._resources[resource]._capacity
42        return round(occup, 2)
43
44    def get_occupations_all_role(self):
45        """
46        Method to retrieve the occupancy in percentage of all roles, as an intercase feature.
47        """
48        list_occupations = []
49        for res in self._resources:
50            if res != 'TRIGGER_TIMER':
51                occup = round(self._resources[res]._get_resource().count / self._resources[res]._capacity, 2)
52                list_occupations.append(occup)
53        return list_occupations
54
55    def _get_resource(self, resource_label):
56        return self._resources[resource_label]
57
58    def _get_resource_event(self, task):
59        return self._resource_events[task]
60
61    def _get_resource_trace(self):
62        return self._resource_trace
63
64    def _define_resource_events(self, env):
65        resources = dict()
66        for key in self._params.PROCESSING_TIME.keys():
67            resources[key] = simpy.Resource(env, math.inf)
68        return resources
69
70    def _set_single_resource(self, resource_task):
71        return self._resources[resource_task]._get_resources_name()
72
73    def _release_single_resource(self, role, resource):
74        self._resources[role]._release_resource_name(resource)
SimulationProcess(env: simpy.core.Environment, params: parameters.Parameters)
15    def __init__(self, env: simpy.Environment, params: Parameters):
16        self._env = env
17        self._params = params
18        self._date_start = params.START_SIMULATION
19        self._resources = self.define_single_role()
20        self._resource_events = self._define_resource_events(env)
21        self._resource_trace = simpy.Resource(env, math.inf)
22        self._am_parallel = []
def define_single_role(self):
24    def define_single_role(self):
25        """
26        Definition of a *RoleSimulator* object for each role in the process.
27        """
28        set_resource = list(self._params.ROLE_CAPACITY.keys())
29        dict_role = dict()
30        for res in set_resource:
31            res_simpy = RoleSimulator(self._env, res, self._params.ROLE_CAPACITY[res][0],
32                                      self._params.ROLE_CAPACITY[res][1])
33            dict_role[res] = res_simpy
34        return dict_role

Definition of a RoleSimulator object for each role in the process.

def get_occupations_single_role(self, resource):
36    def get_occupations_single_role(self, resource):
37        """
38        Method to retrieve the specified role occupancy in percentage, as an intercase feature:
39        $\\frac{resources \: occupated \: in \:role}{total\:resources\:in\:role}$.
40        """
41        occup = self._resources[resource]._get_resource().count / self._resources[resource]._capacity
42        return round(occup, 2)

Method to retrieve the specified role occupancy in percentage, as an intercase feature: $\frac{resources \: occupated \: in \:role}{total\:resources\:in\:role}$.

def get_occupations_all_role(self):
44    def get_occupations_all_role(self):
45        """
46        Method to retrieve the occupancy in percentage of all roles, as an intercase feature.
47        """
48        list_occupations = []
49        for res in self._resources:
50            if res != 'TRIGGER_TIMER':
51                occup = round(self._resources[res]._get_resource().count / self._resources[res]._capacity, 2)
52                list_occupations.append(occup)
53        return list_occupations

Method to retrieve the occupancy in percentage of all roles, as an intercase feature.