GEDLIB  1.0
lsape_based_method.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_LSAPE_BASED_METHOD_HPP_
28 #define SRC_METHODS_LSAPE_BASED_METHOD_HPP_
29 
30 namespace ged {
31 
55 template<class UserNodeLabel, class UserEdgeLabel>
56 class LSAPEBasedMethod : public GEDMethod<UserNodeLabel, UserEdgeLabel> {
57 
58 public:
59 
60  // Constructor and destructor.
61 
66  virtual ~LSAPEBasedMethod() = 0;
67 
73 
74  // Extension of interface provided by GEDMethod.
75 
83  void populate_instance_and_run_as_util(const GEDGraph & g, const GEDGraph & h, Result & result, DMatrix & lsape_instance);
84 
91  void populate_instance(const GEDGraph & g, const GEDGraph & h, DMatrix & lsape_instance);
92 
93 protected:
94 
99 
104 
109 
114 
118  std::size_t num_threads_;
119 
120 private:
121 
122  enum CentralityMethod_ {NONE, DEGREE, EIGENVECTOR, PAGERANK};
123 
124  CentralityMethod_ centrality_method_;
125 
126  double centrality_weight_;
127 
128  std::map<GEDGraph::GraphID, std::vector<double>> centralities_;
129 
130  int max_num_solutions_;
131 
132  // Member functions inherited from GEDMethod.
133 
134  virtual void ged_init_() final;
135 
136  virtual void ged_run_(const GEDGraph & g, const GEDGraph & h, Result & result) final;
137 
138  virtual bool ged_parse_option_(const std::string & option, const std::string & arg) final;
139 
140  virtual std::string ged_valid_options_string_() const final;
141 
142  virtual void ged_set_default_options_() final;
143 
144  // Private helper member functions.
145 
146  void init_graph_(const GEDGraph & graph);
147 
148  void init_centralities_(const GEDGraph & graph);
149 
150  void add_centralities_(const GEDGraph & g, const GEDGraph & h, DMatrix & master_problem);
151 
152  void compute_eigenvector_with_largest_eigenvalue_(const DMatrix & symmetric_matrix, std::vector<double> & eigenvector, double & eigenvalue);
153 
154  // Virtual member functions to be overridden by derived classes.
155 
160  virtual void lsape_init_();
161 
169  virtual bool lsape_parse_option_(const std::string & option, const std::string & arg);
170 
176  virtual std::string lsape_valid_options_string_() const;
177 
182  virtual void lsape_set_default_options_();
183 
191  virtual void lsape_populate_instance_(const GEDGraph & g, const GEDGraph & h, DMatrix & lsape_instance);
192 
198  virtual void lsape_init_graph_(const GEDGraph & graph);
199 
205  virtual void lsape_pre_graph_init_(bool called_at_runtime);
206 
211  virtual void lsape_default_post_graph_init_();
212 
220  virtual double lsape_lower_bound_scaling_factor_(const GEDGraph & g, const GEDGraph & h);
221 
222 };
223 
224 }
225 
226 #endif /* SRC_METHODS_LSAPE_BASED_METHOD_HPP_ */
void populate_instance_and_run_as_util(const GEDGraph &g, const GEDGraph &h, Result &result, DMatrix &lsape_instance)
Runs the method with options specified by set_options() and provides access to constructed LSAPE inst...
virtual bool lsape_parse_option_(const std::string &option, const std::string &arg)
Parses one option that is not among the ones shared by all derived classes of ged::LSAPEBasedMethod.
virtual void lsape_set_default_options_()
Sets all options that are not among the ones shared by all derived classes of ged::LSAPEBasedMethod t...
Contains the standardized input data along with basic functionality.
Definition: ged_data.hpp:55
virtual ~LSAPEBasedMethod()=0
Pure virtual destructor.
std::size_t num_threads_
The number of threads to be used.
virtual std::string lsape_valid_options_string_() const
Returns string of all valid options that are not among the ones shared by all derived classes of ged:...
GreedyMethod
Selects a greedy method.
virtual double lsape_lower_bound_scaling_factor_(const GEDGraph &g, const GEDGraph &h)
Returns scaling factor for lower bound.
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_set_default_options_() final
Sets all options to default values.
virtual void lsape_default_post_graph_init_()
Default initializes the method at runtime after initializing the global variables for the graphs...
bool solve_optimally_
Flag that equals true if an optimal LSAPE solver is used and false if a greedy method is employed...
virtual void ged_init_() final
Initializes the method.
bool compute_lower_bound_
Flag that should be set to true if and only if the method computes a lower bound. ...
LSAPESolver::Model lsape_model_
Specifies model for optimal LSAPE solver.
Abstract class for methods that use lossy transformations to LSAPE for approximating the graph edit d...
void populate_instance(const GEDGraph &g, const GEDGraph &h, DMatrix &lsape_instance)
Populates the LSAPE instance.
The normalized input graphs used by GEDLIB. All labels are integers.
Definition: ged_graph.hpp:104
virtual void lsape_init_graph_(const GEDGraph &graph)
Initializes global variables for one graph.
Global namespace for GEDLIB.
virtual void lsape_populate_instance_(const GEDGraph &g, const GEDGraph &h, DMatrix &lsape_instance)
Populates the LSAPE instance.
virtual void lsape_pre_graph_init_(bool called_at_runtime)
Initializes the method at runtime or during initialization before initializing the global variables f...
virtual std::string ged_valid_options_string_() const final
Returns string of all valid options.
virtual void ged_run_(const GEDGraph &g, const GEDGraph &h, Result &result) final
Runs the method with options specified by set_options().
LSAPESolver::GreedyMethod greedy_method_
Specifies method for greedy LSAPE solver.
Model
Selects a model for solving LSAPE with the Hungarian algorithm.
virtual void lsape_init_()
Initializes the method after initializing the global variables for the graphs.
LSAPEBasedMethod(const GEDData< UserNodeLabel, UserEdgeLabel > &ged_data)
Constructor.
virtual bool ged_parse_option_(const std::string &option, const std::string &arg) final
Parses one option.