GEDLIB  1.0
walks.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_WALKS_HPP_
28 #define SRC_METHODS_WALKS_HPP_
29 
30 namespace ged {
31 
46 template<class UserNodeLabel, class UserEdgeLabel>
47 class Walks : public LSAPEBasedMethod<UserNodeLabel, UserEdgeLabel> {
48 
49 public:
50 
51  virtual ~Walks();
52 
54 
55 private:
56 
57  typedef std::map<LabelID, double> Histogram_;
58 
59  typedef std::map<LabelID, std::vector<std::size_t>> InverseLabelIndex_;
60 
61  typedef std::pair<GEDGraph::NodeID, GEDGraph::NodeID> ProductNode_;
62 
63  typedef std::map<std::pair<GEDGraph::NodeID, GEDGraph::NodeID>, std::size_t> ProductNodeSizeTMap_;
64 
65  static std::size_t undefined_() {return std::numeric_limits<std::size_t>::max();}
66 
67  class AdjGraph_ {
68  public:
69  AdjGraph_(const GEDGraph & graph);
70 
71  AdjGraph_(const AdjGraph_ & adj_graph);
72 
73  AdjGraph_();
74 
75  void operator=(const AdjGraph_ & adj_graph);
76 
77  GEDGraph::NodeID node(std::size_t node_id) const;
78 
79  std::pair<std::vector<std::size_t>::const_iterator, std::vector<std::size_t>::const_iterator> nodes_with_label(LabelID label) const;
80 
81  std::size_t size() const;
82 
83  const Histogram_ & num_walks_from_node_to_labels(std::size_t node_id) const;
84 
85  double operator() (std::size_t row, std::size_t col) const;
86 
87  void compute_num_walks_(const std::set<LabelID> & node_labels, std::size_t depth);
88 
89  private:
90  IMatrix adj_matrix_;
91 
92  std::vector<Histogram_> num_walks_from_nodes_to_labels_;
93 
95 
96  InverseLabelIndex_ inverse_label_index_;
97  };
98 
99 
100  class ProductGraph_ {
101  public:
102  ProductGraph_(const GEDGraph & g, const GEDGraph & h);
103 
104  std::pair<std::vector<std::size_t>::const_iterator, std::vector<std::size_t>::const_iterator> nodes_with_label(LabelID label) const;
105 
106  std::size_t node_id(GEDGraph::NodeID node_g, GEDGraph::NodeID node_h) const;
107 
108  void compute_num_unmatched_walks_(const std::set<LabelID> & node_labels, const AdjGraph_ & adj_graph_g, const AdjGraph_ & adj_graph_h, std::size_t depth);
109 
110  double num_substituted_walks_ending_at_same_label(std::size_t row, std::size_t col) const;
111 
112  double num_substituted_walks_ending_at_different_labels(std::size_t row, std::size_t col) const;
113 
114  double num_inserted_or_deleted_walks(std::size_t row, std::size_t col) const;
115 
116  private:
117  IMatrix adj_matrix_;
118 
119  DMatrix num_substituted_walks_ending_at_same_label_;
120 
121  DMatrix num_substituted_walks_ending_at_different_labels_;
122 
123  DMatrix num_inserted_or_deleted_walks_;
124 
125  std::vector<ProductNode_> nodes_;
126 
127  InverseLabelIndex_ inverse_label_index_;
128 
129  ProductNodeSizeTMap_ product_node_to_id_;
130  };
131 
132  std::size_t depth_;
133 
134  std::size_t min_depth_;
135 
136  std::size_t max_depth_;
137 
138  std::string infile_;
139 
140  std::string outfile_;
141 
142  std::map<GEDGraph::GraphID, AdjGraph_> adj_graphs_;
143 
144  // Member functions inherited from LSAPEBasedMethod.
145 
146  virtual void lsape_set_default_options_() final;
147 
148  virtual std::string lsape_valid_options_string_() const final;
149 
150  virtual bool lsape_parse_option_(const std::string & option, const std::string & arg) final;
151 
152  virtual void lsape_init_graph_(const GEDGraph & graph) final;
153 
154  virtual void lsape_init_() final;
155 
156  virtual void lsape_populate_instance_(const GEDGraph & g, const GEDGraph & h, DMatrix & master_problem) final;
157 
158  virtual void lsape_pre_graph_init_(bool called_at_runtime) final;
159 
160  // Helper member functions.
161 
162  void init_node_labels_(const GEDGraph & g, const GEDGraph & h, std::set<LabelID> & node_labels) const;
163 
164  bool load_config_file_() const;
165 
166 };
167 
168 }
169 
170 #endif /* SRC_METHODS_WALKS_HPP_ */
Contains the standardized input data along with basic functionality.
Definition: ged_data.hpp:55
virtual void lsape_init_graph_(const GEDGraph &graph) final
Initializes global variables for one graph.
Definition: walks.ipp:112
virtual void lsape_set_default_options_() final
Sets all options that are not among the ones shared by all derived classes of ged::LSAPEBasedMethod t...
Definition: walks.ipp:54
std::map< std::size_t, NodeID > SizeTNodeMap
Map that assigns node IDs to integers.
Definition: ged_graph.hpp:118
Computes an upper bound for general edit costs.
Definition: walks.hpp:47
virtual void lsape_init_() final
Initializes the method after initializing the global variables for the graphs.
Definition: walks.ipp:133
virtual void lsape_populate_instance_(const GEDGraph &g, const GEDGraph &h, DMatrix &master_problem) final
Populates the LSAPE instance.
Definition: walks.ipp:198
std::size_t LabelID
Internally used type of node and edge labels.
Abstract class for methods that use lossy transformations to LSAPE for approximating the graph edit d...
The normalized input graphs used by GEDLIB. All labels are integers.
Definition: ged_graph.hpp:104
virtual void lsape_pre_graph_init_(bool called_at_runtime) final
Initializes the method at runtime or during initialization before initializing the global variables f...
Definition: walks.ipp:119
Global namespace for GEDLIB.
virtual std::string lsape_valid_options_string_() const final
Returns string of all valid options that are not among the ones shared by all derived classes of ged:...
Definition: walks.ipp:65
std::size_t NodeID
Internally used vertex ID type.
Definition: ged_graph.hpp:108
virtual bool lsape_parse_option_(const std::string &option, const std::string &arg) final
Parses one option that is not among the ones shared by all derived classes of ged::LSAPEBasedMethod.
Definition: walks.ipp:72