Graph
- class compas.datastructures.Graph[source]
Bases:
Datastructure
Data structure for describing the relationships between nodes connected by edges.
- Parameters:
- default_node_attributesdict, optional
Default values for node attributes.
- default_edge_attributesdict, optional
Default values for edge attributes.
- namestr, optional
The name of the graph.
- **kwargsdict, optional
Additional keyword arguments, which are stored in the attributes dict.
- Attributes:
- default_node_attributesdict[str, Any]
dictionary containing default values for the attributes of nodes. It is recommended to add a default to this dictionary using
update_default_node_attributes()
for every node attribute used in the data structure.- default_edge_attributesdict[str, Any]
dictionary containing default values for the attributes of edges. It is recommended to add a default to this dictionary using
update_default_edge_attributes()
for every edge attribute used in the data structure.
Methods
Constructors
Create a new graph instance from information about the edges. |
|
Construct an object of this type from a JSON file. |
|
Construct a graph from a set of lines represented by their start and end point coordinates. |
|
Create a new graph instance from a NetworkX DiGraph instance. |
|
Construct a graph from nodes and edges. |
|
Construct a graph from the data contained in an OBJ file. |
|
Construct a graph from random connections between the points of a pointcloud. |
Conversions
Convert an object to its native data representation and save it to a JSON file. |
|
Return the lines of the graph as pairs of start and end point coordinates. |
|
Create a new NetworkX graph instance from a graph. |
|
Write the graph to an OBJ file. |
|
Return the coordinates of the graph. |
Builders and Modifiers
Add an edge and specify its attributes. |
|
Add a node and specify its attributes (optional). |
|
Delete an edge from the graph. |
|
Delete a node from the graph. |
|
Join the edges incidental on the given node, if there are exactly two incident edges. |
|
Split and edge by inserting a node along its length. |
Accessors
Get the identifiers of a set of random edges. |
|
Iterate over the edges of the graph. |
|
Get edges for which a certain condition or set of conditions is true. |
|
Get edges for which a certain condition or set of conditions is true using a lambda function. |
|
Get a list of identifiers of a random set of n nodes. |
|
Iterate over the nodes of the graph. |
|
Get nodes for which a certain condition or set of conditions is true. |
|
Get nodes for which a certain condition or set of conditions is true using a lambda function. |
Attributes
Get or set an attribute of an edge. |
|
Get or set multiple attributes of an edge. |
|
Get or set an attribute of multiple edges. |
|
Get or set multiple attributes of multiple edges. |
|
Get or set an attribute of a node. |
|
Get or set multiple attributes of a node. |
|
Get or set an attribute of multiple nodes. |
|
Get or set multiple attributes of multiple nodes. |
|
Update the default edge attributes. |
|
Update the default node attributes. |
|
Unset the attribute of an edge. |
|
Unset the attribute of a node. |
Topology
Generate the complement of a graph. |
|
Get groups of connected nodes. |
|
Get groups of connected edges. |
|
Return the number of neighbors of a node. |
|
Return the number of outgoing neighbors of a node. |
|
Return the numer of incoming neighbors of a node. |
|
Explode the graph into its connected components. |
|
Verify if the graph contains a specific edge. |
|
Verify if a specific node is present in the graph. |
|
Verify if a node is a leaf. |
|
Verify if a specific node is connected. |
|
Return the nodes in the neighborhood of a node. |
|
Return the neighbors of a node. |
|
Return the incoming neighbors of a node. |
|
Return the outgoing neighbors of a node. |
|
Return the edges connected to a node. |
|
Compute the number of edges of the graph. |
|
Compute the number of nodes of the graph. |
Geometry
Return the coordinates of the start and end point of an edge. |
|
Return the direction vector of an edge. |
|
Return the end point of an edge. |
|
Return the length of an edge. |
|
Return the line of an edge. |
|
Return the location of the midpoint of an edge. |
|
Return the point at a parametric location along an edge. |
|
Return the start point of an edge. |
|
Return the vector of an edge. |
|
Return the coordinates of a node. |
|
Return the point of a node. |
|
Return the vector from the node to the centroid of its 1-ring neighborhood. |
|
Return the computed centroid of the neighboring nodes. |
|
Transform all nodes of the graph. |
|
Returns a transformed copy of this data structure. |
Paths
Find the shortest path between two nodes using the A* algorithm. |
Planarity
Count the number of crossings (pairs of crossing edges) in the graph. |
|
Embed the graph in the plane. |
|
Identify all pairs of crossing edges in a graph. |
|
Find the faces of a graph. |
|
Verify if a graph has crossing edges. |
|
Check if the graph is planar. |
|
Verify that a graph is embedded in the plane without crossing edges. |
|
Verify that a graph lies in the XY plane. |
Matrices
Creates a node adjacency matrix from a Graph datastructure. |
|
Creates a connectivity matrix from a Graph datastructure. |
|
Creates a degree matrix from a Graph datastructure. |
|
Creates a Laplacian matrix from a Graph datastructure. |
Mappings
Returns a dictionary that maps geometric keys of a certain precision to the identifiers of the corresponding nodes. |
|
Returns a dictionary that maps node identifiers to the corresponding geometric key up to a certain precision. |
|
Returns a dictionary that maps node identifiers to their corresponding index in a node list or array. |
|
Returns a dictionary that maps edge identifiers (i.e. |
|
Returns a dictionary that maps the indices of a node list to keys in a node dictionary. |
|
Returns a dictionary that maps edges in a list to the corresponding vertex identifier pairs. |
Utilities
Return a summary of the graph. |
|
Make an independent copy of the data object. |
|
Clear all the graph data. |