diff --git a/alib2data/src/graph/directed/DirectedGraph.cpp b/alib2data/src/graph/directed/DirectedGraph.cpp index 12ae66f3bab32d633c386a9e9ab71bbbe3a794bf..7822b83c71390c3f48e17f7bbc9fe8add5eeaa91 100644 --- a/alib2data/src/graph/directed/DirectedGraph.cpp +++ b/alib2data/src/graph/directed/DirectedGraph.cpp @@ -38,6 +38,7 @@ DirectedGraph::DirectedGraph(const DirectedGraph &other) : representation(other.representation) , nodeValues(other.nodeValues) , edgeValues(other.edgeValues) + , embedding(other.embedding) { init(); impl->copy(other.impl); @@ -48,6 +49,7 @@ DirectedGraph::DirectedGraph(DirectedGraph &&other) noexcept , impl(other.impl) , nodeValues(std::move(other.nodeValues)) , edgeValues(std::move(other.edgeValues)) + , embedding(std::move(other.embedding)) { other.impl = 0; } @@ -68,6 +70,7 @@ DirectedGraph &DirectedGraph::operator=(DirectedGraph &&other) noexcept std::swap(this->impl, other.impl); std::swap(this->nodeValues, other.nodeValues); std::swap(this->edgeValues, other.edgeValues); + std::swap(this->embedding, other.embedding); return *this; } @@ -192,6 +195,16 @@ void DirectedGraph::setEdgeValue(const DirectedEdge &edge, int value) edgeValues.insert({edge, value}); } +std::unordered_map < Node, std::vector < Node > > DirectedGraph::getEmbedding ( ) const +{ + return embedding; +} + +void DirectedGraph::setEmbedding ( const std::unordered_map < Node, std::vector< Node > > embedding ) +{ + this->embedding = embedding; +} + void DirectedGraph::operator>>(std::ostream &out) const { out << "(DirectedGraph " << static_cast<std::string>(*impl) << ")"; @@ -203,8 +216,8 @@ int DirectedGraph::compare(const DirectedGraph &other) const return static_cast<int>(representation) - static_cast<int>(other.representation); } - auto first = std::tie(nodeValues, edgeValues); - auto second = std::tie(other.nodeValues, other.edgeValues); + auto first = std::tie(nodeValues, edgeValues, embedding); + auto second = std::tie(other.nodeValues, other.edgeValues, other.embedding); std::compare<decltype(first)> comp; int res = comp(first, second); diff --git a/alib2data/src/graph/directed/DirectedGraph.h b/alib2data/src/graph/directed/DirectedGraph.h index c828f99ac0546267ea0ea01c4008ae11bcc83a3a..7f1a4efe80851db2d95810e2dc8b4a4e5fc8b16b 100644 --- a/alib2data/src/graph/directed/DirectedGraph.h +++ b/alib2data/src/graph/directed/DirectedGraph.h @@ -9,6 +9,7 @@ #define DIRECTED_GRAPH_H_ #include <unordered_map> +#include <vector> #include <set> #include "../GraphBase.h" @@ -62,6 +63,9 @@ public: int getEdgeValue ( const DirectedEdge & edge ) const; void setEdgeValue ( const DirectedEdge & edge, int value ); + std::unordered_map < Node, std::vector < Node > > getEmbedding ( ) const; + void setEmbedding ( const std::unordered_map < Node, std::vector< Node > > embedding ); + int compare ( const ObjectBase & other ) const override { if ( std::type_index ( typeid ( * this ) ) == std::type_index ( typeid ( other ) ) ) return this->compare ( ( decltype ( * this ) )other ); @@ -88,6 +92,7 @@ private: std::unordered_map < Node, int > nodeValues; std::unordered_map < DirectedEdge, int > edgeValues; + std::unordered_map < Node, std::vector < Node > > embedding; friend class GraphToXMLComposer; friend class GraphToStringComposer; diff --git a/alib2data/src/graph/undirected/UndirectedGraph.cpp b/alib2data/src/graph/undirected/UndirectedGraph.cpp index 3a0ebc79bbcaa88e3e64feb599a4fa8bb9dad5e6..c2f773c37e366fc58f48b53670358e246e2a05d3 100644 --- a/alib2data/src/graph/undirected/UndirectedGraph.cpp +++ b/alib2data/src/graph/undirected/UndirectedGraph.cpp @@ -38,6 +38,7 @@ UndirectedGraph::UndirectedGraph(const UndirectedGraph &other) : representation(other.representation) , nodeValues(other.nodeValues) , edgeValues(other.edgeValues) + , embedding(other.embedding) { init(); impl->copy(other.impl); @@ -48,6 +49,7 @@ UndirectedGraph::UndirectedGraph(UndirectedGraph &&other) noexcept , impl(other.impl) , nodeValues(std::move(other.nodeValues)) , edgeValues(std::move(other.edgeValues)) + , embedding(std::move(other.embedding)) { other.impl = 0; } @@ -68,6 +70,7 @@ UndirectedGraph &UndirectedGraph::operator=(UndirectedGraph &&other) noexcept std::swap(this->impl, other.impl); std::swap(this->nodeValues, other.nodeValues); std::swap(this->edgeValues, other.edgeValues); + std::swap(this->embedding, other.embedding); return *this; } @@ -192,6 +195,16 @@ void UndirectedGraph::setEdgeValue(const UndirectedEdge &edge, int value) edgeValues.insert({edge, value}); } +std::unordered_map < Node, std::vector < Node > > UndirectedGraph::getEmbedding ( ) const +{ + return embedding; +} + +void UndirectedGraph::setEmbedding ( const std::unordered_map < Node, std::vector< Node > > embedding ) +{ + this->embedding = embedding; +} + void UndirectedGraph::operator>>(std::ostream &out) const { out << "(UndirectedGraph " << static_cast<std::string>(*impl) << ")"; @@ -203,8 +216,8 @@ int UndirectedGraph::compare(const UndirectedGraph &other) const return static_cast<int>(representation) - static_cast<int>(other.representation); } - auto first = std::tie(nodeValues, edgeValues); - auto second = std::tie(other.nodeValues, other.edgeValues); + auto first = std::tie(nodeValues, edgeValues, embedding); + auto second = std::tie(other.nodeValues, other.edgeValues, other.embedding); std::compare<decltype(first)> comp; int res = comp(first, second); diff --git a/alib2data/src/graph/undirected/UndirectedGraph.h b/alib2data/src/graph/undirected/UndirectedGraph.h index 422b8fdd34c301998393d78bd599b5a2a4b94c6f..5a3d688ba3cf308f10dbb1b7ddb62d0067d7c30b 100644 --- a/alib2data/src/graph/undirected/UndirectedGraph.h +++ b/alib2data/src/graph/undirected/UndirectedGraph.h @@ -9,6 +9,7 @@ #define UNDIRECTED_GRAPH_H_ #include <unordered_map> +#include <vector> #include <set> #include "../GraphBase.h" @@ -62,6 +63,9 @@ public: int getEdgeValue ( const UndirectedEdge & edge ) const; void setEdgeValue ( const UndirectedEdge & edge, int value ); + std::unordered_map < Node, std::vector < Node > > getEmbedding ( ) const; + void setEmbedding ( const std::unordered_map < Node, std::vector< Node > > embedding ); + int compare ( const ObjectBase & other ) const override { if ( std::type_index ( typeid ( * this ) ) == std::type_index ( typeid ( other ) ) ) return this->compare ( ( decltype ( * this ) )other ); @@ -88,6 +92,7 @@ private: std::unordered_map < Node, int > nodeValues; std::unordered_map < UndirectedEdge, int > edgeValues; + std::unordered_map < Node, std::vector < Node > > embedding; friend class GraphToXMLComposer; friend class GraphToStringComposer;