Package sim2net.placement¶
This package provides a collections of placement model classes.
A placement (or deployment) model describes a simulation area and a given number of nodes deployed in the area. It provides also node positions in case of static networks or initial node positions for mobile environments.
Package modules:
See also
Module sim2net.placement._placement¶
Contains an abstract class that should be implemented by all placement classes.
- class sim2net.placement._placement.Placement(name)¶
Bases: object
This class is an abstract class that should be implemented by all placement model classes.
Parameters: - name (str): a name of the implemented placement model.
- get_placement()¶
Generates placement positions and returns the result as a dictionary.
- Returns:
- A dictionary containing the placement information.
- Raises:
- NotImplementedError: this method is an abstract method.
- logger¶
(Property) A logger object of the logging.Logger class with an appropriate channel name.
See also
- static position_conflict(horizontal_coordinates, vertical_coordinates, index=-1)¶
If index is less than 0, checks whether the given coordinates are unique, that is, if no two points have the same horizontal and vertical coordinates. Otherwise, checks if there is a point that has the same coordinates as these at the index position.
- Parameters:
- horizontal_coordinates (list): a list of horizontal coordinates;
- vertical_coordinates (list): a list of vertical coordinates;
- index (int): an index of the coordinate lists; if greater than -1, it is checked whether there is a point with the same horizontal and vertical coordinates as at index.
- Returns:
- (int) an index of the coordinate that is in conflict, or -1 if the given coordinates are unique.
- Raises:
- ValueError: if given coordinate lists have different lengths, or if a given value of the index parameter is greater than the total number of coordinates.
Examples:
>>> Placement.position_conflict([1, 2, 2, 4], [5, 6, 6, 7]) 2 >>> Placement.position_conflict([1, 2, 2, 4], [5, 6, 6, 7], 1) 2 >>> Placement.position_conflict([1, 2, 2, 4], [5, 6, 6, 7], 0) -1
- random_generator¶
(Property) An object representing the sim2net.utility.randomness._Randomness pseudo-random number generator.
Module sim2net.placement.grid¶
Provides an implementation of the grid placement model.
In the grid placement model nodes are placed at intersections of a square or rectangular grid. Usually, the grid has quadratic-shaped cells with edge length that is close to the communication radius of a node. It creates networks that are regular in shape and provides excellent connectivity at a startup.
- class sim2net.placement.grid.Grid(area, nodes_number, transmission_range)¶
Bases: sim2net.placement._placement.Placement
This class implements the grid placement model, in which a given number of nodes are placed at intersections of a square or rectangular grid within a simulator area.
- Parameters:
- area: an object representing the simulation area;
- nodes_number (int): a number of nodes to place within the simulation area;
- transmission_range (float): a value of the transmission (or communication) radius of nodes, that is, the distance from a transmitter at which the signal strength remains above the minimum usable level.
- Raises:
- ValueError: raised when: the given number of nodes or transmission range is less or equal to 0, or when the given value of the area parameter is None.
- _Grid__adjust_grid_dimensions(columns, rows)¶
Adjusts the given grid dimensions to the size of the simulation area. If the area shape is square and the grid shape is rectangular, the longer side of the grid is placed along the horizontal x-axis of the simulation area. If both shapes are rectangular, the longer side of the grid is placed along the longer size of the simulation area.
- Parameters:
- columns (int): a number of grid columns;
- rows (int): a number of grid rows.
- Returns:
- A number of grid columns and rows as a tuple.
- _Grid__get_grid_dimensions()¶
Calculates dimensions of the grid based on the number of nodes. If the number has a square root, the grid shape will be a square, otherwise it will be a rectangular. In the worst case if the number of nodes is prime, the number of rows (or columns) will be equal to one.
- Returns:
- A number of grid columns and rows as a tuple.
- _Grid__get_horizontal_coordinates(columns, rows, distance)¶
Generates horizontal coordinates of nodes based on the number of columns, rows and the distance between nodes.
- Returns:
- A list of horizontal coordinates.
- _Grid__get_nodes_distance(columns, rows)¶
Calculates a distance between nodes in the same row and column based on the their transmission ranges. The distance is also adjust to fit the dimensions of the simulation area.
- Returns:
- A distance between nodes in the grid of type float.
- _Grid__get_vertical_coordinates(columns, rows, distance)¶
Generates vertical coordinates of nodes based on the number of columns, rows and the distance between nodes.
- Returns:
- A list of vertical coordinates.
- get_placement()¶
Generates grid placement coordinates for the given number of nodes and its transmission ranges and returns the result as a dictionary.
- Returns:
- A list of tuples of horizontal and vertical coordinates for each host.
Module sim2net.placement.normal¶
Provides an implementation of the normal placement model.
In the normal placement model, a simulation area of a given size is chosen and a given number of nodes are placed over it with the normal, i.e. Gaussian, probability distribution.
- class sim2net.placement.normal.Normal(area, nodes_number, standard_deviation=0.2)¶
Bases: sim2net.placement._placement.Placement
This class implements the normal placement model, in which a given number of nodes are placed over a simulation area with the normal probability distribution.
- Parameters:
- area: an object representing the simulation area;
- nodes_number (int): a number of nodes to place over the simulation area;
- standard_deviation (float): a value of the standard deviation (default: 0.2).
- Raises:
- ValueError: raised when the number of nodes is less or equal to 0, or when the given value of the area parameter is None.
- get_placement()¶
Generates normal (Gaussian) placement coordinates for the given number of nodes and returns the result as a dictionary.
The means used here are computed as follows: \(\frac{1}{2}\times area~width\) and \(\frac{1}{2}\times area~height\).
- Returns:
- A list of tuples of horizontal and vertical coordinates for each host.
Module placement.uniform¶
Provides an implementation of the uniform placement model.
In the uniform placement model, a simulation area of a given size is chosen and a given number of nodes are placed over it with the uniform probability distribution.
- class sim2net.placement.uniform.Uniform(area, nodes_number)¶
Bases: sim2net.placement._placement.Placement
This class implements implements the uniform placement model, in which a given number of nodes are placed over a simulation area with the uniform probability distribution.
- Parameters:
- area: an object representing the simulation area;
- nodes_number (int): a number of nodes to place over the simulation area.
- Raises:
- ValueError: raised when the number of nodes is less or equal to 0, or when the given value of the area parameter is None.
- get_placement()¶
Generates uniform placement coordinates for the given number of nodes and returns the result as a dictionary.
- Returns:
- A list of tuples of horizontal and vertical coordinates for each host.