GEDLIB  1.0
ls_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_LS_BASED_METHOD_HPP_
28 #define SRC_METHODS_LS_BASED_METHOD_HPP_
29 
30 namespace ged {
31 
51 template<class UserNodeLabel, class UserEdgeLabel>
52 class LSBasedMethod : public GEDMethod<UserNodeLabel, UserEdgeLabel> {
53 
54 public:
55 
60  virtual ~LSBasedMethod() = 0;
61 
67 
68 protected:
69 
73  std::size_t num_threads_;
74 
75 private:
76 
77  LSAPEBasedMethod<UserNodeLabel, UserEdgeLabel> * initialization_method_;
78 
79  std::string initialization_options_;
80 
81  GEDMethod<UserNodeLabel, UserEdgeLabel> * lower_bound_method_;
82 
83  std::string lower_bound_method_options_;
84 
85  double random_substitution_ratio_;
86 
87  std::size_t num_initial_solutions_;
88 
89  double ratio_runs_from_initial_solutions_;
90 
91  std::size_t num_randpost_loops_;
92 
93  std::size_t max_randpost_retrials_;
94 
95  double randpost_penalty_;
96 
97  double randpost_decay_;
98 
99  std::string logfile_name_;
100 
101  bool use_real_randomness_;
102 
103  // Member functions inherited from GEDMethod.
104 
105  virtual void ged_init_() final;
106 
107  virtual void ged_run_(const GEDGraph & g, const GEDGraph & h, Result & result) final;
108 
109  virtual bool ged_parse_option_(const std::string & option, const std::string & arg) final;
110 
111  virtual std::string ged_valid_options_string_() const final;
112 
113  virtual void ged_set_default_options_() final;
114 
115  // Private helper member functions.
116 
117  std::size_t num_runs_from_initial_solutions_() const;
118 
119  void generate_initial_node_maps_(const GEDGraph & g, const GEDGraph & h, std::vector<NodeMap> & initial_node_maps, Result & result);
120 
121  void generate_random_initial_node_maps_(const GEDGraph & g, const GEDGraph & h, std::vector<NodeMap> & initial_node_maps);
122 
123  void generate_lsape_based_initial_node_maps_(const GEDGraph & g, const GEDGraph & h, std::vector<NodeMap> & initial_node_maps, Result & result);
124 
125  double update_counts_matrix_and_visited_node_maps_(const std::vector<NodeMap> & result_node_maps, const std::vector<bool> & is_converged_node_map, const double & upper_bound,
126  const double & lower_bound, std::vector<NodeMap> & visited_node_maps, std::size_t loop, std::vector<std::vector<double>> & counts_matrix) const;
127 
128  void generate_node_maps_from_counts_matrix_(const GEDGraph & g, const GEDGraph & h,const std::vector<std::vector<double>> & counts_matrix, std::vector<NodeMap> & visited_node_maps, std::vector<NodeMap> & initial_node_maps) const;
129 
130  // Virtual member functions to be overridden by derived classes.
131 
141  virtual void ls_run_from_initial_solution_(const GEDGraph & g, const GEDGraph & h, double lower_bound, const NodeMap & initial_node_map, NodeMap & output_node_map);
142 
147  virtual void ls_init_();
148 
155  virtual void ls_runtime_init_(const GEDGraph & g, const GEDGraph & h);
156 
164  virtual bool ls_parse_option_(const std::string & option, const std::string & arg);
165 
171  virtual std::string ls_valid_options_string_() const;
172 
177  virtual void ls_set_default_options_();
178 
179 };
180 
181 }
182 
183 #endif /* SRC_METHODS_LS_BASED_METHOD_HPP_ */
Abstract class for methods that use variants of local search for upper bounding the graph edit distan...
Contains the standardized input data along with basic functionality.
Definition: ged_data.hpp:55
virtual void ls_runtime_init_(const GEDGraph &g, const GEDGraph &h)
Initializes the method for a run between two graphs.
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
LSBasedMethod(const GEDData< UserNodeLabel, UserEdgeLabel > &ged_data)
Constructor.
virtual std::string ged_valid_options_string_() const final
Returns string of all valid options.
virtual bool ls_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::LSBasedMethod.
virtual ~LSBasedMethod()=0
Pure virtual destructor.
virtual void ged_run_(const GEDGraph &g, const GEDGraph &h, Result &result) final
Runs the method with options specified by set_options().
Abstract class for methods that use lossy transformations to LSAPE for approximating the graph edit d...
std::size_t num_threads_
The number of threads to be used.
virtual void ls_init_()
Initializes the method.
virtual std::string ls_valid_options_string_() const
Returns string of all valid options that are not among the ones shared by all derived classes of ged:...
virtual void ged_init_() final
Initializes the method.
The normalized input graphs used by GEDLIB. All labels are integers.
Definition: ged_graph.hpp:104
Global namespace for GEDLIB.
virtual void ged_set_default_options_() final
Sets all options to default values.
virtual void ls_run_from_initial_solution_(const GEDGraph &g, const GEDGraph &h, double lower_bound, const NodeMap &initial_node_map, NodeMap &output_node_map)
Runs the local search from an initial node map.
virtual bool ged_parse_option_(const std::string &option, const std::string &arg) final
Parses one option.
virtual void ls_set_default_options_()
Sets all options that are not among the ones shared by all derived classes of ged::LSBasedMethod to d...