Graph Fundamentals#
The Graph class is the foundation for all graph-based analysis in volmdlr_tools.
It wraps networkx graphs with dessia_common serialization support.
Overview#
All graph types in volmdlr_tools inherit from the base Graph class:
AttributedAdjacencyGraph (AAG): Face adjacency graphs for BRep models
GraphAssembly: Assembly structure graphs
The base class provides common operations for node/edge manipulation, attribute management, and filtering.
Key Concepts#
Nodes and Edges#
Graphs consist of nodes (vertices) and edges (connections):
from volmdlr_tools.graph import Graph
# Create a graph
graph = Graph()
# Add nodes with attributes
graph.add_node(0, name="part_a", color="red")
graph.add_node(1, name="part_b", color="blue")
# Add edge between nodes
graph.add_edge(0, 1, distance=10.5)
Attribute Management#
Set and get attributes on nodes and edges:
# Get node attribute
name = graph.get_node_attribute(0, "name")
# Set node attribute
graph.set_node_attribute(0, "mass", 2.5)
# Get edge attribute
dist = graph.get_edge_attribute((0, 1), "distance")
# Set edge attribute with computation function
graph.set_edges_attribute("weight", lambda e: compute_weight(e))
Filtering#
Filter nodes and edges using callable functions:
# Get nodes matching a condition
red_nodes = graph.get_nodes(filter_function=lambda n: graph[n].get("color") == "red")
# Get edges matching a condition
short_edges = graph.get_edges(filter_function=lambda e: graph[e].get("distance") < 5)
Subgraphs#
Extract subgraphs from filtered nodes or edges:
# Get subgraph containing only specific nodes
subgraph = graph.subgraph([0, 1, 2])
# Get edge-induced subgraph
edge_subgraph = graph.edge_subgraph([(0, 1), (1, 2)])
See Also#
Attributed Adjacency Graph (AAG) - Attributed Adjacency Graph for face analysis
GraphAssembly - Assembly graphs for multi-part analysis