GEDLIB  1.0
ipfp.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_IPFP_HPP_
28 #define SRC_METHODS_IPFP_HPP_
29 
30 namespace ged {
31 
63 template<class UserNodeLabel, class UserEdgeLabel>
64 class IPFP : public LSBasedMethod<UserNodeLabel, UserEdgeLabel> {
65 
66 public:
67 
68  virtual ~IPFP();
69 
71 
72 private:
73 
74  enum QuadraticModel_ {C_QAP, B_QAP, QAPE, QAP};
75 
76  class QAPInstance_ {
77 
78  public:
79 
80  QAPInstance_();
81 
82  void init(const IPFP<UserNodeLabel, UserEdgeLabel> * ipfp, const GEDGraph & g, const GEDGraph & h);
83 
84  double operator() (std::size_t row_1, std::size_t col_1, std::size_t row_2, std::size_t col_2) const;
85 
86  double operator() (std::size_t row, std::size_t col) const;
87 
88  std::size_t num_rows() const;
89 
90  std::size_t num_cols() const;
91 
92  std::size_t num_nodes_g() const;
93 
94  std::size_t num_nodes_h() const;
95 
96  private:
97 
98  double quadratic_cost_qap_(std::size_t row_1, std::size_t col_1, std::size_t row_2, std::size_t col_2) const;
99 
100  double quadratic_cost_b_qap_(std::size_t row_1, std::size_t col_1, std::size_t row_2, std::size_t col_2) const;
101 
102  double quadratic_cost_qape_(std::size_t row_1, std::size_t col_1, std::size_t row_2, std::size_t col_2) const;
103 
104  double quadratic_cost_c_qap_(std::size_t row_1, std::size_t col_1, std::size_t row_2, std::size_t col_2) const;
105 
107 
108  const GEDGraph * g_;
109 
110  const GEDGraph * h_;
111 
112  std::size_t num_nodes_g_;
113 
114  std::size_t num_nodes_h_;
115 
116  double translation_factor_;
117  };
118 
119  QuadraticModel_ quadratic_model_;
120 
121  LSAPESolver::Model lsape_model_;
122 
123  double epsilon_;
124 
125  std::size_t max_itrs_;
126 
127  double time_limit_in_sec_;
128 
129  double omega_;
130 
131  QAPInstance_ qap_instance_;
132 
133  // Member functions inherited from LSBasedMethod.
134 
135  void ls_run_from_initial_solution_(const GEDGraph & g, const GEDGraph & h, double lower_bound, const NodeMap & initial_node_map, NodeMap & output_node_map) final;
136 
137  virtual void ls_runtime_init_(const GEDGraph & g, const GEDGraph & h) final;
138 
139  virtual void ls_set_default_options_() final;
140 
141  virtual bool ls_parse_option_(const std::string & options, const std::string & arg) final;
142 
143  virtual std::string ls_valid_options_string_() const final;
144 
145  // Private helper member functions.
146 
147  void node_map_to_matrix_(const NodeMap & node_map, DMatrix & matrix) const;
148 
149  double compute_induced_linear_cost_(const QAPInstance_ & qap_instance, const DMatrix & x) const;
150 
151  double compute_induced_linear_cost_(const QAPInstance_ & qap_instance, const LSAPSolver & solver) const;
152 
153  double compute_induced_linear_cost_(const QAPInstance_ & qap_instance, const LSAPESolver & solver) const;
154 
155  double compute_induced_quadratic_cost_(const QAPInstance_ & qap_instance, const LSAPSolver & solver) const;
156 
157  double compute_induced_quadratic_cost_(const QAPInstance_ & qap_instance, const LSAPESolver & solver) const;
158 
159  void solve_linear_problem_(const QAPInstance_ & qap_instance, LSAPSolver & solver,
160  double & min_linear_problem, double & linear_cost_b, double & overall_cost_b, DMatrix & b) const;
161 
162  void solve_linear_problem_(const QAPInstance_ & qap_instance, LSAPESolver & solver,
163  double & min_linear_problem, double & linear_cost_b, double & overall_cost_b, DMatrix & b) const;
164 
165  void solver_to_matrix_(const LSAPSolver & solver, DMatrix & b) const;
166 
167  void solver_to_matrix_(const LSAPESolver & solver, DMatrix & b) const;
168 
169  void init_linear_cost_matrix_(const QAPInstance_ & qap_instance, DMatrix & linear_cost_matrix) const;
170 
171  void init_next_linear_problem_(const QAPInstance_ & qap_instance, const DMatrix & x, const DMatrix & linear_cost_matrix, DMatrix & linear_problem) const;
172 
173  bool termination_criterion_met_(const Timer & timer, const double & alpha, const double & min_linear_problem, const std::size_t & current_itr, double lower_bound, double upper_bound) const;
174 
175 };
176 
177 }
178 
179 #endif /* SRC_METHODS_IPFP_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
This class solves LSAPE instances by calling the library lsape available at https://bougleux.users.greyc.fr/lsape/.
A class for node maps.
Definition: node_map.hpp:43
A timer class that can be used by methods that support time limits.
Definition: timer.hpp:38
virtual bool ls_parse_option_(const std::string &options, const std::string &arg) final
Parses one option that is not among the ones shared by all derived classes of ged::LSBasedMethod.
Definition: ipfp.ipp:196
virtual void ls_set_default_options_() final
Sets all options that are not among the ones shared by all derived classes of ged::LSBasedMethod to d...
Definition: ipfp.ipp:178
void ls_run_from_initial_solution_(const GEDGraph &g, const GEDGraph &h, double lower_bound, const NodeMap &initial_node_map, NodeMap &output_node_map) final
Runs the local search from an initial node map.
Definition: ipfp.ipp:53
virtual std::string ls_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: ipfp.ipp:189
The normalized input graphs used by GEDLIB. All labels are integers.
Definition: ged_graph.hpp:104
Global namespace for GEDLIB.
This class solves LSAP instances by calling the library lsape available at https://bougleux.users.greyc.fr/lsape/.
Definition: lsap_solver.hpp:39
void init()
Initializes the method with options specified by set_options().
Definition: ged_method.ipp:81
virtual void ls_runtime_init_(const GEDGraph &g, const GEDGraph &h) final
Initializes the method for a run between two graphs.
Definition: ipfp.ipp:170
Computes an upper bound for general edit costs.
Definition: ipfp.hpp:64
Model
Selects a model for solving LSAPE with the Hungarian algorithm.