pydistsim.network.rangenetwork.RangeNetworkMixin
- class RangeNetworkMixin(incoming_graph_data=None, environment: Environment | None = None, rangeType: RangeType | None = None, behavioral_properties: NetworkBehaviorModel | None = None, **kwargs)[source]
Bases:
objectMixin to define a type of network that decides which nodes are connected based on their communication range.
- Parameters:
environment (Environment, optional) – The environment in which the network operates. If not provided, a new Environment instance will be created.
rangeType (RangeType, optional) – The type of channel to be used for communication. If not provided, a new RangeType instance will be created using the environment.
graph (NetworkX graph, optional) – The graph representing the network topology. Defaults to None.
kwargs – Additional keyword arguments.
Methods
__init__Add an edge to the network.
add_nodeDEPRECATED AND UNTESTED
Recalculate edges for given nodes or for all self.nodes().
remove_nodeto_directed_classto_undirected_classvalidate_params- add_edge(u_of_edge, v_of_edge, **attr)[source]
Add an edge to the network.
- Parameters:
u_of_edge – The source node of the edge.
v_of_edge – The target node of the edge.
attr – Additional attributes to be assigned to the edge.
- modify_avg_degree(value)[source]
DEPRECATED AND UNTESTED
Modifies (increases) average degree based on the given value by modifying nodes’ commRange.
- Parameters:
value (float) – The desired average degree value.
- Raises:
AssertionError – If all nodes do not have the same commRange.
AssertionError – If the given value is not greater than the current average degree.
This method increases the average degree of the network by modifying the communication range (commRange) of the nodes. It ensures that all nodes have the same communication range.
The method uses a step-wise approach to gradually increase the average degree until it reaches the desired value. It adjusts the communication range of each node in the network by adding a step size calculated based on the difference between the desired average degree and the current average degree.
The step size is determined by the step_factor parameter, which controls the rate of change in the communication range. If the step size overshoots or undershoots the desired average degree, the step_factor is halved to reduce the step size for the next iteration.
Once the average degree reaches the desired value, the method logs the modified degree.
Note: This method assumes that the network is initially connected and all nodes have the same communication range.
- Example usage:
network.modify_avg_degree(5.0)
- recalculate_edges(nodes: Iterable | None = None)[source]
Recalculate edges for given nodes or for all self.nodes().
- Parameters:
nodes (list, optional) – A list of nodes to recalculate edges for. If not provided, edges will be recalculated for all nodes in the network.
Edge between nodes n1 and n2 are added if both are RangeType.in_comm_range of each other.