Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

ModifiedNibbleClusterer.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Graph.h>
35 #include <ogdf/basic/GraphCopy.h>
36 #include <ogdf/basic/geometry.h>
37 #include <vector>
38 
39 namespace ogdf {
40 
42 
55 
56 public:
59  , m_maxClusterSize(100)
60  , maxClusterNum(100)
61  , m_spreadProbability(0.8)
62  , m_pG(nullptr)
63  , m_pGC(nullptr)
64  , m_sns(StartNodeStrategy::MaxDeg)
65  {
66  }
67 
69  {
70 #if 0
71  delete m_pGC;
72 #endif
73  }
74 
75  //TODO add a call with GraphAttributes and store in intweight
76 
79  long call(Graph &G, NodeArray<long> &clusterNum);
80 
87  long call(Graph &G, NodeArray<long> &clusterNum, NodeArray<long> &topLevelNum);
88 
91  // TODO long call(ClusterGraph &C, Graph & G) {}
92  void setMaxClusterNum(int i) {maxClusterNum = i;}
93  void setMaxClusterSize(long i) {m_maxClusterSize = i;}
94  // Smaller clusters are joint with a neighbor (non-recursive) as a postprocessing
95  void setClusterSizeThreshold(int threshold)
96  {
97  if (threshold > 0) {
98  m_clusterThreshold = threshold;
99  }
100  }
101 
103 
104 protected:
105  void initialize(); //1< Initialize values for calculation before first step
107  void modifiedNibble(node snode, std::vector<node> &bestCluster);
108  double findBestCluster(NodeArray<bool> &isActive, std::vector<node> &activeNodes, std::vector<node> &cluster);
109  void spreadValues(NodeArray<bool> &isActive, std::vector<node> &activeNodes, NodeArray<double> & probUpdate);
110 
111  inline long maxClusterSize() {
112  return m_maxClusterSize;
113  }
114 
115  // Arithmetic plus Geometric Progression
116  int aPGP(int i)
117  {
118  const int a = 2;
119  const int d = 7;
120  const double r = 1.5;
121  return static_cast<int>(ceil(a * pot(r, i))) + i*d + a;
122  }
123 
124  // TODO we expect i to be very small, but do this efficiently anyway
125  double pot(double r, long i)
126  {
127  return pow(r, static_cast<double>(i));
128  }
129 
131  {
132  const int factor = 25;
133  //does not make sense to set it to 500 as they did, as we want less clusters.
134  return factor*m_maxClusterSize;
135  }
136 
137  void postProcess();
138 
139 private:
140  int m_steps;
141  int m_clusterThreshold; // Below that size all remaining nodes are just packed in a cluster
143  long m_maxActiveNodes; // Bound on number of nodes in active set
145  double m_spreadProbability; //how much is spread, i.e. 1-val is the prob to stay at the node
146  node m_startNode; // Node to start a walk from
147  NodeArray<double> m_prob; // Probability of a node along the walk
151 
152  // Tests
154  {
155  double sum = 0.0;
156  for(node v : m_pGC->nodes) {
157  sum += m_prob[v];
158  }
159  return OGDF_GEOM_ET.equal(sum, 1.0);
160  }
161 };
162 
163 }
void setClusterSizeThreshold(int threshold)
std::enable_if< std::is_integral< T >::value, bool >::type equal(const T &x, const T &y) const
Compare if x is EQUAL to y for integral types.
Definition: EpsilonTest.h:113
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:492
void spreadValues(NodeArray< bool > &isActive, std::vector< node > &activeNodes, NodeArray< double > &probUpdate)
void modifiedNibble(node snode, std::vector< node > &bestCluster)
main step with walks starting from snode
The modified nibble clustering algorithm.
void setMaxClusterNum(int i)
Call method: Creates a clustering of G in C Returns number of created clusters.
const EpsilonTest OGDF_GEOM_ET
node selectStartNode()
select start node according to some strategy
Dynamic arrays indexed with nodes.
Definition: Graph_d.h:438
Declaration of graph copy classes.
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:249
Class for the representation of nodes.
Definition: Graph_d.h:169
double findBestCluster(NodeArray< bool > &isActive, std::vector< node > &activeNodes, std::vector< node > &cluster)
Representation of clusters in a clustered graph.
Definition: ClusterGraph.h:53
Includes declaration of graph class.
long call(Graph &G, NodeArray< long > &clusterNum)
Call method: Creates a clustering of G Returns number of created clusters and sets cluster index for ...
The namespace for all OGDF objects.
Declaration of classes GenericPoint, GenericPolyline, GenericLine, GenericSegment, DPolygon, DRect, DIntersectableRect.
Container::value_type sum(const Container &values)
Returns the sum of an iterable container of given values.
Definition: Math.h:245
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition: Graph_d.h:565