Graph

class compas.datastructures.Graph[source]

Bases: Datastructure

Base graph data structure for describing the topological relationships between nodes connected by edges.

Parameters:
default_node_attributesdict[str, Any], optional

Default values for node attributes.

default_edge_attributesdict[str, Any], optional

Default values for edge attributes.

**kwargsdict, optional

Additional keyword arguments are passed to the base class, and will be stored in the attributes attribute.

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

add_edge

Add an edge and specify its attributes.

add_node

Add a node and specify its attributes (optional).

clear

Clear all the network data.

connected_edges

Return the edges connected to a node.

degree

Return the number of neighbors of a node.

degree_in

Return the numer of incoming neighbors of a node.

degree_out

Return the number of outgoing neighbors of a node.

delete_edge

Delete an edge from the network.

delete_node

Delete a node from the graph.

edge_attribute

Get or set an attribute of an edge.

edge_attributes

Get or set multiple attributes of an edge.

edge_index

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

edge_sample

Get the identifiers of a set of random edges.

edges

Iterate over the edges of the network.

edges_attribute

Get or set an attribute of multiple edges.

edges_attributes

Get or set multiple attributes of multiple edges.

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.

from_data

Construct an object of this type from the provided data.

from_edges

Create a new graph instance from information about the edges.

from_networkx

Create a new graph instance from a NetworkX DiGraph instance.

has_edge

Verify if the network contains a specific edge.

has_node

Verify if a specific node is present in the network.

index_edge

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

index_node

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

is_leaf

Verify if a node is a leaf.

is_node_connected

Verify if a specific node is connected.

leaves

Return all leaves of the network.

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_attribute

Get or set an attribute of a node.

node_attributes

Get or set multiple attributes of a node.

node_index

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

node_sample

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

nodes

Iterate over the nodes of the network.

nodes_attribute

Get or set an attribute of multiple nodes.

nodes_attributes

Get or set multiple attributes of multiple nodes.

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.

number_of_edges

Compute the number of edges of the graph.

number_of_nodes

Compute the number of nodes of the graph.

summary

Return a summary of the graph.

to_networkx

Create a new NetworkX graph instance from a graph.

unset_edge_attribute

Unset the attribute of an edge.

unset_node_attribute

Unset the attribute of a node.

update_dea

Update the default edge attributes.

update_default_edge_attributes

Update the default edge attributes.

update_default_node_attributes

Update the default node attributes.

update_dna

Update the default node attributes.

Inherited Methods

ToString

Converts the instance to a string.

copy

Make an independent copy of the data object.

from_json

Construct an object of this type from a JSON file.

from_jsonstring

Construct an object of this type from a JSON string.

sha256

Compute a hash of the data for comparison during version control using the sha256 algorithm.

to_data

Convert an object to its native data representation.

to_json

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

to_jsonstring

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

validate_data

Validate the data against the object's data schema.