graph_analysis
CorrelationClustering.hpp
Go to the documentation of this file.
1 #ifndef GRAPH_ANALYSIS_ALGORITHMS_CORRELATION_CLUSTERING_HPP
2 #define GRAPH_ANALYSIS_ALGORITHMS_CORRELATION_CLUSTERING_HPP
3 
4 #include <map>
5 #include <glpk.h>
6 #include <numeric/Combinatorics.hpp>
7 #include <base-logging/Logging.hpp>
8 #include "../EdgeIterator.hpp"
9 #include "../Graph.hpp"
10 #include "../SharedPtr.hpp"
11 
12 
13 namespace graph_analysis {
14 namespace algorithms {
15 
16 typedef function1<double, Edge::Ptr> EdgeWeightFunction;
17 
21 struct Ball
22 {
23  Ball()
24  : graph()
25  , radius(0.0)
26  , volume(0.0)
27  {}
28 
30  double radius;
31  double volume;
32 };
33 
51 {
52  BaseGraph::Ptr mpGraph;
53  EdgeWeightFunction mEdgeWeightFunction;
54 
55  std::map<Edge::Ptr, double> mEdgeActivation;
56  std::vector<Edge::Ptr> mColumnToEdge;
57 
58  glp_prob* mpProblem;
59  size_t mTotalNumberOfColumns;
60 
61  double mInitialVolume;
62  double mConstant;
63 
64  void prepare();
65  void solve();
66 
73  bool areFormingTriangle(const std::vector<size_t>& triangleIndices) const;
74 
75 public:
76  CorrelationClustering(BaseGraph::Ptr graph, EdgeWeightFunction weightfunction);
77 
78  static std::string toString(const std::map<Edge::Ptr, double>& solution);
79 
80  void round();
81 
87  std::map<Edge::Ptr, double> getEdgeActivation() const { return mEdgeActivation; }
88 
97  double cut(Ball ball);
98 
99  double volume(Ball ball);
100 
108  Ball createBall(Vertex::Ptr vertex, double radius);
109 };
110 
111 } // end namespace algorithms
112 } // end namespace graph_analysis
113 #endif // GRAPH_ANALYSIS_ALGORITHMS_CORRELATION_CLUSTERING_HPP
function1< double, Edge::Ptr > EdgeWeightFunction
Definition: CorrelationClustering.hpp:16
double radius
Definition: CorrelationClustering.hpp:30
std::map< Edge::Ptr, double > getEdgeActivation() const
Definition: CorrelationClustering.hpp:87
BaseGraph::Ptr graph
Definition: CorrelationClustering.hpp:29
Main namespace of the graph analysis library.
Definition: BFS.cpp:3
shared_ptr< Vertex > Ptr
Definition: Vertex.hpp:22
double volume
Definition: CorrelationClustering.hpp:31
Ball()
Definition: CorrelationClustering.hpp:23
Implementation of "Correlation Clustering in General Weighted Graphs" (Demaine et al...
Definition: CorrelationClustering.hpp:50
A Ball representation for the CorrelationClustering.
Definition: CorrelationClustering.hpp:21
shared_ptr< BaseGraph > Ptr
Definition: BaseGraph.hpp:34