diff --git a/include/CXXGraph/CXXGraphConfig.h b/include/CXXGraph/CXXGraphConfig.h index 44cfc71de..f6ff9ff4e 100644 --- a/include/CXXGraph/CXXGraphConfig.h +++ b/include/CXXGraph/CXXGraphConfig.h @@ -1,4 +1,4 @@ -// the configured options and settings for CXXGraph -#define CXXGraph_VERSION_MAJOR 4 -#define CXXGraph_VERSION_MINOR 1 -#define CXXGraph_VERSION_PATCH 0 +// the configured options and settings for CXXGraph +#define CXXGraph_VERSION_MAJOR 4 +#define CXXGraph_VERSION_MINOR 1 +#define CXXGraph_VERSION_PATCH 0 diff --git a/include/CXXGraph/Graph/Graph_decl.h b/include/CXXGraph/Graph/Graph_decl.h index e6d7983c7..03d0f7e9b 100644 --- a/include/CXXGraph/Graph/Graph_decl.h +++ b/include/CXXGraph/Graph/Graph_decl.h @@ -261,6 +261,20 @@ class Graph { */ virtual void removeNode(const std::string &nodeUserId); + /** + * \brief + * Invalidates and rebuilds the graph's core caches. + * This includes the adjacency matrix, degree matrix, and Laplacian matrix. + * Optionally, the transition matrix can also be rebuilt. + * + * \param includeTransitionMatrix + * If true, the transition matrix will be rebuilt as part of the cache update. + * + * \note Not thread-safe. + * \note Call after any structural modification of the graph. + */ + void invalidateCache(bool includeTransitionMatrix); + /** * \brief * Finds the given edge defined by v1 and v2 within the graph. @@ -562,10 +576,9 @@ class Graph { virtual std::shared_ptr>> eulerianPath() const; /** - * @brief Function runs the dijkstra algorithm with inverted metric for some source node and - * target node in the graph and returns the longest distance of target - * from the source (called critical path). - * Note: No Thread Safe + * @brief Function runs the dijkstra algorithm with inverted metric for some + * source node and target node in the graph and returns the longest distance + * of target from the source (called critical path). Note: No Thread Safe * * @param source source vertex * @param target target vertex @@ -574,9 +587,8 @@ class Graph { * case if target is not reachable from source or there is error in the * computation. */ - virtual const DijkstraResult criticalpath_deterministic(const Node& source, - const Node& target) const; - + virtual const DijkstraResult criticalpath_deterministic( + const Node &source, const Node &target) const; /** * @brief Function runs the dijkstra algorithm for some source node and diff --git a/include/CXXGraph/Graph/Graph_impl.hpp b/include/CXXGraph/Graph/Graph_impl.hpp index 950cd8daf..bbdb9426e 100644 --- a/include/CXXGraph/Graph/Graph_impl.hpp +++ b/include/CXXGraph/Graph/Graph_impl.hpp @@ -36,10 +36,7 @@ using std::make_unique; template Graph::Graph() { /* Caching the adjacency matrix */ - cacheAdjMatrix(); - cacheDegreeMatrix(); - cacheLaplacianMatrix(); - cacheTransitionMatrix(); + invalidateCache(true); } template @@ -48,10 +45,7 @@ Graph::Graph(const T_EdgeSet &edgeSet) { this->edgeSet.insert(edgeIt); } /* Caching the adjacency matrix */ - cacheAdjMatrix(); - cacheDegreeMatrix(); - cacheLaplacianMatrix(); - cacheTransitionMatrix(); + invalidateCache(true); } template @@ -72,9 +66,7 @@ void Graph::setEdgeSet(const T_EdgeSet &edgeSet) { this->edgeSet.insert(edgeIt); } /* Caching the adjacency matrix */ - cacheAdjMatrix(); - cacheDegreeMatrix(); - cacheLaplacianMatrix(); + invalidateCache(false); } template @@ -610,6 +602,17 @@ void Graph::cacheLaplacianMatrix() { this->cachedLaplacianMatrix = laplacianMatrix; } +template +void Graph::invalidateCache(bool includeTransitionMatrix) { + cacheAdjMatrix(); + cacheDegreeMatrix(); + cacheLaplacianMatrix(); + + if (includeTransitionMatrix) { + cacheTransitionMatrix(); + } +} + template shared> Graph::getTransitionMatrix() const { const auto adjacencyMatrix = this->cachedAdjMatrix;