GEDLIB  1.0
anchor_aware_ged.hpp
Go to the documentation of this file.
1 /***************************************************************************
2 * *
3 * Copyright (C) 2018 by David B. Blumenthal *
4 * *
5 * This file is part of GEDLIB. *
6 * *
7 * GEDLIB is free software: you can redistribute it and/or modify it *
8 * under the terms of the GNU Lesser General Public License as published *
9 * by the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * GEDLIB is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU Lesser General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with GEDLIB. If not, see <http://www.gnu.org/licenses/>. *
19 * *
20 ***************************************************************************/
21 
27 #ifndef SRC_METHODS_ANCHOR_AWARE_GED_HPP_
28 #define SRC_METHODS_ANCHOR_AWARE_GED_HPP_
29 
30 namespace ged {
31 
49 template<class UserNodeLabel, class UserEdgeLabel>
50 class AnchorAwareGED : public GEDMethod<UserNodeLabel, UserEdgeLabel> {
51 
52 public:
53 
54  virtual ~AnchorAwareGED();
55 
57 
58 private:
59 
60  enum SearchMethod_ {DFS, ASTAR};
61 
62  enum LowerBoundMethod_ {BRANCH, BRANCH_FAST};
63 
64  struct Edge_ {
65  Edge_(LabelID label, GEDGraph::EdgeID edge_id);
66 
67  LabelID label;
68 
69  GEDGraph::EdgeID edge_id;
70 
71  bool operator<(const Edge_ & rhs) const;
72  };
73 
74  class SortedEdges_ {
75  public:
76  SortedEdges_();
77 
78  SortedEdges_(const GEDGraph & g);
79 
80  void operator=(const SortedEdges_ & rhs);
81 
82  const std::vector<Edge_> & get_incident_edges(GEDGraph::NodeID) const;
83  private:
84  std::map<GEDGraph::NodeID, std::vector<typename AnchorAwareGED<UserNodeLabel, UserEdgeLabel>::Edge_>> sorted_edges_;
85  };
86 
87  class TreeNode_ {
88 
89  public:
90 
91  TreeNode_(const GEDGraph & g, const GEDGraph & h, const AnchorAwareGED * exact);
92 
93  TreeNode_(const TreeNode_ & tree_node);
94 
95  double lower_bound() const;
96 
97  void operator=(const TreeNode_ & rhs);
98 
99  bool operator<(const TreeNode_ & rhs) const;
100 
101  void prepare_for_sibling_generation();
102 
103  void prepare_for_child_generation();
104 
105  void append_extension(const GEDGraph & g, const GEDGraph & h, const NodeMap & extension);
106 
107  void append_next_assignment(const NodeMap & extension);
108 
109  void populate_lsape_instance(const GEDGraph & g, const GEDGraph & h, DMatrix & lsape_instance);
110 
111  void set_lower_bound_to_leaf(double lower_bound_to_leaf);
112 
113  void update_induced_cost(const GEDGraph & g, const GEDGraph & h);
114 
115  double induced_cost() const;
116 
117  const NodeMap & node_map() const;
118 
119  bool is_leaf_node() const;
120 
121  void extend_leaf_node(const GEDGraph & g, const GEDGraph & h);
122 
123  GEDGraph::NodeID next_unmatched_node_in_g() const;
124 
125  GEDGraph::NodeID last_matched_node_in_g() const;
126 
127  bool has_unexplored_sibling();
128 
129  std::size_t num_unmatched_nodes_in_g() const;
130 
131  std::size_t num_unmatched_nodes_in_h() const;
132 
133  void update_original_id_of_unmatched_nodes_in_h();
134 
135  private:
136 
137  const AnchorAwareGED * exact_;
138 
139  NodeMap node_map_;
140 
141  std::vector<bool> is_matched_node_in_g_;
142 
143  std::vector<bool> is_matched_node_in_h_;
144 
145  std::vector<bool> is_candidate_in_h_;
146 
147  bool dummy_node_is_candidate_in_h_;
148 
149  std::vector<std::size_t> original_id_of_unmatched_nodes_in_h_;
150 
151  double induced_cost_;
152 
153  double lower_bound_to_leaf_;
154 
155  std::size_t num_matched_nodes_in_g_;
156 
157  std::size_t num_matched_nodes_in_h_;
158 
159  double compute_deletion_cost_(const GEDGraph & g, GEDGraph::NodeID i) const;
160 
161  double compute_insertion_cost_(const GEDGraph & h, GEDGraph::NodeID k) const;
162 
163  double compute_branch_fast_substitution_cost_(const GEDGraph & g, const GEDGraph & h, GEDGraph::NodeID i, GEDGraph::NodeID k) const;
164 
165  double compute_branch_substitution_cost_(const GEDGraph & g, const GEDGraph & h, GEDGraph::NodeID i, GEDGraph::NodeID k) const;
166  };
167 
168  LSAPESolver::Model lsape_model_;
169 
170  SearchMethod_ search_method_;
171 
172  LowerBoundMethod_ lower_bound_method_;
173 
174  std::size_t num_threads_;
175 
176  double time_limit_in_sec_;
177 
178  bool map_root_to_root_;
179 
180  std::map<GEDGraph::GraphID, SortedEdges_> sorted_edges_;
181 
182  NodeMap best_feasible_;
183 
184  std::priority_queue<TreeNode_> open_;
185 
186  double omega_;
187 
188  // Member functions inherited from GEDMethod.
189 
190  virtual void ged_run_(const GEDGraph & g, const GEDGraph & h, Result & result) final;
191 
192  virtual void ged_set_default_options_() final;
193 
194  virtual std::string ged_valid_options_string_() const final;
195 
196  virtual bool ged_parse_option_(const std::string & option, const std::string & arg) final;
197 
198  virtual void ged_init_() final;
199 
200  // Private helper functions.
201 
202  void init_graph_(const GEDGraph & graph);
203 
204  void generate_best_child_(const GEDGraph & g, const GEDGraph & h, const TreeNode_ & tree_node);
205 
206  void generate_best_sibling_(const GEDGraph & g, const GEDGraph & h, const TreeNode_ & tree_node);
207 
208  void generate_next_tree_node_(const GEDGraph & g, const GEDGraph & h, TreeNode_ & next_map, bool update_induced_cost, bool update_upper_bound);
209 };
210 
211 }
212 
213 #endif /* SRC_METHODS_ANCHOR_AWARE_GED_HPP_ */
Contains the standardized input data along with basic functionality.
Definition: ged_data.hpp:55
virtual void ged_run_(const GEDGraph &g, const GEDGraph &h, Result &result) final
Runs the method with options specified by set_options().
A class for node maps.
Definition: node_map.hpp:43
A wrapper structure for the result of calls to ged::GEDMethod::run_as_util() and ged::GEDMethod::ged_...
Definition: result.hpp:38
Abstract class for the (suboptimal) computation of the graph edit distance.
Definition: ged_method.hpp:40
virtual void ged_init_() final
Initializes the method.
std::size_t LabelID
Internally used type of node and edge labels.
virtual std::string ged_valid_options_string_() const final
Returns string of all valid options.
The normalized input graphs used by GEDLIB. All labels are integers.
Definition: ged_graph.hpp:104
detail::GedGraphAL::edge_descriptor EdgeID
Internally used edge ID type.
Definition: ged_graph.hpp:110
Global namespace for GEDLIB.
Computes the exact graph edit distance for general edit costs.
virtual void ged_set_default_options_() final
Sets all options to default values.
std::size_t NodeID
Internally used vertex ID type.
Definition: ged_graph.hpp:108
Model
Selects a model for solving LSAPE with the Hungarian algorithm.
virtual bool ged_parse_option_(const std::string &option, const std::string &arg) final
Parses one option.