Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

ModifiedNibbleClusterer.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/EpsilonTest.h>
35 #include <ogdf/basic/Graph.h>
36 #include <ogdf/basic/GraphCopy.h>
37 #include <ogdf/basic/GraphList.h>
38 #include <ogdf/basic/geometry.h>
39 
40 #include <cmath>
41 #include <vector>
42 
43 namespace ogdf {
44 
46 
59 public:
62  , m_maxClusterSize(100)
63  , maxClusterNum(100)
64  , m_spreadProbability(0.8)
65  , m_pG(nullptr)
66  , m_pGC(nullptr)
67  , m_sns(StartNodeStrategy::MaxDeg) { }
68 
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 
94  void setMaxClusterSize(long i) { m_maxClusterSize = i; }
95 
96  // Smaller clusters are joint with a neighbor (non-recursive) as a postprocessing
97  void setClusterSizeThreshold(int threshold) {
98  if (threshold > 0) {
99  m_clusterThreshold = threshold;
100  }
101  }
102 
104 
105 protected:
106  void initialize(); //1< Initialize values for calculation before first step
108  void modifiedNibble(node snode,
109  std::vector<node>& bestCluster);
110  double findBestCluster(NodeArray<bool>& isActive, std::vector<node>& activeNodes,
111  std::vector<node>& cluster);
112  void spreadValues(NodeArray<bool>& isActive, std::vector<node>& activeNodes,
113  NodeArray<double>& probUpdate);
114 
115  inline long maxClusterSize() { return m_maxClusterSize; }
116 
117  // Arithmetic plus Geometric Progression
118  int aPGP(int i) {
119  const int a = 2;
120  const int d = 7;
121  const double r = 1.5;
122  return static_cast<int>(ceil(a * pot(r, i))) + i * d + a;
123  }
124 
125  // TODO we expect i to be very small, but do this efficiently anyway
126  double pot(double r, long i) { return pow(r, static_cast<double>(i)); }
127 
129  const int factor = 25;
130  //does not make sense to set it to 500 as they did, as we want less clusters.
131  return factor * m_maxClusterSize;
132  }
133 
134  void postProcess();
135 
136 private:
137  int m_steps;
138  int m_clusterThreshold; // Below that size all remaining nodes are just packed in a cluster
140  long m_maxActiveNodes; // Bound on number of nodes in active set
142  double m_spreadProbability; //how much is spread, i.e. 1-val is the prob to stay at the node
143  node m_startNode; // Node to start a walk from
144  NodeArray<double> m_prob; // Probability of a node along the walk
148 
149  // Tests
150  bool testSpreadSum() {
151  double sum = 0.0;
152  for (node v : m_pGC->nodes) {
153  sum += m_prob[v];
154  }
155  return OGDF_GEOM_ET.equal(sum, 1.0);
156  }
157 };
158 
159 }
ogdf::ModifiedNibbleClusterer::m_spreadProbability
double m_spreadProbability
Definition: ModifiedNibbleClusterer.h:142
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::ModifiedNibbleClusterer::m_maxClusterSize
long m_maxClusterSize
Definition: ModifiedNibbleClusterer.h:139
EpsilonTest.h
Compare floating point numbers with epsilons and integral numbers with normal compare operators.
Graph.h
Includes declaration of graph class.
ogdf::ModifiedNibbleClusterer::maxClusterNum
int maxClusterNum
Definition: ModifiedNibbleClusterer.h:141
geometry.h
Declaration of classes GenericPoint, GenericPolyline, GenericLine, GenericSegment,...
ogdf::ModifiedNibbleClusterer::setMaxClusterSize
void setMaxClusterSize(long i)
Definition: ModifiedNibbleClusterer.h:94
ogdf::ModifiedNibbleClusterer::initialize
void initialize()
ogdf::ModifiedNibbleClusterer::StartNodeStrategy::MaxDeg
@ MaxDeg
ogdf::ModifiedNibbleClusterer::findBestCluster
double findBestCluster(NodeArray< bool > &isActive, std::vector< node > &activeNodes, std::vector< node > &cluster)
ogdf::ModifiedNibbleClusterer::StartNodeStrategy::Random
@ Random
ogdf::ModifiedNibbleClusterer::call
long call(Graph &G, NodeArray< long > &clusterNum)
Call method: Creates a clustering of G Returns number of created clusters and sets cluster index for ...
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:391
ogdf::ModifiedNibbleClusterer
The modified nibble clustering algorithm.
Definition: ModifiedNibbleClusterer.h:58
ogdf::ModifiedNibbleClusterer::m_startNode
node m_startNode
Definition: ModifiedNibbleClusterer.h:143
ogdf::ClusterElement
Representation of clusters in a clustered graph.
Definition: ClusterGraph.h:62
r
int r[]
Definition: hierarchical-ranking.cpp:13
ogdf::Graph::nodes
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition: Graph_d.h:932
ogdf::ModifiedNibbleClusterer::m_maxActiveNodes
long m_maxActiveNodes
Definition: ModifiedNibbleClusterer.h:140
ogdf::OGDF_GEOM_ET
const EpsilonTest OGDF_GEOM_ET
ogdf::ModifiedNibbleClusterer::pot
double pot(double r, long i)
Definition: ModifiedNibbleClusterer.h:126
ogdf::ModifiedNibbleClusterer::m_pG
Graph * m_pG
Definition: ModifiedNibbleClusterer.h:145
GraphList.h
Decralation of GraphElement and GraphList classes.
ogdf::ModifiedNibbleClusterer::StartNodeStrategy::MinDeg
@ MinDeg
ogdf::ModifiedNibbleClusterer::maxClusterSize
long maxClusterSize()
Definition: ModifiedNibbleClusterer.h:115
ogdf::ModifiedNibbleClusterer::m_prob
NodeArray< double > m_prob
Definition: ModifiedNibbleClusterer.h:144
GraphCopy.h
Declaration of graph copy classes.
ogdf::ModifiedNibbleClusterer::StartNodeStrategy
StartNodeStrategy
Definition: ModifiedNibbleClusterer.h:103
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
ogdf::ModifiedNibbleClusterer::setClusterSizeThreshold
void setClusterSizeThreshold(int threshold)
Definition: ModifiedNibbleClusterer.h:97
ogdf::ModifiedNibbleClusterer::m_sns
StartNodeStrategy m_sns
Definition: ModifiedNibbleClusterer.h:147
ogdf::ModifiedNibbleClusterer::selectStartNode
node selectStartNode()
select start node according to some strategy
ogdf::ModifiedNibbleClusterer::modifiedNibble
void modifiedNibble(node snode, std::vector< node > &bestCluster)
main step with walks starting from snode
ogdf::EpsilonTest::equal
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:107
ogdf::ModifiedNibbleClusterer::testSpreadSum
bool testSpreadSum()
Definition: ModifiedNibbleClusterer.h:150
ogdf::ModifiedNibbleClusterer::spreadValues
void spreadValues(NodeArray< bool > &isActive, std::vector< node > &activeNodes, NodeArray< double > &probUpdate)
ogdf::ModifiedNibbleClusterer::m_pGC
GraphCopy * m_pGC
Definition: ModifiedNibbleClusterer.h:146
ogdf::ModifiedNibbleClusterer::setMaxClusterNum
void setMaxClusterNum(int i)
Call method: Creates a clustering of G in C Returns number of created clusters.
Definition: ModifiedNibbleClusterer.h:92
ogdf::ModifiedNibbleClusterer::~ModifiedNibbleClusterer
~ModifiedNibbleClusterer()
Definition: ModifiedNibbleClusterer.h:69
ogdf::ModifiedNibbleClusterer::activeNodeBound
long activeNodeBound()
Definition: ModifiedNibbleClusterer.h:128
ogdf::ModifiedNibbleClusterer::postProcess
void postProcess()
ogdf::ModifiedNibbleClusterer::m_steps
int m_steps
Definition: ModifiedNibbleClusterer.h:137
ogdf::ModifiedNibbleClusterer::ModifiedNibbleClusterer
ModifiedNibbleClusterer()
Definition: ModifiedNibbleClusterer.h:60
ogdf::ModifiedNibbleClusterer::aPGP
int aPGP(int i)
Definition: ModifiedNibbleClusterer.h:118
ogdf::ModifiedNibbleClusterer::m_clusterThreshold
int m_clusterThreshold
Definition: ModifiedNibbleClusterer.h:138
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240