def __init__(self, network=None, commRange=None, sensors=None, node_type=None, power_type=1, mobile_type=0, **kwargs): """ Initialize the node object. node_type: 'N' regular, 'B' base station/Sink, 'C' coordinator/cluster head/relay/Anchor power_type = {0: "External", 1: "Battery", 2: "Energy Harvesting"} Mobility_Type = {0: "Fixed", 1: "Mobile-Vel", 2: "Mobile-Acc", 3: "Random"} """ self._compositeSensor = CompositeSensor(self, sensors or settings.SENSORS) self.network = network self._commRange = commRange or settings.COMM_RANGE self.id = self.__class__.cid self.__class__.cid += 1 self._inboxDelay = True self.type = node_type or 'N' self.power = EnergyModel(power_type=power_type) self.mobility = MobilityModel(mobile_type=mobile_type) self.reset()
def __init__(self, network=None, commRange=None, sensors=None, **kwargs): self._compositeSensor = CompositeSensor(self, sensors or settings.SENSORS) self.network = network self._commRange = commRange or settings.COMM_RANGE self.id = self.__class__.cid self.__class__.cid += 1 self._inboxDelay = True self.reset()
def validate_params(self, params): """ Validate if given network params match its real params. """ logger.info('Validating params') count = params.get('count', None) # for unit tests if count: if isinstance(count, list): assert (len(self) in count) else: assert (len(self) == count) n_min = params.get('n_min', 0) n_max = params.get('n_max', Inf) assert (len(self) >= n_min and len(self) <= n_max) for param, value in params.items(): if param == 'connected': assert (not value or is_connected(self)) elif param == 'degree': assert (allclose(self.avg_degree(), value, atol=settings.DEG_ATOL)) elif param == 'environment': assert (self.environment.__class__ == value.__class__) elif param == 'channelType': assert (self.channelType.__class__ == value.__class__) elif param == 'comm_range': for node in self: assert (node.commRange == value) elif param == 'sensors': compositeSensor = CompositeSensor(Node(), value) for node in self: assert (all( map(lambda s1, s2: pymote_equal_objects(s1, s2), node.sensors, compositeSensor.sensors))) elif param == 'aoa_pf_scale': for node in self: for sensor in node.sensors: if sensor.name() == 'AoASensor': assert (sensor.probabilityFunction.scale == value) elif param == 'dist_pf_scale': for node in self: for sensor in node.sensors: if sensor.name() == 'DistSensor': assert (sensor.probabilityFunction.scale == value) #TODO: refactor this part as setting algorithms resets nodes """
def sensors(self, sensors): self._compositeSensor = CompositeSensor(self, sensors)
def compositeSensor(self, compositeSensor): self._compositeSensor = CompositeSensor(self, compositeSensor)