Gudhi  1.1.0
 All Classes Functions Typedefs Friends Groups Pages
Edge_length_cost.h
1  /* This file is part of the Gudhi Library. The Gudhi library
2  * (Geometric Understanding in Higher Dimensions) is a generic C++
3  * library for computational topology.
4  *
5  * Author(s): David Salinas
6  *
7  * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France)
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef GUDHI_EDGE_LENGTH_COST_H_
24 #define GUDHI_EDGE_LENGTH_COST_H_
25 
26 #include "Cost_policy.h"
27 
28 namespace Gudhi{
29 
30 namespace contraction {
31 
32 
36 template< typename EdgeProfile> class Edge_length_cost : public Cost_policy<EdgeProfile>{
37 public:
38  typedef typename Cost_policy<EdgeProfile>::Cost_type Cost_type;
39  typedef typename EdgeProfile::Point Point;
40  Cost_type operator()(const EdgeProfile& profile, const boost::optional<Point>& placement) const override{
41  double res = 0;
42  auto p0_coord = profile.p0().begin();
43  auto p1_coord = profile.p1().begin();
44  for(; p0_coord != profile.p0().end(); p0_coord++, p1_coord++){
45  res += (*p0_coord - *p1_coord) * (*p0_coord - *p1_coord);
46  }
47  return res;
48  }
49 
50 };
51 
52 } // namespace contraction
53 
54 } // namespace GUDHI
55 
56 #endif /* GUDHI_EDGE_LENGTH_COST_H_ */
Policy to specify the cost of contracting an edge.
Definition: Cost_policy.h:36
return a cost corresponding to the squared length of the edge
Definition: Edge_length_cost.h:36