# Welcome to extended-networkx-tools’s documentation!¶

class Analytics.Analytics[source]

Bases: object

static convergence_rate(nxg: networkx.classes.graph.Graph = None, stochastic_neighbour_matrix: List[List[float]] = None) → float[source]

Function to retrieve the 2nd largest eigenvalue in the adjacency matrix of a graph

Parameters: nxg (nx.Graph) – networkx bi-directional graph object stochastic_neighbour_matrix (List[List[float]]) – The stochastic neighbour matrix of the given graph. The 2nd largest eigenvalue of the adjacency matrix float
static convergence_rate2(nxg: networkx.classes.graph.Graph) → float[source]

Function to retrieve convergence rate based on an alternate approach.

Parameters: nxg (nx.Graph) – networkx bi-directional graph object Alternate convergence rage float
convergence_rate_cuda[source]
static get_adjacency_matrix(nxg: networkx.classes.graph.Graph, self_assignment=False) → List[List[int]][source]

Creates a neighbour matrix for a specified graph: g, each row represents a node in the graph where the values in each column represents if there is an edge or not between those nodes.

Parameters: nxg (bool) – networkx bi-directional graph object. self_assignment – Whether or not to use self assignment in the graph. Used for convergence rate. List of rows, representing the adjacency matrix. List[List[float]]
static get_average_eccentricity(nxg: networkx.classes.graph.Graph) → float[source]

Calculates the average eccentricity from the given graph.

Return type: float nxg – The graph to get the average eccentricity from. The average eccentricty from the graph.
static get_degree_matrix(nxg: networkx.classes.graph.Graph) → List[List[int]][source]
static get_distance_distribution(nxg: networkx.classes.graph.Graph) → Dict[int, int][source]

Makes a list representing the distribution of longest shortest paths between every node in the graph.

Return type: Dict[int, int] nxg – A given graph with edges. A dict with a distribution of the longest shortest paths between nodes.
static get_eccentricity_distribution(nxg: networkx.classes.graph.Graph) → Dict[int, int][source]

Makes a list representing the distribution of longest shortest paths between every node in the graph.

Return type: Dict[int, int] nxg – A given graph with edges. A dict with a distribution of the longest shortest paths between nodes.
static get_edge_dict(nxg: networkx.classes.graph.Graph) → Dict[int, List[int]][source]

Converts a networkx object to a dict with edges and their neighbours. Can be used to recreate a new graph with Creator.from_dict().

Return type: Dict[int, List[int]] nxg – The graph to get the edges from. A neighbour list for all nodes.
static get_eigenvalues(mx: List[List[float]], symmetrical: bool = False) → numpy.ndarray[source]

Simple function to retrieve the eigenvalues of a matrix.

Parameters: mx – A matrix made up of nested lists. symmetrical – Whether or not the matrix is symmetrical. If tru it can make faster computations. List of eigenvalues of the provided matrix. List[float]
static get_laplacian_matrix(nxg: networkx.classes.graph.Graph) → List[List[int]][source]

Calculates the laplacian matrix based on a given graph.

Parameters: nxg – The graph to get the laplacian matrix from. The laplacian matrix, such as L = D - A where D = Degree matrix and A = Adjacency matrix
static get_neighbour_matrix(nxg: networkx.classes.graph.Graph)[source]
static get_node_dict(nxg: networkx.classes.graph.Graph) → Dict[int, Tuple[int, int]][source]

Converts a networkx object to a dict with nodes and their positions. Can be used to recreate a new graph with Creator.from_dict().

Return type: Dict[int, Tuple[int, int]] nxg – The graph to get the nodes from. A dict of nodes with their corresponding positions.
static get_stochastic_neighbour_matrix(nxg: networkx.classes.graph.Graph = None, adjacency_matrix: List[List[int]] = None) → List[List[float]][source]

Creates a stochastic adjacency matrix for a specified graph: g, each row represents a node in the graph where the values in each column represents if there is an edge or not between those nodes. The values for each neighbour is represented by 1/(number of neighbours), if no edge exists this value is 0.

Parameters: nxg (nx.Graph) – Networkx bi-directional graph object. adjacency_matrix (List[List[int]]) – Self assigned adjacency matrix. List of rows, representing the adjacency matrix. List[List[float]]
static hypothetical_max_edge_cost(nxg: networkx.classes.graph.Graph) → float[source]

Calculates the hypothetical total edge cost if the graph were to be complete.

Return type: float nxg – The graph to calculate the hypothetical edge cost of. The total edge cost if the graph were complete.
static is_graph_connected(laplacian_matrix: List[List[int]])[source]

Checks whether a given graph is connected based on its laplacian matrix.

Parameters: laplacian_matrix – The laplacian matrix, representing the graph. Whether it’s connected or not.
static is_nodes_connected(nxg: networkx.classes.graph.Graph, origin: int, destination: int) → bool[source]

Checks if two nodes are connected with each other using a BFS approach.

Parameters: nxg – The grapg that contains the two nodes. origin – The origin node id to check from. destination – The destination node to check the connectivity to. True if there’s a connection between the nodes, otherwise False.
is_nodes_connected_cuda[source]
static second_largest(numbers: List[float], sorted_list: bool = False) → float[source]

Simple function to return the 2nd largest number in a list of numbers.

Parameters: numbers – A list of numbers sorted_list – If the list is sorted or not The 2nd largest number in the list numbers float
second_largest_cuda[source]

Simple function to return the 2nd largest number in a list of numbers.

Parameters: numbers – A list of numbers The 2nd largest number in the list numbers float
static second_smallest(numbers: List[float], sorted_list: bool = False) → float[source]

Simple function to return the 2nd smallest number in a list of numbers.

Parameters: numbers – A list of numbers sorted_list – If the list is sorted or not The 2nd smallest number in the list numbers float
static total_edge_cost(nxg: networkx.classes.graph.Graph) → int[source]

Calculates the total cost of all edges in the given graph

Parameters: nxg (nx.Graph) – A networkx object with nodes and edges. The total cost of all edges in the graph. float
class Creator.Creator[source]

Bases: object

Static class that works with creating graph objects from given specifications. Can either create a random unassigned graph with given nodes or a graph with edges from given parameters.

static add_weighted_edge(nxg: networkx.classes.graph.Graph, origin: int, destination: int, ignore_validity: bool = False) → bool[source]

Adds a bidirectional edge between 2 nodes with weight corresponding to the distance between the nodes squared.

Parameters: nxg – The graph to add an edge to. origin – First node id to add the edge from destination – Second node id to add the edge to. ignore_validity – Whether to skip the validity check when adding the edge True if the edge was added, otherwise false if the edge already existed.
static from_random(node_count: int, area_dimension: int = None) → networkx.classes.graph.Graph[source]

Creates an unassigned graph with nodes of random position. The work area corresponds to the node count squared.

Return type: networkx.Graph node_count – The number of nodes to create a graph from. area_dimension – The size of the area to put nodes in. Defaults to the node count. An unassigned graph with nodes with random position.
static from_spec(v: Dict[int, Tuple[int, int]], e: Dict[int, List[int]]) → networkx.classes.graph.Graph[source]

Creates a graph from given parameters, that also assigns weighted edges based on a neighbour list.

Parameters: v – Nodes in the graph. Should be a dict with the format { node_1: (x, y), node_2: (x, y)… } e – Edges that connects the nodes.Should be a dict with the format { node_1: [dest_1, dest_2, …], node_2: [dest_3, dest_4, …] } A graph with assigned nodes and weighted edges. networkx.Graph
class Solver.Solver[source]

Bases: object

Class to add edges to given networkx grahps taken from simple Graph Theory, such as path, cycle and complete graph.

static complete(nxg: networkx.classes.graph.Graph) → networkx.classes.graph.Graph[source]

Makes a graph a complete graph, such as all nodes are connected to each other with one edge.

Return type: networkx.Graph nxg – A graph with nodes containing coordinates. A complete graph.
static cycle(nxg: networkx.classes.graph.Graph) → networkx.classes.graph.Graph[source]

Adds edges to a given graph as a path, such as the following: (0, 1), (1, 2), … (n-1, n), (n, 0)

Return type: networkx.Graph nxg – A graph with nodes containing coordinates. A graph with connected nodes such as they form a cycle.
static path(nxg: networkx.classes.graph.Graph) → networkx.classes.graph.Graph[source]

Adds edges to a given graph as a path, such as the following: (0, 1), (1, 2), … (n-1, n)

Return type: networkx.Graph nxg – A graph with nodes containing coordinates. A graph with connected nodes such as they form a path.
class Visual.Visual[source]

Bases: object

Static class that only helps in visualising graph information.

static draw(nx_graph)[source]

Takes a networkx graph and prints the nodes with given edges in the fixed positions.

Parameters: nx_graph (networkx.Graph) – The networkx object to show the graph from.
static save(nx_graph, filename)[source]

Takes a networkx graph and save graph with given edges in the fixed positions to a PNG-image.

Parameters: nx_graph (networkx.Graph) – The networkx object to show the graph from.
class AnalyticsGraph.AnalyticsGraph(nxg: networkx.classes.graph.Graph)[source]

Bases: object

add_edge(origin, destination)[source]
get_adjacency_matrix_sa()[source]
get_convergence_rate() → float[source]

Calculates the convergence rate for the current graph.

get_dimension()[source]
get_edge_cost() → float[source]

Calculates the edge cost for the current graph.

get_laplacian_matrix()[source]
graph() → networkx.classes.graph.Graph[source]

Returns the graph instance that the class has been working on.

Returns: The current networkx graph instance.
has_edge(origin, destination)[source]

Checks whether the graph has an edge by looking up directly in a adjacency matrix.

Parameters: origin – destination –
is_connected() → bool[source]

Checks whether the graph is connected or not.

move_edge(origin, old_destination, new_destination)[source]
remove_edge(origin, destination)[source]
reset_stage_actions()[source]
revert()[source]