27 #ifndef SRC_ENV_NODE_MAP_IPP_ 28 #define SRC_ENV_NODE_MAP_IPP_ 33 NodeMap(std::size_t num_nodes_g, std::size_t num_nodes_h) :
34 forward_map_(num_nodes_g,
GEDGraph::undefined_node()),
35 backward_map_(num_nodes_h,
GEDGraph::undefined_node()),
36 induced_cost_{std::numeric_limits<double>::infinity()} {}
40 forward_map_(node_map.forward_map_),
41 backward_map_(node_map.backward_map_),
42 induced_cost_(node_map.induced_cost_) {}
47 forward_map_ = node_map.forward_map_;
48 backward_map_ = node_map.backward_map_;
49 induced_cost_ = node_map.induced_cost_;
55 for (
auto & node_id : forward_map_) {
58 for (
auto & node_id : backward_map_) {
66 for (
const auto & node_id : forward_map_) {
71 for (
const auto & node_id : backward_map_) {
82 return forward_map_.size();
88 return backward_map_.size();
94 for (
const auto & node_id : forward_map_) {
99 for (
const auto & node_id : backward_map_) {
111 if (node < forward_map_.size()) {
112 return forward_map_.at(node);
115 throw Error(
"The node with ID " + std::to_string(node) +
" is not contained in the source nodes of the node map.");
123 if (node < forward_map_.size()) {
126 if (
image < backward_map_.size()) {
131 throw Error(
"The node with ID " + std::to_string(node) +
" is not contained in the source nodes of the node map.");
138 if (node < backward_map_.size()) {
139 return backward_map_.at(node);
142 throw Error(
"The node with ID " + std::to_string(node) +
" is not contained in the target nodes of the node map.");
150 if (node < backward_map_.size()) {
158 throw Error(
"The node with ID " + std::to_string(node) +
" is not contained in the target nodes of the node map.");
167 for (i = 0; i < forward_map_.size(); i++) {
168 k = forward_map_.at(i);
170 relation.emplace_back(i, k);
173 for (k = 0; k < backward_map_.size(); k++) {
174 i = backward_map_.at(k);
176 relation.emplace_back(i, k);
185 if (i < forward_map_.size()) {
189 throw Error(
"The node with ID " + std::to_string(i) +
" is not contained in the source nodes of the node map.");
193 if (k < backward_map_.size()) {
194 backward_map_[k] = i;
197 throw Error(
"The node with ID " + std::to_string(k) +
" is not contained in the target nodes of the node map.");
211 return induced_cost_;
217 return (induced_cost_ < rhs.induced_cost_);
223 return ((forward_map_ == node_map.forward_map_) and (backward_map_ == node_map.backward_map_));
227 std::vector<NodeMap::Assignment> relation;
230 for (
const auto & assignment : relation) {
231 os << assignment <<
" ";
237 std::ostream &
operator<<(std::ostream & os,
const NodeMap::Assignment & assignment) {
243 os << assignment.first <<
",";
249 os << assignment.second <<
"";
void erase_image(GEDGraph::NodeID node)
Erases image of a node.
void as_relation(std::vector< Assignment > &relation) const
Constructs the representation as relation.
bool empty() const
Checks if the node map is empty.
std::size_t num_source_nodes() const
Returns number of source nodes contained in the node map.
GEDGraph::NodeID pre_image(GEDGraph::NodeID node) const
Returns pre-image of a node.
double induced_cost() const
Returns the induced cost.
std::ostream & operator<<(std::ostream &os, const NodeMap &node_map)
Streams a node map.
bool complete(const GEDGraph &g, const GEDGraph &h) const
Checks if the node map is complete.
static NodeID dummy_node()
Returns a dummy node.
static NodeID undefined_node()
Returns an undefined node.
NodeMap(std::size_t num_nodes_g, std::size_t num_nodes_h)
Default constructor.
The normalized input graphs used by GEDLIB. All labels are integers.
void add_assignment(GEDGraph::NodeID i, GEDGraph::NodeID k)
Add node substitution, insertion, or deletion to the node map.
void set_induced_cost(double induced_cost)
Sets the induced cost of the node map.
std::size_t num_target_nodes() const
Returns number of target nodes contained in the node map.
Global namespace for GEDLIB.
void clear()
Clears the node map.
void erase_pre_image(GEDGraph::NodeID node)
Erases pre-image of a node.
bool operator==(const NodeMap &node_map) const
Checks if two node maps are the same.
GEDGraph::NodeID image(GEDGraph::NodeID node) const
Returns image of a node.
bool operator<(const NodeMap &node_map) const
Compares this node map to another node map.
void operator=(const NodeMap &node_map)
Assignment operator.
std::size_t NodeID
Internally used vertex ID type.