Network

class compas.datastructures.Network[source]

Bases: Graph

Geometric implementation of an edge graph.

Parameters:
default_node_attributes: dict, optional

Default values for node attributes.

default_edge_attributes: dict, optional

Default values for edge attributes.

**kwargsdict, optional

Additional attributes to add to the network.

Methods

Constructors

from_edges

Create a new graph instance from information about the edges.

from_json

Construct an object of this type from a JSON file.

from_lines

Construct a network from a set of lines represented by their start and end point coordinates.

from_networkx

Create a new graph instance from a NetworkX DiGraph instance.

from_nodes_and_edges

Construct a network from nodes and edges.

from_obj

Construct a network from the data contained in an OBJ file.

from_pointcloud

Construct a network from random connections between the points of a pointcloud.

Conversions

to_json

Convert an object to its native data representation and save it to a JSON file.

to_lines

Return the lines of the network as pairs of start and end point coordinates.

to_networkx

Create a new NetworkX graph instance from a graph.

to_obj

Write the network to an OBJ file.

to_points

Return the coordinates of the network.

Builders and Modifiers

add_edge

Add an edge and specify its attributes.

add_node

Add a node and specify its attributes (optional).

delete_edge

Delete an edge from the network.

delete_node

Delete a node from the graph.

join_edges

Join the edges incidental on the given node, if there are exactly two incident edges.

split_edge

Split and edge by inserting a node along its length.

Accessors

edge_sample

Get the identifiers of a set of random edges.

edges

Iterate over the edges of the network.

edges_where

Get edges for which a certain condition or set of conditions is true.

edges_where_predicate

Get edges for which a certain condition or set of conditions is true using a lambda function.

node_sample

Get a list of identifiers of a random set of n nodes.

nodes

Iterate over the nodes of the network.

nodes_where

Get nodes for which a certain condition or set of conditions is true.

nodes_where_predicate

Get nodes for which a certain condition or set of conditions is true using a lambda function.

Attributes

edge_attribute

Get or set an attribute of an edge.

edge_attributes

Get or set multiple attributes of an edge.

edges_attribute

Get or set an attribute of multiple edges.

edges_attributes

Get or set multiple attributes of multiple edges.

node_attribute

Get or set an attribute of a node.

node_attributes

Get or set multiple attributes of a node.

nodes_attribute

Get or set an attribute of multiple nodes.

nodes_attributes

Get or set multiple attributes of multiple nodes.

update_default_edge_attributes

Update the default edge attributes.

update_default_node_attributes

Update the default node attributes.

unset_edge_attribute

Unset the attribute of an edge.

unset_node_attribute

Unset the attribute of a node.

Topology

complement

Generate the complement of a graph.

connected_nodes

Get groups of connected nodes.

connected_edges

Get groups of connected edges.

degree

Return the number of neighbors of a node.

degree_out

Return the number of outgoing neighbors of a node.

degree_in

Return the numer of incoming neighbors of a node.

exploded

Explode the graph into its connected components.

has_edge

Verify if the network contains a specific edge.

has_node

Verify if a specific node is present in the network.

is_leaf

Verify if a node is a leaf.

is_node_connected

Verify if a specific node is connected.

neighborhood

Return the nodes in the neighborhood of a node.

neighbors

Return the neighbors of a node.

neighbors_in

Return the incoming neighbors of a node.

neighbors_out

Return the outgoing neighbors of a node.

node_edges

Return the edges connected to a node.

number_of_edges

Compute the number of edges of the graph.

number_of_nodes

Compute the number of nodes of the graph.

Geometry

edge_coordinates

Return the coordinates of the start and end point of an edge.

edge_direction

Return the direction vector of an edge.

edge_end

Return the end point of an edge.

edge_length

Return the length of an edge.

edge_line

Return the line of an edge.

edge_midpoint

Return the location of the midpoint of an edge.

edge_point

Return the point at a parametric location along an edge.

edge_start

Return the start point of an edge.

edge_vector

Return the vector of an edge.

node_coordinates

Return the coordinates of a node.

node_point

Return the point of a node.

node_laplacian

Return the vector from the node to the centroid of its 1-ring neighborhood.

node_neighborhood_centroid

Return the computed centroid of the neighboring nodes.

transform

Transform all nodes of the network.

transformed

Returns a transformed copy of this data structure.

Paths

shortest_path

Find the shortest path between two nodes using the A* algorithm.

Planarity

count_crossings

Count the number of crossings (pairs of crossing edges) in the network.

embed_in_plane

Embed the network in the plane.

find_crossings

Identify all pairs of crossing edges in a network.

find_cycles

Find the faces of a network.

is_crossed

Verify if a network has crossing edges.

is_planar

Check if the network is planar.

is_planar_embedding

Verify that a network is embedded in the plane without crossing edges.

is_xy

Verify that a network lies in the XY plane.

Matrices

adjacency_matrix

Creates a node adjacency matrix from a Network datastructure.

connectivity_matrix

Creates a connectivity matrix from a Network datastructure.

degree_matrix

Creates a degree matrix from a Network datastructure.

laplacian_matrix

Creates a Laplacian matrix from a Network datastructure.

Mappings

gkey_node

Returns a dictionary that maps geometric keys of a certain precision to the identifiers of the corresponding nodes.

node_gkey

Returns a dictionary that maps node identifiers to the corresponding geometric key up to a certain precision.

node_index

Returns a dictionary that maps node identifiers to their corresponding index in a node list or array.

edge_index

Returns a dictionary that maps edge identifiers (i.e.

index_node

Returns a dictionary that maps the indices of a node list to keys in a node dictionary.

index_edge

Returns a dictionary that maps edges in a list to the corresponding vertex identifier pairs.

Utilities

summary

Return a summary of the graph.

copy

Make an independent copy of the data object.

clear

Clear all the network data.