Graph
- class compas.datastructures.Graph(name=None, default_node_attributes=None, default_edge_attributes=None)[source]
Bases:
Datastructure
Base graph data structure for describing the topological relationships between nodes connected by edges.
- Parameters
name (str, optional) – The name of the datastructure.
default_node_attributes (dict[str, Any], optional) – Default values for node attributes.
default_edge_attributes (dict[str, Any], optional) – Default values for edge attributes.
- Attributes
attributes (dict[str, Any]) – General attributes of the data structure that are included in the data representation and serialization.
default_node_attributes (dict[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_attributes (dict[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.
Examples
>>>
Methods
Add an edge and specify its attributes.
Add a node and specify its attributes (optional).
Clear all the network data.
Return the edges connected to a node.
Return the number of neighbors of a node.
Return the numer of incoming neighbors of a node.
Return the number of outgoing neighbors of a node.
Delete an edge from the network.
Delete a node from the graph.
Get or set an attribute of an edge.
Get or set multiple attributes of an edge.
Get the identifiers of a set of random edges.
Iterate over the edges of the network.
Get or set an attribute of multiple edges.
Get or set multiple attributes of multiple edges.
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.
Create a new graph instance from information about the edges.
Create a new graph instance from a NetworkX DiGraph instance.
Get the identifier of a random edge.
Get the identifiers of a set of random edges.
Get the identifier of a random node.
Get a list of identifiers of a random set of n nodes.
Verify if the network contains a specific edge.
Verify if a specific node is present in the network.
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 key pairs.
Verify if a node is a leaf.
Verify if a specific node is connected.
Returns a dictionary that maps node identifiers to their corresponding index in a node list or array.
Return all leaves of the network.
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.
Get or set an attribute of a node.
Get or set multiple attributes of a node.
Get a list of identifiers of a random set of n nodes.
Iterate over the nodes of the network.
Get or set an attribute of multiple nodes.
Get or set multiple attributes of multiple nodes.
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.
Compute the number of edges of the graph.
Compute the number of nodes of the graph.
Return a summary of the graph.
Create a new NetworkX graph instance from a graph.
Unset the attribute of an edge.
Unset the attribute of a node.
Update the default edge attributes.
Update the default edge attributes.
Update the default node attributes.
Update the default node attributes.
Returns a dictionary that maps edge keys (i.e.
Inherited Methods
Make an independent copy of the data object.
Construct an object of this type from the provided data.
Construct an object from serialized data contained in a JSON file.
Construct an object from serialized data contained in a JSON string.
Convert an object to its native data representation.
Serialize the data representation of an object to a JSON file.
Serialize the data representation of an object to a JSON string.
Validate the object's data against its data schema.
Validate the object's data against its json schema.