GEDLIB  1.0
letter.ipp
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_EDIT_COSTS_LETTER_IPP_
28 #define SRC_EDIT_COSTS_LETTER_IPP_
29 
30 namespace ged {
31 
32 template<>
33 Letter<GXLLabel, GXLLabel>::
34 ~Letter() {}
35 
36 template<>
38 Letter(double node_ins_del_cost, double edge_ins_del_cost, double alpha) :
39 node_ins_del_cost_{node_ins_del_cost},
40 edge_ins_del_cost_{edge_ins_del_cost},
41 alpha_{alpha} {}
42 
43 template<>
44 double
46 node_ins_cost_fun(const GXLLabel & node_label) const {
47  return alpha_ * node_ins_del_cost_;
48 }
49 
50 template<>
51 double
53 node_del_cost_fun(const GXLLabel & node_label) const {
54  return alpha_ * node_ins_del_cost_;
55 }
56 
57 template<>
58 double
60 node_rel_cost_fun(const GXLLabel & node_label_1, const GXLLabel & node_label_2) const {
61  double x_l_minus_x_r(std::stod(node_label_1.at("x")) - std::stod(node_label_2.at("x")));
62  double y_l_minus_y_r(std::stod(node_label_1.at("y")) - std::stod(node_label_2.at("y")));
63  return alpha_ * std::sqrt(std::pow(x_l_minus_x_r, 2) + std::pow(y_l_minus_y_r, 2));
64 }
65 
66 template<>
67 double
69 edge_ins_cost_fun(const GXLLabel & edge_label) const {
70  return (1 - alpha_) * edge_ins_del_cost_;
71 }
72 
73 template<>
74 double
76 edge_del_cost_fun(const GXLLabel & edge_label) const {
77  return (1 - alpha_) * edge_ins_del_cost_;
78 }
79 
80 template<>
81 double
83 edge_rel_cost_fun(const GXLLabel & edge_label_1, const GXLLabel & edge_label_2) const {
84  return 0.0;
85 }
86 
87 }
88 
89 #endif /* SRC_EDIT_COSTS_LETTER_IPP_ */
virtual double edge_ins_cost_fun(const UserEdgeLabel &edge_label) const final
Edge insertion cost function.
virtual double node_rel_cost_fun(const UserNodeLabel &node_label_1, const UserNodeLabel &node_label_2) const final
Node relabeling cost function.
Letter(double node_ins_del_cost=0.9, double edge_ins_del_cost=1.7, double alpha=0.75)
Constructor.
std::map< std::string, std::string > GXLLabel
Type of node and edge labels of graphs given in the .gxl file format.
virtual double edge_del_cost_fun(const UserEdgeLabel &edge_label) const final
Edge deletion cost function.
virtual double node_del_cost_fun(const UserNodeLabel &node_label) const final
Node deletion cost function.
Global namespace for GEDLIB.
virtual double node_ins_cost_fun(const UserNodeLabel &node_label) const final
Node insertions cost function.
virtual double edge_rel_cost_fun(const UserEdgeLabel &edge_label_1, const UserEdgeLabel &edge_label_2) const final
Edge relabeling cost function.