def __init__(self, area, time, initial_coordinates, pause_time=0.0): """ *Parameters*: - **area**: an object representing the simulation area; - **time**: a simulation time object of the :class:`sim2net._time.Time` class; - **initial_coordinates** (`list`): initial coordinates of all nodes; each element of this parameter should be a tuple of two coordinates: horizontal and vertical (respectively) of type `float`; - **pause_time** (`float`): a maximum value of the pause time in the *simulation time* units (default: `0.0`, see also: :mod:`sim2net._time`). *Raises*: - **ValueError**: raised when the given value of the *area*, *time* or *initial_coordinates* parameter is `None` or when the given value of the *pause_time* parameter is less that zero. (At the beginning, nodes' destination points are set to be equal to its initial coordinates passed by the *initial_coordinates* parameter.) """ if area is None: raise ValueError('Parameter "area": a simulation area object' \ ' expected but "None" value given!') if time is None: raise ValueError('Parameter "time": a time abstraction object' \ ' expected but "None" value given!') if initial_coordinates is None: raise ValueError('Parameter "initial_coordinates": identifiers' \ ' of nodes expected but "None" value given!') Mobility.__init__(self, RandomDirection.__name__) self._area = area self._time = time self._destinations = dict() check_argument_type(RandomDirection.__name__, 'initial_coordinates', list, initial_coordinates, self.logger) check_argument_type(RandomDirection.__name__, 'pause_time', float, pause_time, self.logger) if pause_time < 0.0: raise ValueError('Parameter "pause_time": a value of the pause' \ ' time cannot be less that zero but %f given!' \ % float(pause_time)) self._pause_time = float(pause_time) # { node id: # { 'destination': (horizontal coordinate, vertical coordinate), # 'pause time' : time } } for node_id in range(0, len(initial_coordinates)): self._destinations[node_id] = dict() self._destinations[node_id]['destination'] = \ initial_coordinates[node_id] self._destinations[node_id]['pause time'] = None self.logger.debug('Destination points has been initialized for %d' \ ' nodes' % len(self._destinations))
def __init__(self, area, time, initial_coordinates, initial_speed, **kwargs): """ *Parameters*: - **area**: an object representing the simulation area; - **time**: a simulation time object of the :class:`sim2net._time.Time` class; - **initial_coordinates** (`list`): initial coordinates of all nodes; each element of this parameter should be a tuple of two coordinates: horizontal and vertical (respectively) of type `float`; - **initial_speed** (`float`): a value of the initial speed that is assigned to each node at the beginning of the simulation; - **kwargs** (`dict`): a dictionary of (optional) keyword parameters related to the Gauss-Markov mobility model; the following parameters are accepted: **alpha** (`float`) The tuning parameter :math:`0\\leqslant\\alpha\\leqslant 1` used to vary the randomness of movements (default: `0.75`). **direction_deviation** (`float`) Constant representing the standard deviation of direction random variable :math:`d_x` (it defaults to :math:`\\frac{\\pi}{2}`). **direction_margin** (`float`) Constant used to change direction mean :math:`\\overline{d}` to ensure that nodes do not remain near a border of the simulation area for a long period of time (it defaults to `0.15`, or `15%` of the simulation area width/height, and cannot be less than zero and greater than one; see: :meth:`_GaussMarkov__velocity_recalculation`). **direction_mean** (`float`) Constant representing mean value :math:`\\overline{d}` of direction (it defaults to :math:`\\frac{\\pi}{6}`). The same value is used as mean of direction random variable :math:`d_x`. **recalculation_interval** (`int`) Velocity (i.e. speed and direction) recalculation time interval (it defaults to the *simulation frequency*; see: :mod:`sim2net._time`). It determines how often, counting in simulation steps, new values of velocity are recalculated. *Raises*: - **ValueError**: raised when the given value of the *area*, *time*, *initial_coordinates* or *initial_speed* parameter is `None`; or when the given value of the keyword parameter *alpha* is less than zero or greater that one; or when the given value of the (optional) keyword parameter *direction_margin* is less than zero or greater than one. *Example*: .. doctest:: :options: +SKIP >>> gm = GaussMarkov(area, time, coordinates, 10.0, alpha=0.35) """ if area is None: raise ValueError('Parameter "area": a simulation area object' ' expected but "None" value given!') if time is None: raise ValueError('Parameter "time": a time abstraction object' ' expected but "None" value given!') if initial_coordinates is None: raise ValueError( 'Parameter "initial_coordinates": identifiers' ' of nodes expected but "None" value given!' ) if initial_speed is None: raise ValueError( 'Parameter "initial_speed": a value of the' ' initial speed of nodes expected but "None"' " value given!" ) Mobility.__init__(self, GaussMarkov.__name__) self.__area = area self.__time = time check_argument_type(GaussMarkov.__name__, "initial_coordinates", list, initial_coordinates, self.logger) check_argument_type(GaussMarkov.__name__, "initial_speed", float, initial_speed, self.logger) if "alpha" in kwargs: check_argument_type(GaussMarkov.__name__, "alpha", float, kwargs["alpha"], self.logger) if kwargs["alpha"] < 0.0 or kwargs["alpha"] > 1.0: raise ValueError( 'Keyword parameter "alpha": a value of the' ' "alpha" parameter cannot be less than' " zero and greater than one but %f given!" % float(kwargs["alpha"]) ) if "direction_deviation" in kwargs: check_argument_type( GaussMarkov.__name__, "direction_deviation", float, kwargs["direction_deviation"], self.logger ) if "direction_margin" in kwargs: check_argument_type( GaussMarkov.__name__, "direction_margin", float, kwargs["direction_margin"], self.logger ) if kwargs["direction_margin"] < 0.0 or kwargs["direction_margin"] > 1.0: raise ValueError( 'Keyword parameter "direction_margin": a' " value of the direction margin cannot be" " less than zero and greater than one but" " %f given!" % float(kwargs["direction_margin"]) ) if "direction_mean" in kwargs: check_argument_type(GaussMarkov.__name__, "direction_mean", float, kwargs["direction_mean"], self.logger) if "recalculation_interval" in kwargs: check_argument_type( GaussMarkov.__name__, "recalculation_interval", int, kwargs["recalculation_interval"], self.logger ) self.__alpha = float(kwargs.get("alpha", GaussMarkov.__DEFAULT_ALPHA)) self.__direction_deviation = float(kwargs.get("direction_deviation", GaussMarkov.__DEFAULT_DIRECTION_DEVIATION)) self.__direction_margin = float(kwargs.get("direction_margin", GaussMarkov.__DEFAULT_DIRECTION_MARGIN)) self.__direction_mean = float(kwargs.get("direction_mean", GaussMarkov.__DEFAULT_DIRECTION_MEAN)) self.__recalculation_interval = int(kwargs.get("recalculation_interval", self.__time.simulation_frequency)) # 1.0 - alpha: self.__gauss_markov_factor_one = 1.0 - self.__alpha # sqrt((1.0 - alpha^2)): self.__gauss_markov_factor_two = sqrt(1.0 - (pow(self.__alpha, 2.0))) # area width * direction margin: self.__width_left = self.__area.width * self.__direction_margin # area width - (area width * direction margin): self.__width_right = self.__area.width - self.__width_left # area height * direction margin: self.__height_bottom = self.__area.height * self.__direction_margin # area height - (area height * direction margin): self.__height_top = self.__area.height - self.__height_bottom # { node id: # { 'speed': current speed), # 'direction': current direction } } self.__velocities = dict() for node_id in range(0, len(initial_coordinates)): self.__velocities[node_id] = dict() self.__velocities[node_id]["speed"] = float(initial_speed) self.__velocities[node_id]["direction"] = self.__get_new_direction() self.logger.debug("Speed and direction values has been initialized" " for %d nodes" % len(self.__velocities))
def __init__(self, area, time, initial_coordinates, pause_time=0.0, area_factor=0.25): """ *Parameters*: - **area**: an object representing the simulation area; - **time**: a simulation time object of the :class:`sim2net._time.Time` class; - **initial_coordinates** (`list`): initial coordinates of all nodes; each element of this parameter should be a tuple of two coordinates: horizontal and vertical (respectively) of type `float`; - **pause_time** (`float`): a maximum value of the pause time in the *simulation time* units (default: `0.0`, see also: :mod:`sim2net._time`); - **area_factor** (`float`): a factor used to determine the width and height of the free roam area around the reference point (default: `0.25`). *Raises*: - **ValueError**: raised when the given value of the *area*, *time* or *initial_coordinates* parameter is `None`; or when the given value of the *pause_time* parameter is less that zero; or when the given value of the *area_factor* parameter is less than zero or greater than one. (At the beginning, nodes' destination points are set to be equal to its initial coordinates passed by the *initial_coordinates* parameter.) """ if area is None: raise ValueError('Parameter "area": a simulation area object' \ ' expected but "None" value given!') if time is None: raise ValueError('Parameter "time": a time abstraction object' \ ' expected but "None" value given!') if initial_coordinates is None: raise ValueError('Parameter "initial_coordinates": identifiers' \ ' of nodes expected but "None" value given!') Mobility.__init__(self, NomadicCommunity.__name__) check_argument_type(RandomWaypoint.__name__, 'initial_coordinates', list, initial_coordinates, self.logger) check_argument_type(RandomWaypoint.__name__, 'pause_time', float, pause_time, self.logger) if pause_time < 0.0: raise ValueError('Parameter "pause_time": a value of the pause' \ ' time cannot be less that zero but %f given!' \ % float(pause_time)) self._pause_time = float(pause_time) check_argument_type(RandomWaypoint.__name__, 'area_factor', float, area_factor, self.logger) if area_factor < 0.0 or area_factor > 1.0: raise ValueError('Parameter "area_factor": a value of the factor' \ ' used to compute the free roam area of nodes' \ ' cannot be less than zero or greater than one' \ ' but %f given!' % float(area_factor)) self.__area_factor = float(area_factor) self._area = area self._time = time self.__reference_point = \ (self.random_generator.uniform(self._area.ORIGIN[0], self._area.width), self.random_generator.uniform(self._area.ORIGIN[1], self._area.height)) self.__relocation_time = None # { node id: # { 'destination': (horizontal coordinate, vertical coordinate), # 'pause time' : time } } # 'on site' : True/False } } self._destinations = dict() for node_id in range(0, len(initial_coordinates)): self._destinations[node_id] = dict() self._destinations[node_id]['destination'] = \ initial_coordinates[node_id] self._destinations[node_id]['pause time'] = None self._destinations[node_id]['on site'] = False self.logger.debug('Destination points has been initialized for %d' \ ' nodes with the initial reference point at (%f,' \ ' %f)' % (len(self._destinations), self.__reference_point[0], self.__reference_point[1]))
def __init__(self, area, time, initial_coordinates, initial_speed, **kwargs): """ *Parameters*: - **area**: an object representing the simulation area; - **time**: a simulation time object of the :class:`sim2net._time.Time` class; - **initial_coordinates** (`list`): initial coordinates of all nodes; each element of this parameter should be a tuple of two coordinates: horizontal and vertical (respectively) of type `float`; - **initial_speed** (`float`): a value of the initial speed that is assigned to each node at the beginning of the simulation; - **kwargs** (`dict`): a dictionary of (optional) keyword parameters related to the Gauss-Markov mobility model; the following parameters are accepted: **alpha** (`float`) The tuning parameter :math:`0\\leqslant\\alpha\\leqslant 1` used to vary the randomness of movements (default: `0.75`). **direction_deviation** (`float`) Constant representing the standard deviation of direction random variable :math:`d_x` (it defaults to :math:`\\frac{\\pi}{2}`). **direction_margin** (`float`) Constant used to change direction mean :math:`\\overline{d}` to ensure that nodes do not remain near a border of the simulation area for a long period of time (it defaults to `0.15`, or `15%` of the simulation area width/height, and cannot be less than zero and greater than one; see: :meth:`_GaussMarkov__velocity_recalculation`). **direction_mean** (`float`) Constant representing mean value :math:`\\overline{d}` of direction (it defaults to :math:`\\frac{\\pi}{6}`). The same value is used as mean of direction random variable :math:`d_x`. **recalculation_interval** (`int`) Velocity (i.e. speed and direction) recalculation time interval (it defaults to the *simulation frequency*; see: :mod:`sim2net._time`). It determines how often, counting in simulation steps, new values of velocity are recalculated. *Raises*: - **ValueError**: raised when the given value of the *area*, *time*, *initial_coordinates* or *initial_speed* parameter is `None`; or when the given value of the keyword parameter *alpha* is less than zero or greater that one; or when the given value of the (optional) keyword parameter *direction_margin* is less than zero or greater than one. *Example*: .. doctest:: :options: +SKIP >>> gm = GaussMarkov(area, time, coordinates, 10.0, alpha=0.35) """ if area is None: raise ValueError('Parameter "area": a simulation area object' \ ' expected but "None" value given!') if time is None: raise ValueError('Parameter "time": a time abstraction object' \ ' expected but "None" value given!') if initial_coordinates is None: raise ValueError('Parameter "initial_coordinates": identifiers' \ ' of nodes expected but "None" value given!') if initial_speed is None: raise ValueError('Parameter "initial_speed": a value of the' \ ' initial speed of nodes expected but "None"' \ ' value given!') Mobility.__init__(self, GaussMarkov.__name__) self.__area = area self.__time = time check_argument_type(GaussMarkov.__name__, 'initial_coordinates', list, initial_coordinates, self.logger) check_argument_type(GaussMarkov.__name__, 'initial_speed', float, initial_speed, self.logger) if 'alpha' in kwargs: check_argument_type(GaussMarkov.__name__, 'alpha', float, kwargs['alpha'], self.logger) if kwargs['alpha'] < 0.0 or kwargs['alpha'] > 1.0: raise ValueError('Keyword parameter "alpha": a value of the' \ ' "alpha" parameter cannot be less than' \ ' zero and greater than one but %f given!' \ % float(kwargs['alpha'])) if 'direction_deviation' in kwargs: check_argument_type(GaussMarkov.__name__, 'direction_deviation', float, kwargs['direction_deviation'], self.logger) if 'direction_margin' in kwargs: check_argument_type(GaussMarkov.__name__, 'direction_margin', float, kwargs['direction_margin'], self.logger) if kwargs['direction_margin'] < 0.0 \ or kwargs['direction_margin'] > 1.0: raise ValueError('Keyword parameter "direction_margin": a' \ ' value of the direction margin cannot be' \ ' less than zero and greater than one but' \ ' %f given!' \ % float(kwargs['direction_margin'])) if 'direction_mean' in kwargs: check_argument_type(GaussMarkov.__name__, 'direction_mean', float, kwargs['direction_mean'], self.logger) if 'recalculation_interval' in kwargs: check_argument_type(GaussMarkov.__name__, 'recalculation_interval', int, kwargs['recalculation_interval'], self.logger) self.__alpha = float(kwargs.get('alpha', GaussMarkov.__DEFAULT_ALPHA)) self.__direction_deviation = \ float(kwargs.get('direction_deviation', GaussMarkov.__DEFAULT_DIRECTION_DEVIATION)) self.__direction_margin = \ float(kwargs.get('direction_margin', GaussMarkov.__DEFAULT_DIRECTION_MARGIN)) self.__direction_mean = \ float(kwargs.get('direction_mean', GaussMarkov.__DEFAULT_DIRECTION_MEAN)) self.__recalculation_interval = \ int(kwargs.get('recalculation_interval', self.__time.simulation_frequency)) # 1.0 - alpha: self.__gauss_markov_factor_one = 1.0 - self.__alpha # sqrt((1.0 - alpha^2)): self.__gauss_markov_factor_two = sqrt(1.0 - (pow(self.__alpha, 2.0))) # area width * direction margin: self.__width_left = self.__area.width * self.__direction_margin # area width - (area width * direction margin): self.__width_right = self.__area.width - self.__width_left # area height * direction margin: self.__height_bottom = self.__area.height * self.__direction_margin # area height - (area height * direction margin): self.__height_top = self.__area.height - self.__height_bottom # { node id: # { 'speed': current speed), # 'direction': current direction } } self.__velocities = dict() for node_id in range(0, len(initial_coordinates)): self.__velocities[node_id] = dict() self.__velocities[node_id]['speed'] = float(initial_speed) self.__velocities[node_id]['direction'] = \ self.__get_new_direction() self.logger.debug('Speed and direction values has been initialized' \ ' for %d nodes' % len(self.__velocities))