C++ API
-
class BaseNode
- #include <base_node.h>
Base class for all vertex property classes in the GHL.
BaseNode provides core functionality for vertex properties, including:
Unique identification through ID management
Cloning capability for graph operations
GraphViz attribute generation for visualization
Optional serialization support
This class is designed to be inherited from when creating custom vertex property types. See the City class in examples/city.h for an example of proper inheritance and extension.
Public Functions
-
inline explicit BaseNode(int id = -1)
Constructs a BaseNode with the specified ID.
- Parameters:
id – The unique identifier for the node. Defaults to -1 if not specified.
-
inline virtual std::shared_ptr<BaseNode> clone()
Creates a clone of the node.
This virtual method enables polymorphic cloning of nodes, which is essential for graph operations that require copying vertices.
- Returns:
std::shared_ptr<BaseNode> A smart pointer to a new instance with the same properties.
-
virtual ~BaseNode() = default
Virtual destructor to ensure proper cleanup of derived classes.
-
inline int id() const
Gets the node’s ID.
- Returns:
The unique identifier of the node.
-
inline void id(int id)
Sets the node’s ID.
- Parameters:
id – The new unique identifier for the node.
-
inline bool operator==(const BaseNode &other) const
Equality comparison operator.
Nodes are considered equal if they have the same ID. This is used in graph algorithms that need to compare vertices.
- Parameters:
other – The node to compare with.
- Returns:
true if the nodes have the same ID, false otherwise.
-
inline virtual std::map<std::string, std::string, std::less<>> graphAttributes()
Generates GraphViz attributes for visualization.
This virtual method can be overridden by derived classes to customize the appearance of nodes in GraphViz output. The base implementation provides a simple label with the node’s ID.
- Returns:
A map of GraphViz attribute names to values.
Private Members
-
int id_ = INT_MIN
Unique identifier for the node.
-
template<class T>
class construct
-
struct edge_comp_helper
- #include <graph_isomorphisms.h>
Helper struct for edge comparison during isomorphism detection.
-
template<typename VertexProperties, typename DirectionProperty, typename EdgeProperties = b::no_property>
struct EdgeReplacementStruct - #include <graph.h>
Represents the replacement of an edge in a graph.
- Template Parameters:
VertexProperties – Properties associated with vertices.
DirectionProperty – Boost direction selector for the graph.
EdgeProperties – Properties associated with edges (default:
boost::no_property).
Public Types
-
using VertexDescriptor = Graph<VertexProperties, DirectionProperty, EdgeProperties>::vertex_descriptor
Vertex descriptor type.
Public Members
-
VertexDescriptor src_trg
The source or target vertex of the edge.
-
VertexDescriptor old_vertex
The old vertex to be replaced.
-
VertexDescriptor new_vertex
The new vertex replacing the old one.
-
EdgeProperties edge_properties
Properties of the edge being replaced.
-
template<typename VertexProperties_, typename DirectionProperty_, typename EdgeProperties_ = b::no_property>
class ExtendedGraph - #include <graph.h>
A wrapper class around a Boost graph providing extended functionality.
- Template Parameters:
VertexProperties – Properties associated with vertices.
DirectionProperty – Boost direction selector for the underlying graph.
EdgeProperties – Properties associated with edges (default:
boost::no_property).
Public Types
-
using GraphType = Graph<VertexProperties_, DirectionProperty_, EdgeProperties_>
Alias for the graph type.
-
using VertexProperties = VertexProperties_
Vertex property type.
-
using DirectionProperty = DirectionProperty_
Graph direction selector type.
-
using EdgeProperties = EdgeProperties_
Edge property type.
-
using IsoMap = std::map<VertexDescriptor, std::vector<VertexDescriptor>>
Mapping of pattern to target vertices.
-
using GraphEdgeReplacementStruct = EdgeReplacementStruct<VertexProperties, DirectionProperty, EdgeProperties>
Alias for edge replacement structure.
Public Functions
-
ExtendedGraph() = default
Default constructor.
-
inline explicit ExtendedGraph(GraphType graph)
Constructor initializing the graph with a given Boost graph instance.
- Parameters:
graph – The Boost graph instance to initialize with.
-
virtual ~ExtendedGraph() = default
Virtual destructor.
-
inline GraphType &graph()
Accessor for the internal graph.
- Returns:
A reference to the internal graph instance.
-
inline const GraphType &graph() const
Const accessor for the internal graph.
- Returns:
A reference to the internal graph instance.
-
inline VertexDescriptor add_vertex(VertexProperties v = VertexProperties())
Adds a vertex to the graph.
- Parameters:
v – The properties of the vertex to add (default constructed if not provided).
- Returns:
The descriptor of the newly added vertex.
-
inline EdgeDescriptor add_edge(VertexDescriptor src, VertexDescriptor trg, EdgeProperties e = EdgeProperties())
Adds an edge between two vertices in the graph.
- Parameters:
src – The source vertex of the edge.
trg – The target vertex of the edge.
e – The properties of the edge to add (default constructed if not provided).
- Returns:
The descriptor of the newly added edge.
-
inline VertexDescriptor edge_source(EdgeDescriptor e) const
Retrieves the source vertex of a given edge.
- Parameters:
e – The edge descriptor.
- Returns:
The descriptor of the source vertex.
-
inline VertexDescriptor edge_target(EdgeDescriptor e) const
Retrieves the target vertex of a given edge.
- Parameters:
e – The edge descriptor.
- Returns:
The descriptor of the target vertex.
-
inline b::iterator_range<typename GraphType::vertex_iterator> vertex_range() const
Provides a range of all vertices in the graph.
- Returns:
An iterator range of all vertices in the graph.
-
inline b::iterator_range<typename GraphType::edge_iterator> edge_range() const
Provides a range of all edges in the graph.
- Returns:
An iterator range of all edges in the graph.
-
inline VertexProperties &operator[](const VertexDescriptor &v)
Accesses the properties of a vertex.
- Parameters:
v – The vertex descriptor.
- Returns:
A reference to the properties of the specified vertex.
-
inline const VertexProperties &operator[](const VertexDescriptor &v) const
Accesses the properties of a vertex (const).
- Parameters:
v – The vertex descriptor.
- Returns:
A reference to the properties of the specified vertex.
-
inline EdgeProperties &operator[](const EdgeDescriptor &e)
Accesses the properties of an edge.
- Parameters:
e – The edge descriptor.
- Returns:
A reference to the properties of the specified edge.
-
inline const EdgeProperties &operator[](const EdgeDescriptor &e) const
Accesses the properties of an edge (const).
- Parameters:
e – The edge descriptor.
- Returns:
A reference to the properties of the specified edge.
-
inline bool is_vertex_in_isomorphism(const VertexDescriptor &vertex, const IsoMap &isomorphism) const
Checks if a vertex exists in the isomorphism map.
- Parameters:
vertex – The vertex to check.
isomorphism – The isomorphism map containing vertices.
- Returns:
True if the vertex exists in the isomorphism map, false otherwise.
-
inline void print_dfs_graph() const
Performs a depth-first search (DFS) on the graph and prints events.
This function uses a custom DFS visitor to print initialization, start, discovery, and finish events for each vertex during the traversal.
-
inline void write_graph(const std::string &filename, bool render_pdf = true)
Writes the graph to a DOT file and optionally renders it as a PDF. This is not const as instances of this class keep an internal counter of the emitted graphs, and prefix it to the file name so that file names reflect the ordering of calls to this method.
- Parameters:
filename – The base filename (without extension) for the output files.
render_pdf – If true, renders the DOT file to a PDF.
-
inline VertexDescriptor duplicate_vertex(int id_to_duplicate, CloneVertexFunction<VertexProperties> cvf, ModifyVertexPairFunction<VertexProperties> mvpf)
Duplicates a vertex in the graph, along with its edges.
- Parameters:
id_to_duplicate – The ID of the vertex to duplicate.
cvf – A function to clone the properties of the vertex.
mvpf – A function to modify the pair of original and duplicated vertices.
- Returns:
The descriptor of the newly duplicated vertex.
-
inline void add_vertex_after_vertex(VertexDescriptor v, const VertexProperties &new_vertex_properties)
Adds a vertex after a specified vertex and adjusts edges accordingly.
- Parameters:
v – The vertex after which the new vertex will be added.
new_vertex_properties – The properties of the new vertex to add.
-
template<typename Predicate>
inline void add_vertex_after_pred(Predicate pred, const VertexProperties &new_vertex_properties) Adds a vertex after vertices that satisfy a given predicate.
- Template Parameters:
Predicate – A callable that takes vertex properties and returns true if the vertex matches the criteria.
- Parameters:
pred – The predicate function to filter vertices.
new_vertex_properties – The properties of the new vertex to add.
-
template<typename Predicate>
inline void remove_vertex_pred(Predicate pred) Removes all vertices that satisfy a predicate and reconnects edges.
For every matching vertex, in-edges are rewired to all out-vertices (excluding self-loops) before the vertex is cleared and erased. Vertex removal is processed in descending descriptor order to keep descriptors valid during mutation.
- Template Parameters:
Predicate – Callable that accepts vertex properties and returns true when the vertex should be removed.
- Parameters:
pred – Predicate applied to each vertex.
-
inline void add_vertex_before_vertex(VertexDescriptor v, const VertexProperties &new_vertex_properties)
Inserts a vertex immediately before an existing vertex.
Transfers all incoming edges of
vto the new vertex and adds a single edge from the new vertex intov, effectively splitting inbound traffic through the new vertex.- Parameters:
v – Vertex to insert in front of
new_vertex_properties – Properties to assign to the inserted vertex
-
template<typename Predicate>
inline void add_vertex_before_pred(Predicate pred, const VertexProperties &new_vertex_properties) Inserts a vertex before every vertex that satisfies a predicate.
Copies vertex properties via
clone()for each match to avoid sharing instances between insertions.- Template Parameters:
Predicate – Callable returning true when a vertex should be preceded.
- Parameters:
pred – Predicate applied to vertex properties.
new_vertex_properties – Prototype properties for the inserted vertex.
-
inline void merge_vertices(VertexDescriptor v1, VertexDescriptor v2, std::function<bool(VertexDescriptor, VertexDescriptor)> can_merge)
Merges two vertices in the graph if they satisfy a given condition.
This function attempts to merge two specified vertices (v1 and v2). The vertices are merged by redirecting all in-edges and out-edges of v2 to v1 and then removing v2 from the graph. The merge only occurs if the provided ‘canMerge’ predicate returns true for the two vertices.
- Parameters:
v1 – The first vertex to be merged.
v2 – The second vertex to be merged into the first.
can_merge – A predicate that takes two vertices and returns true if they can be merged.
-
inline std::set<VertexDescriptor, std::greater<>> replace_subgraph(const GraphType &ng, IsoMap &isomorphism, std::optional<std::function<void(std::vector<GraphEdgeReplacementStruct>, std::vector<GraphEdgeReplacementStruct>, std::vector<VertexDescriptor>, std::vector<VertexDescriptor>, GraphType&)>> reconnect_edges = std::nullopt)
Replace a matched subgraph with a new graph.
Adds all vertices/edges from
nginto the current graph, maps them to the vertices being replaced as described byisomorphism, and reconnects external edges either via a customreconnect_edgescallback or a default root/leaf strategy. Vertices slated for removal are returned so callers can clean them up after edge reconstruction.- Parameters:
ng – Constructed replacement graph
isomorphism – Mapping from replacement vertices to matched vertices
reconnect_edges – Optional hook to override external edge rewiring
- Returns:
Set of vertices that should be erased from the original graph
-
inline void fix_vertex_obj_ids()
Reassign IDs based on graph directionality.
Separate functions are required for directed and undirected graphs, since the concept of a root doesn’t exist in an undirected graph.
-
inline virtual void vertex_property_writer(std::ostream &out, const VertexDescriptor &v) const
Extension point for [write_graph]. Write the attributes of the vertex in dot format to the output stream.
-
inline virtual void edge_property_writer(std::ostream &out, const EdgeDescriptor&) const
Extension point for [write_graph]. Write the attributes of the edge in dot format to the output stream.
Protected Functions
Protected Attributes
-
Graph<VertexProperties_, DirectionProperty_, EdgeProperties_> graph_ = {}
Internal Boost graph instance.
-
template<typename VertexProperties, typename DirectionProperty, typename EdgeProperties = b::no_property>
class ExtendedSubGraph - #include <subgraph.h>
Extends graph functionality with subgraph operations.
This class provides support for creating and managing subgraphs within a larger graph structure. It includes functionality for:
Managing vertex and edge properties with GraphViz attributes
Creating and tracking hierarchical subgraph relationships
Maintaining consistent vertex object IDs across the graph hierarchy
Generating visual representations through GraphViz
- Template Parameters:
VertexProperties – The type of properties stored in vertices.
DirectionProperty – The directionality tag for the underlying graph.
EdgeProperties – The type of properties stored in edges (defaults to boost::no_property).
Public Types
-
using GraphType = b::subgraph<UnderlyingGraph>
Exposed subgraph type.
Public Functions
-
inline GraphType &graph()
Accesses the underlying graph instance.
- Returns:
Reference to the underlying graph.
-
inline const GraphType &graph() const
Accesses the underlying graph instance (const version).
- Returns:
Const reference to the underlying graph.
-
inline std::pair<VertexDescriptor, VertexDescriptor> add_vertex(VertexProperties v, GraphType &subgraph)
Creates a vertex in both global and subgraph contexts.
Creates a vertex with the specified properties in both the global graph and the provided subgraph. The vertex’s GraphViz attributes are initialized based on the vertex properties.
- Parameters:
v – Properties to assign to the new vertex
subgraph – The subgraph to add the vertex to
- Returns:
A pair containing the global and local vertex descriptors
-
inline VertexDescriptor add_vertex(VertexProperties v = VertexProperties())
Creates a vertex in the global graph.
- Parameters:
v – Properties to assign to the new vertex (default constructed if not provided)
- Returns:
The descriptor of the newly created vertex
-
inline std::pair<VertexDescriptor, VertexDescriptor> add_vertex(GraphType &subgraph)
Creates a vertex with default properties in both contexts.
Creates a vertex with default-constructed properties in both the global graph and specified subgraph.
- Parameters:
subgraph – The subgraph to add the vertex to
- Returns:
A pair containing the global and local vertex descriptors
-
inline std::pair<EdgeDescriptor, bool> add_edge(VertexDescriptor source, VertexDescriptor target, EdgeProperties e, GraphType &subgraph)
Creates an edge with properties in a specific graph context.
Adds an edge between specified vertices with associated properties. The edge is created in the specified graph context and its GraphViz attributes are initialized.
- Parameters:
source – Source vertex descriptor
target – Target vertex descriptor
e – Properties to assign to the new edge
subgraph – The graph or subgraph to add the edge to
- Returns:
A pair containing the edge descriptor and a boolean indicating success
-
inline std::pair<EdgeDescriptor, bool> add_edge(VertexDescriptor source, VertexDescriptor target, EdgeProperties e = EdgeProperties())
Creates an edge with properties in the global graph.
- Parameters:
source – Source vertex descriptor
target – Target vertex descriptor
e – Properties to assign to the new edge (default constructed if not provided)
- Returns:
A pair containing the edge descriptor and a boolean indicating success
-
inline std::pair<EdgeDescriptor, bool> add_edge(VertexDescriptor source, VertexDescriptor target, GraphType &subgraph)
Creates an edge with default properties in a specific graph context.
Creates an edge with default-constructed properties between specified vertices in the given graph context.
- Parameters:
source – Source vertex descriptor
target – Target vertex descriptor
subgraph – The graph or subgraph to add the edge to
- Returns:
A pair containing the edge descriptor and a boolean indicating success
-
inline GraphType &add_subgraph(GraphType &curr_graph, const std::string &name)
Creates a new subgraph within the current graph.
Creates and initializes a new subgraph with the given name, setting up appropriate GraphViz attributes for visualization.
- Parameters:
curr_graph – The parent graph to create the subgraph in.
name – The name to assign to the new subgraph.
- Returns:
Reference to the newly created subgraph.
-
inline GraphType &operator[](const std::string &name)
Accesses a subgraph by name.
Retrieves a reference to a previously created subgraph using its assigned name. Throws std::out_of_range if the subgraph doesn’t exist.
- Parameters:
name – The name of the subgraph to retrieve
- Throws:
std::out_of_range – if no subgraph exists with the given name
- Returns:
Reference to the requested subgraph
-
inline void update_graph_attributes()
Updates GraphViz attributes for all vertices.
Refreshes the GraphViz attributes for each vertex in the graph by calling their graphAttributes() method. This is useful after modifying vertex properties that affect visualization.
-
inline void fix_id_vertices()
Updates vertex object IDs to match their position in the graph.
Iterates through all vertices and sets their internal ID to match their vertex descriptor value, ensuring consistent identification across the graph.
- Pre:
The graph must not be empty and vertices must have an ‘id’ member.
Private Types
-
using GraphvizAttributes = std::map<std::string, std::string, std::less<>>
GraphViz attribute map type.
-
using ExtendedVertexProperties = b::property<b::vertex_attribute_t, GraphvizAttributes, VertexProperties>
Vertex property with attributes.
-
using ExtendedEdgeProperties = b::property<b::edge_index_t, int, b::property<b::edge_attribute_t, GraphvizAttributes, EdgeProperties>>
Edge property with attributes/index.
-
using UnderlyingGraph = b::adjacency_list<b::vecS, b::vecS, DirectionProperty, ExtendedVertexProperties, ExtendedEdgeProperties, b::property<b::graph_name_t, std::string, b::property<b::graph_graph_attribute_t, GraphvizAttributes, b::property<b::graph_vertex_attribute_t, GraphvizAttributes, b::property<b::graph_edge_attribute_t, GraphvizAttributes>>>>>
Type definition for the underlying graph structure.
Combines the extended property types with Boost’s adjacency list and adds graph-level attributes for GraphViz visualization.
Private Members
-
b::subgraph<UnderlyingGraph> graph_
The underlying Boost subgraph instance.
Underlying graph storage with subgraph support.
-
std::map<std::string, b::subgraph<UnderlyingGraph>*> subgraphs_
Maps subgraphs to their names.
Named subgraphs keyed by identifier.
-
template<typename T, typename U = b::no_property>
struct generic_edge_descriptor - #include <graph.h>
Descriptor for defining an edge in the graph.
- Template Parameters:
T – The type of the vertex identifier.
U – The type of the edge properties (default:
boost::no_property).
- #include <subgraph.h>
- #include <subgraph.h>
-
template<typename VertexProperties_, typename DirectionProperty_, typename EdgeProperties_ = boost::no_property>
class Isomorphism - #include <graph_isomorphisms.h>
Base class for implementing graph isomorphism operations.
This class provides the framework for defining and discovering graph isomorphisms, as well as applying transformations based on discovered isomorphisms. It can be extended to implement specific isomorphism patterns and transformations.
- Template Parameters:
VertexProperties – The type of vertex properties in the graph.
DirectionProperty – The directionality tag for the underlying graph (e.g., boost::bidirectionalS or boost::undirectedS).
EdgeProperties – The type of edge properties in the graph (defaults to boost::no_property).
Public Types
-
using GraphType = Graph<VertexProperties_, DirectionProperty_, EdgeProperties_>
Graph type alias.
-
using VertexProperties = VertexProperties_
Vertex property type.
-
using DirectionProperty = DirectionProperty_
Graph direction selector.
-
using EdgeProperties = EdgeProperties_
Edge property type.
-
using IsoMap = std::map<VertexDescriptor, std::vector<VertexDescriptor>>
Pattern-to-target vertex map.
-
using SpecializeIsoFunction = std::function<IsoMap(const GraphType &graph, const IsoMap &isomorphism)>
Function type for specializing discovered isomorphisms.
-
using VertexCompFunction = std::function<bool(const GraphType &G1, const GraphType &G2, const VertexDescriptor v1, const VertexDescriptor v2)>
Function type for comparing vertices during isomorphism detection.
-
using EdgeCompFunction = std::function<bool(const GraphType &G1, const GraphType &G2, const EdgeDescriptor e1, const EdgeDescriptor e2)>
Function type for comparing edges during isomorphism detection.
-
using IsIsomorphismValidFunction = std::function<bool(const GraphType &graph, const IsoMap &isomorphism)>
Function type for validating discovered isomorphisms.
-
using ConstructDesiredGraphFunction = std::function<GraphType(GraphType input_graph)>
Function type for constructing the desired graph after transformation.
-
using TemplatedEdgeReplacementStruct = EdgeReplacementStruct<VertexProperties, DirectionProperty, EdgeProperties>
Edge replacement helper type.
-
using ReconstructEdgesFunction = std::optional<std::function<void(std::vector<TemplatedEdgeReplacementStruct>, std::vector<TemplatedEdgeReplacementStruct>, std::vector<VertexDescriptor>, std::vector<VertexDescriptor>, GraphType&)>>
Reconnect hook type.
Public Functions
-
inline explicit Isomorphism(GraphType input_graph)
Constructs an Isomorphism instance with the given input graph.
- Parameters:
input_graph – The graph to search for isomorphisms in.
-
virtual ~Isomorphism() = default
-
inline void reset_input_graph()
Resets the working graph to the original input graph.
-
inline virtual VertexCompFunction vertex_comp_function()
Virtual function defining vertex comparison criteria.
- Returns:
Function object for comparing vertices.
-
inline virtual EdgeCompFunction edge_comp_function()
Virtual function defining edge comparison criteria.
- Returns:
Function object for comparing edges.
-
inline virtual bool is_isomorphism_valid(const GraphType &graph, const IsoMap &isomorphism)
Virtual function for validating discovered isomorphisms.
- Parameters:
graph – The graph containing the isomorphism.
isomorphism – The discovered isomorphism mapping.
- Returns:
true if the isomorphism is valid, false otherwise.
-
inline virtual IsoMap specialize_isomorphism(const GraphType &graph, const IsoMap &isomorphism)
Virtual function for specializing discovered isomorphisms.
This function can modify or extend the discovered isomorphism mapping before validation.
- Parameters:
graph – The graph containing the isomorphism.
isomorphism – The discovered isomorphism mapping.
- Returns:
The specialized isomorphism mapping.
-
inline virtual GraphType construct_desired_graph(const GraphType &input_graph, IsoMap &isomorphism)
Virtual function for constructing the transformed graph.
- Parameters:
input_graph – The original graph to transform.
isomorphism – The isomorphism mapping guiding the transformation.
- Returns:
The transformed graph.
-
inline virtual ReconstructEdgesFunction reconstruct_edges_function()
Virtual function providing edge reconstruction rules.
- Returns:
Optional function for reconstructing edges after transformation.
-
inline virtual InPlaceUpdateFunction inplace_update_function()
Virtual function providing in-place update rules.
- Returns:
Optional function for updating the graph in place.
-
inline virtual std::vector<IsoMap> discover(GraphType &sg, const GraphType &g, bool first, bool nonoverlapping = false, bool use_vf3 = true, IsIsomorphismValidFunction is_isomorphism_valid_ = nullptr, SpecializeIsoFunction specialize_isomorphism_ = nullptr)
Discovers isomorphisms in the graph matching the defined criteria.
This function uses Boost to find subgraph isomorphisms, then applies specialization and validation as defined by the derived class.
- Parameters:
sg – The subgraph pattern to search for.
g – The graph to search in.
first – If true, stop after finding the first valid isomorphism.
is_isomorphism_valid_ – Optional custom validation function.
specialize_isomorphism_ – Optional custom specialization function.
nonoverlapping – When true, skip mappings that reuse vertices from prior matches.
use_vf3 – Whether to use VF3 (true) or VF2 (false).
- Returns:
Vector of valid isomorphism mappings.
-
inline virtual GraphType apply_isomorphism_to_graph(const GraphType &g, IsoMap isomorphism)
Applies an isomorphism mapping to transform a graph.
Creates a new graph based on the isomorphism mapping, preserving the necessary vertices and edges while applying any transformations defined by the derived class.
- Parameters:
g – The graph to transform.
isomorphism – The isomorphism mapping to apply.
- Returns:
The transformed graph.
-
struct isomorphisms_callback
- #include <graph_isomorphisms.h>
Callback struct for collecting valid isomorphisms during search.
Public Functions
-
inline isomorphisms_callback(GraphType &sg, const GraphType &g, std::vector<IsoMap> &iso, bool first, IsIsomorphismValidFunction is_isomorphism_valid, SpecializeIsoFunction specialize_isomorphism, bool nonoverlapping)
-
template<typename CorrespondenceMap1To2, typename CorrespondenceMap2To1>
inline bool operator()(CorrespondenceMap1To2 cm1, CorrespondenceMap2To1) const Processes each discovered isomorphism mapping.
- Returns:
true to continue search, false to stop.
Public Members
-
GraphType &sg_
Pattern graph reference.
-
const GraphType &g_
Target graph reference.
-
bool discover_first_
Stop after first valid mapping.
-
IsIsomorphismValidFunction is_isomorphism_valid_
Custom validation function.
-
SpecializeIsoFunction specialize_isomorphism_
Custom specialization function.
-
bool nonoverlapping
Enforce non-overlapping results.
-
inline isomorphisms_callback(GraphType &sg, const GraphType &g, std::vector<IsoMap> &iso, bool first, IsIsomorphismValidFunction is_isomorphism_valid, SpecializeIsoFunction specialize_isomorphism, bool nonoverlapping)
-
struct pair_hash
- #include <graph.h>
Custom hash function for hashing pairs of objects.
Public Functions
-
template<class T1, class T2>
inline std::size_t operator()(const std::pair<T1, T2> &pair) const Compute the hash value for a pair.
- Template Parameters:
T1 – The type of the first element in the pair.
T2 – The type of the second element in the pair.
- Parameters:
pair – The pair to hash.
- Returns:
The computed hash value.
-
template<class T1, class T2>
-
class PrimitiveEdge : public boost::no_property
- #include <primitive_edge.h>
Base class for all edge property classes in the GHL.
PrimitiveEdge extends boost::no_property to provide:
Unique identification through ID management
Cloning capability for graph operations
Optional serialization support
This class is designed to be inherited from when creating custom edge property types. See the Road class in examples/city.h for an example of proper inheritance and extension.
Note
Unlike BaseNode, PrimitiveEdge inherits from boost::no_property to maintain compatibility with Boost Graph Library’s edge property system while adding GHL-specific functionality.
Public Functions
-
inline explicit PrimitiveEdge(int id = -1)
Constructs a PrimitiveEdge with the specified ID.
- Parameters:
id – The unique identifier for the edge. Defaults to -1 if not specified.
-
inline virtual std::shared_ptr<PrimitiveEdge> clone()
Creates a clone of the edge.
This virtual method enables polymorphic cloning of edges, which is essential for graph operations that require copying edges, such as subgraph extraction or graph transformation.
- Returns:
std::shared_ptr<PrimitiveEdge> A smart pointer to a new instance with the same properties.
-
virtual ~PrimitiveEdge() = default
Virtual destructor to ensure proper cleanup of derived classes.
-
inline int id() const
Gets the edge’s ID.
- Returns:
The unique identifier of the edge.
-
inline void id(int id)
Sets the edge’s ID.
- Parameters:
id – The new unique identifier for the edge.
-
inline virtual std::map<std::string, std::string, std::less<>> graphAttributes()
Generates GraphViz attributes for visualization.
This virtual method can be overridden by derived classes to customize the appearance of edges in GraphViz output. The base implementation results in no output.
- Returns:
A map of GraphViz attribute names to values.
Private Members
-
int id_
Unique identifier for the edge.
-
struct vertex_comp_helper
- #include <graph_isomorphisms.h>
Helper struct for vertex comparison during isomorphism detection.
-
template<typename T>
concept NodeLike - #include <base_node.h>
-
namespace boost
-
namespace cereal
Functions
-
template<class Archive, typename VertexProperties, typename DirectionProperty, typename EdgeProperties = b::no_property>
void save(Archive &ar, ghl::Graph<VertexProperties, DirectionProperty, EdgeProperties> const &graph) Serializes a GHL graph to an archive.
Saves the complete graph structure including vertices, edges, and their associated properties. The serialization process preserves the graph topology and all property data.
- Template Parameters:
Archive – The type of archive to serialize to
VertexProperties – The type of vertex properties in the graph
DirectionProperty – The directionality property (e.g., bidirectionalS or undirectedS)
EdgeProperties – The type of edge properties in the graph
- Parameters:
ar – The archive to save to
graph – The graph to serialize
-
template<class Archive, typename VertexProperties, typename DirectionProperty, typename EdgeProperties = b::no_property>
void load(Archive &ar, ghl::Graph<VertexProperties, DirectionProperty, EdgeProperties> &graph) Deserializes a GHL graph from an archive.
Reconstructs a complete graph structure from serialized data, including vertices, edges, and their associated properties. The deserialization process restores the original graph topology and all property data.
- Template Parameters:
Archive – The type of archive to deserialize from
VertexProperties – The type of vertex properties in the graph
DirectionProperty – The directionality property (e.g., bidirectionalS or undirectedS)
EdgeProperties – The type of edge properties in the graph
- Parameters:
ar – The archive to load from
graph – The graph to deserialize into
-
template<class Archive, typename VertexProperties, typename DirectionProperty, typename EdgeProperties = b::no_property>
-
namespace ghl
Typedefs
-
using DirectedEdgeDescImpl = b::detail::edge_desc_impl<b::bidirectional_tag, unsigned long>
-
using UndirectedEdgeDescImpl = b::detail::edge_desc_impl<b::undirected_tag, unsigned long>
-
typedef std::function<void(T, T)> ModifyVertexPairFunction
Function type for modifying a pair of vertices.
- Template Parameters:
T – The type of the vertices.
-
typedef std::function<T(T)> CloneVertexFunction
Function type for cloning a vertex.
- Template Parameters:
T – The type of the vertex.
-
typedef b::adjacency_list<b::vecS, b::vecS, DirectionProperty, VertexProperties, EdgeProperties, GraphProperties> Graph
An adjacency-list graph structure with customizable properties.
- Template Parameters:
VertexProperties – Properties associated with vertices. This is commonly a class that will be instantiated at each vertex.
DirectionProperty – Boost direction selector (e.g., bidirectionalS, undirectedS).
EdgeProperties – Properties associated with edges (default:
boost::no_property). This is commonly a class that will be instantiated at each edge.GraphProperties – Properties associated with the entire graph (default:
boost::no_property).
-
template<typename VertexProperties, typename EdgeProperties = b::no_property, typename GraphProperties = b::no_property>
using DirectedGraph = Graph<VertexProperties, b::bidirectionalS, EdgeProperties, GraphProperties> Graph specialization for directed graphs.
-
template<typename VertexProperties, typename EdgeProperties = b::no_property, typename GraphProperties = b::no_property>
using UndirectedGraph = Graph<VertexProperties, b::undirectedS, EdgeProperties, GraphProperties> Graph specialization for unddirected graphs.
-
template<typename VertexProperties, typename EdgeProperties = b::no_property>
using DirectedExtendedGraph = ExtendedGraph<VertexProperties, b::bidirectionalS, EdgeProperties>
-
template<typename VertexProperties, typename EdgeProperties = b::no_property>
using UndirectedExtendedGraph = ExtendedGraph<VertexProperties, b::undirectedS, EdgeProperties>
-
template<typename VertexProperties, typename EdgeProperties = b::no_property>
using DirectedExtendedSubGraph = ExtendedSubGraph<VertexProperties, b::bidirectionalS, EdgeProperties>
-
template<typename VertexProperties, typename EdgeProperties = b::no_property>
using UndirectedExtendedSubGraph = ExtendedSubGraph<VertexProperties, b::undirectedS, EdgeProperties>
-
template<typename VertexProperties, typename EdgeProperties = b::no_property>
using DirectedIsomorphism = Isomorphism<VertexProperties, b::bidirectionalS, EdgeProperties> Isomorphism specialization for directed graphs.
-
template<typename VertexProperties, typename EdgeProperties = b::no_property>
using UndirectedIsomorphism = Isomorphism<VertexProperties, b::undirectedS, EdgeProperties> Isomorphism specialization for undirected graphs.
Functions
-
template<typename GraphT>
void print_graph(const GraphT &graph) Prints the structure of a graph to standard output.
Outputs all vertices and edges in the graph for debugging and visualization purposes.
- Template Parameters:
GraphT – Boost graph type exposing vertex/edge iterators and descriptors.
- Parameters:
graph – The graph to print
-
template<typename GraphT>
void declare_graph_bindings(py::module_ &m, const std::string &pyclass_name) Declares Python bindings for a graph type.
Creates Python bindings for graph operations including vertex/edge manipulation, property access, and traversal methods.
- Template Parameters:
GraphT – Boost graph type to expose to Python.
- Parameters:
m – The pybind11 module to add bindings to
pyclass_name – Name of the Python class to create
-
template<typename ExtendedGraphT>
void declare_extended_graph_bindings(py::module_ &m, const std::string &pyclass_name) Declares Python bindings for an ExtendedGraph wrapper.
- Template Parameters:
ExtendedGraphT – The extended graph wrapper type.
- Parameters:
m – The pybind11 module to add bindings to.
pyclass_name – Name of the Python class to create.
-
template<typename Isomorphism>
void declare_isomorphism_bindings(py::module_ &m, const std::string &pyclass_name) Declares Python bindings for an isomorphism type.
Creates Python bindings for isomorphism initialization and discover function.
- Template Parameters:
Isomorphism – The isomorphism class to expose.
- Parameters:
m – The pybind11 module to add bindings to
pyclass_name – Name of the Python class to create
-
void base_node_bindings(const py::module_ &m)
Creates Python bindings for the BaseNode class.
- Parameters:
m – The pybind11 module to add bindings to
-
void primitive_edge_bindings(const py::module_ &m)
Creates Python bindings for the PrimitiveEdge class.
- Parameters:
m – The pybind11 module to add bindings to
-
void graph_bindings(py::module_ &m)
Creates Python bindings for core graph functionality.
Initializes bindings for base classes and common graph operations.
- Parameters:
m – The pybind11 module to add bindings to
-
void isomorphism_bindings(py::module_ &m)
Creates Python bindings for core isomorphism functionality.
Initializes bindings for base classes and common isomorphism operations.
- Parameters:
m – The pybind11 module to add bindings to
-
void register_base_types(py::module_ &m)
-
template<typename T, typename D, typename E = b::no_property>
Graph<T, D, E> construct_graph(std::vector<T> vertex_vector, std::vector<generic_edge_descriptor<int, E>> vertex_eds) Constructs a graph from a set of vertices and edges.
- Template Parameters:
T – The type of vertex properties.
D – Boost direction selector for the graph.
E – The type of edge properties (default:
boost::no_property).
- Parameters:
vertex_vector – A vector of vertices to be added to the graph.
vertex_eds – A vector of edge descriptors defining the edges between vertices.
- Returns:
A constructed graph of type
Graph<T, E>.
-
template<typename T, typename D, typename E = b::no_property>
std::pair<std::vector<T>, std::vector<generic_edge_descriptor<int, E>>> deconstruct_graph(Graph<T, D, E> g) Deconstructs a graph into its vertices and edge descriptors.
- Template Parameters:
T – The type of vertex properties.
D – Boost direction selector for the graph.
E – The type of edge properties (default:
boost::no_property).
- Parameters:
g – The graph to be deconstructed.
- Returns:
A pair containing a vector of vertices and a vector of edge descriptors.
-
inline void convert_dot_to_pdf(const std::string &dot_filename, const std::string &pdf_filename)
Converts a DOT file to a PDF using the Graphviz
dottool.- Parameters:
dot_filename – The path to the input DOT file.
pdf_filename – The path to the output PDF file.
-
template<typename V, typename G>
void update_edge_source(V source, V new_source, V target, G &g) Updates the source vertex of an edge in a graph.
- Template Parameters:
V – The type of the vertex descriptor.
G – The type of the graph.
- Parameters:
source – The current source vertex of the edge.
new_source – The new source vertex for the edge.
target – The target vertex of the edge.
g – The graph where the edge resides.
-
template<typename V, typename G>
void update_edge_target(V source, V target, V new_target, G &g) Updates the target vertex of an edge in a graph.
- Template Parameters:
V – The type of the vertex descriptor.
G – The type of the graph.
- Parameters:
source – The source vertex of the edge.
target – The current target vertex of the edge.
new_target – The new target vertex for the edge.
g – The graph where the edge resides.
Applies a vector of isomorphism transformations to a graph.
This function implements the process of applying a graph isomorphism, which can modify both the structure and properties of the graph. It supports both in-place updates and constructive transformations where a new subgraph replaces part of the original graph.
The function operates iteratively, implementing the passed vector of previously found isomorphisms. This enables comprehensive graph transformations that may require multiple passes.
- Template Parameters:
ExtendedGraphT – Extended graph wrapper type that owns the Boost graph.
- Parameters:
graph – The graph to transform
isomorphism – The isomorphism object defining the transformation rules
isomorphisms – The vector or view on the vector of previously found isomorphisms
Discover and apply isomorphisms to a graph.
Repeatedly discovers subgraph matches in the target graph and applies the provided isomorphism rules until no further matches are found. When
nonoverlappingis true, all disjoint matches are collected and applied in a single pass; when false, only the first match is applied each iteration, allowing overlapping matches across iterations. All discovered IsoMaps are returned.- Template Parameters:
ExtendedGraphT – The wrapped graph type to mutate.
- Parameters:
graph – The graph to transform.
isomorphism – The isomorphism object defining the transformation rules.
nonoverlapping – When true, collect and apply all non-overlapping matches at once.
use_vf3 – If true, use the VF3 algorithm; otherwise use VF2.
- Returns:
A vector of all IsoMaps discovered during the run.
-
using DirectedEdgeDescImpl = b::detail::edge_desc_impl<b::bidirectional_tag, unsigned long>
-
namespace pybind11
Functions
-
template<class Archive>
void save(Archive &ar, const object &obj) Serializes a Python object to an archive.
Converts the Python object to a serialized string using pickle and base64 encoding to ensure safe storage of binary data.
- Template Parameters:
Archive – The type of archive to serialize to
- Parameters:
ar – The archive instance
obj – The Python object to serialize
-
template<class Archive>
void load(Archive &ar, object &obj) Deserializes a Python object from an archive.
Reconstructs a Python object from its serialized string representation using base64 decoding and pickle.
- Template Parameters:
Archive – The type of archive to deserialize from
- Parameters:
ar – The archive instance
obj – The Python object to deserialize into
-
template<class Archive>
void save(Archive &ar, const pybind11::kwargs &kwargs) Serializes Python keyword arguments to an archive.
Converts Python kwargs into a serializable map structure.
- Template Parameters:
Archive – The type of archive to serialize to
- Parameters:
ar – The archive instance
kwargs – The Python keyword arguments to serialize
-
template<class Archive>
void load(Archive &ar, pybind11::kwargs &kwargs) Deserializes Python keyword arguments from an archive.
Reconstructs Python kwargs from a serialized map structure.
- Template Parameters:
Archive – The type of archive to deserialize from
- Parameters:
ar – The archive instance
kwargs – The Python keyword arguments to deserialize into
- template void save< cereal::JSONOutputArchive > (cereal::JSONOutputArchive &, const object &)
- template void save< cereal::BinaryOutputArchive > (cereal::BinaryOutputArchive &, const object &)
- template void save< cereal::PortableBinaryOutputArchive > (cereal::PortableBinaryOutputArchive &, const object &)
- template void load< cereal::JSONInputArchive > (cereal::JSONInputArchive &, object &)
- template void load< cereal::BinaryInputArchive > (cereal::BinaryInputArchive &, object &)
- template void load< cereal::PortableBinaryInputArchive > (cereal::PortableBinaryInputArchive &, object &)
- template void save< cereal::JSONOutputArchive > (cereal::JSONOutputArchive &, const pybind11::kwargs &)
- template void save< cereal::BinaryOutputArchive > (cereal::BinaryOutputArchive &, const pybind11::kwargs &)
- template void save< cereal::PortableBinaryOutputArchive > (cereal::PortableBinaryOutputArchive &, const pybind11::kwargs &)
- template void load< cereal::JSONInputArchive > (cereal::JSONInputArchive &, pybind11::kwargs &)
- template void load< cereal::BinaryInputArchive > (cereal::BinaryInputArchive &, pybind11::kwargs &)
- template void load< cereal::PortableBinaryInputArchive > (cereal::PortableBinaryInputArchive &, pybind11::kwargs &)
-
template<class Archive>
-
namespace std
- file graph_bindings.cpp
- #include “graph_bindings.h”
- file graph_bindings.h
- #include “../graph/graph.h”#include “../isomorphism/apply_isomorphism.h”#include “../isomorphism/graph_isomorphisms.h”#include <pybind11/functional.h>#include <pybind11/pybind11.h>#include <pybind11/stl.h>
Provides Python bindings for the Generic Graph Library core functionality.
This file implements pybind11-based Python bindings for GHL’s core graph types and operations. It enables seamless integration between C++ and Python by exposing graph manipulation functions, property access, and traversal methods.
Dependencies:
pybind11 (when GHL_BINDINGS is defined)
Boost Graph Library
Functions
- file cereal.h
- #include <fstream>#include <cereal/access.hpp>#include <cereal/archives/binary.hpp>#include <cereal/archives/json.hpp>#include <cereal/archives/portable_binary.hpp>#include <cereal/types/array.hpp>#include <cereal/types/complex.hpp>#include <cereal/types/map.hpp>#include <cereal/types/memory.hpp>#include <cereal/types/string.hpp>#include <cereal/types/tuple.hpp>#include <cereal/types/unordered_map.hpp>#include <cereal/types/utility.hpp>#include <cereal/types/vector.hpp>
Provides serialization utilities and macros for the GHL.
This file sets up the serialization infrastructure for the Generic Graph Library using the cereal serialization library. It defines a set of macros that simplify the process of implementing serialization for different types of graph components, including:
Base class serialization
Derived class serialization with polymorphic support
Automatic registration of types with cereal
The macros defined here are used throughout the GHL to provide consistent serialization behavior across all serializable components.
Defines
-
REGISTER_SERIALIZATION(cls)
Registers serialization functions for a class with different archive types.
This macro generates the necessary template specializations for serializing a class with JSON, Binary, and PortableBinary archives in both input and output modes.
- Parameters:
cls – The class to register for serialization
-
REGISTER_TYPE_AND_POLYMORPHISM(base, cls)
Registers polymorphic type information for a class and its base.
This macro registers a class for polymorphic serialization and establishes its relationship with a base class in the serialization system.
- Parameters:
base – The base class in the polymorphic relationship
cls – The derived class to register
-
SERIALIZE_CHILD_NO_ARGS(cls, base)
Implements serialization for a child class without additional members.
This macro defines serialization for a derived class that only needs to serialize its base class members.
- Parameters:
cls – The derived class implementing serialization
base – The base class whose serialization should be included
-
SERIALIZE_CHILD(cls, base, ...)
Implements serialization for a child class with additional members.
This macro defines serialization for a derived class that needs to serialize both its base class members and its own members.
- Parameters:
cls – The derived class implementing serialization
base – The base class whose serialization should be included
... – Additional members to serialize
-
SERIALIZE_BASE(base, ...)
Implements serialization for a base class.
This macro defines serialization for a base class, including all specified members in the serialization process.
- Parameters:
base – The base class implementing serialization
... – Members to serialize
- file forward_decl.h
Forward declarations for cereal serialization library components.
This header provides minimal forward declarations needed for cereal integration, along with macros to handle dynamic initialization of polymorphic support. It helps prevent linker optimization issues that can occur with static polymorphic registration objects.
Defines
-
CEREAL_FWD_DLL_EXPORT
Platform-specific DLL export macro for MSVC compilers.
Defines export behavior differently for MSVC versus other compilers to ensure proper symbol visibility.
-
CEREAL_FWD_USED
-
CEREAL_FWD_FORCE_DYNAMIC_INIT(LibName)
Forces dynamic initialization of polymorphic support in a previously registered source file
See CEREAL_REGISTER_DYNAMIC_INIT for detailed explanation of how this macro should be used. The name used should match that for CEREAL_REGISTER_DYNAMIC_INIT.
See also
CEREAL_REGISTER_DYNAMIC_INIT
-
CEREAL_FWD_DLL_EXPORT
- file pybind11.cpp
- #include “pybind11.h”#include “cereal.h”#include <pybind11/embed.h>
- file pybind11.h
- file ghl.h
- #include “graph/graph.h”
- file ghl_isomorphisms.h
- #include “isomorphism/apply_isomorphism.h”#include “isomorphism/graph_isomorphisms.h”
- file ghl_subgraphs.h
- #include “graph/subgraph.h”
- file base_node.h
- #include <format>#include <map>#include <memory>#include “pybind11_fwd_decl.h”
Defines the base class for vertex properties in the Generic Graph Library.
This file contains the BaseNode class which serves as the foundation for all vertex property classes in the GHL. It provides basic functionality such as unique identification and GraphViz attribute generation that can be extended by derived classes.
The BaseNode class is designed to work seamlessly with the Boost Graph Library while providing additional functionality specific to GHL’s needs. It supports optional serialization capabilities when the GHL_SERIALIZATION flag is defined.
- file graph.h
- #include “base_node.h”#include “primitive_edge.h”#include <boost/graph/adjacency_list.hpp>#include <boost/graph/copy.hpp>#include <boost/graph/depth_first_search.hpp>#include <boost/graph/graph_traits.hpp>#include <boost/graph/graph_utility.hpp>#include <boost/graph/graphviz.hpp>#include <boost/graph/subgraph.hpp>#include <boost/graph/vf2_sub_graph_iso.hpp>#include <boost/graph/vf3_sub_graph_iso.hpp>#include <climits>#include <filesystem>#include <map>#include <ranges>#include <set>#include <type_traits>#include <typeinfo>#include <unordered_set>
Header file defining the primary graph data structures and utilities for the Generic Graph Library (GHL).
This file contains core definitions and implementations for managing and manipulating graphs. It utilizes the Boost Graph Library for foundational graph structures and supports extended operations such as vertex duplication, edge updates, and subgraph replacement.
Dependencies:
Boost Graph Library (>= 1.86.0)
- file primitive_edge.h
- #include <boost/graph/adjacency_list.hpp>#include <memory>
Defines the base class for edge properties in the Generic Graph Library.
This file contains the PrimitiveEdge class which serves as the foundation for all edge property classes in the GHL. It extends boost::no_property to maintain compatibility with the Boost Graph Library while adding unique identification capabilities for GHL’s extended functionality.
The PrimitiveEdge class parallels BaseNode in providing core property management for graph elements, but specifically for edges rather than vertices. It supports optional serialization when the GHL_SERIALIZATION flag is defined.
- file pybind11_fwd_decl.h
Defines
-
PYBIND11_EXPORT
-
PYBIND11_EXPORT
- file subgraph.h
- #include “graph.h”#include <format>#include <stdexcept>#include <type_traits>
Provides subgraph functionality for the Generic Graph Library.
This file defines the ExtendedSubGraph class which extends GHL’s graph functionality to support subgraph operations. It builds upon Boost’s subgraph capabilities while adding GHL-specific features such as vertex object ID management and GraphViz attribute handling.
The implementation uses Boost’s property system to maintain visualization attributes and supports hierarchical graph structures through subgraph relationships.
- file apply_isomorphism.h
- #include “graph_isomorphisms.h”
Implements functionality for applying graph isomorphisms in the GHL.
This file defines the core mechanism for applying discovered isomorphisms to transform graphs. It provides a templated function that handles the process of applying structural and property modifications based on isomorphism mappings, including:
Applying vertex and edge transformations
Managing external edge reconnection
Maintaining property consistency
Supporting both in-place and constructive updates
The implementation works in conjunction with the Isomorphism class to enable complete graph transformation workflows.
- file graph_isomorphisms.h
- #include “../graph/graph.h”#include <unordered_set>
Provides graph isomorphism detection and transformation capabilities.
This file defines the core isomorphism framework for GHL, enabling detection of structurally equivalent subgraphs and graph transformations. It builds upon Boost’s VF2 subgraph isomorphism algorithm while adding GHL-specific functionality for property-based matching and graph transformations.
The implementation supports:
Custom vertex and edge matching criteria
Isomorphism validation and specialization
Graph transformation based on discovered isomorphisms
In-place and constructive graph updates
- file graph_serialization.h
- #include “../cereal/cereal.h”#include “../graph/graph.h”
Provides serialization support for graph structures in the GHL.
This file implements serialization and deserialization functionality for GHL graph structures using the cereal library. It enables graphs to be saved to and loaded from various formats including JSON and binary. The implementation handles both vertex and edge properties, maintaining the complete graph structure during serialization.
Dependencies:
cereal (>= 1.3.0)
- dir /home/runner/work/graph-hook-library/graph-hook-library/include/ghl/bindings
- dir /home/runner/work/graph-hook-library/graph-hook-library/include/ghl/cereal
- dir /home/runner/work/graph-hook-library/graph-hook-library/include/ghl
- dir /home/runner/work/graph-hook-library/graph-hook-library/include/ghl/graph
- dir /home/runner/work/graph-hook-library/graph-hook-library/include
- dir /home/runner/work/graph-hook-library/graph-hook-library/include/ghl/isomorphism
- dir /home/runner/work/graph-hook-library/graph-hook-library/include/ghl/serialization