1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
/*
* $Revision: 3521 $
*
* last checkin:
* $Author: gutwenger $
* $Date: 2013-05-31 14:52:33 +0200 (Fri, 31 May 2013) $
***************************************************************/
/** \file
* \brief Declaration of interface for clustering algorithms that
* compute a clustering for a given graph based on some
* structural or semantical properties.
*
* Precondition:
* Input graph has to be connected
*
* \author Karsten Klein
*
* \par License:
* This file is part of the Open Graph Drawing Framework (OGDF).
*
* \par
* Copyright (C)<br>
* See README.txt in the root directory of the OGDF installation for details.
*
* \par
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* Version 2 or 3 as published by the Free Software Foundation;
* see the file LICENSE.txt included in the packaging of this file
* for details.
*
* \par
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* \par
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* \see http://www.gnu.org/copyleft/gpl.html
***************************************************************/
#ifdef _MSC_VER
#pragma once
#endif
#ifndef OGDF_CLUSTERER_MODULE_H
#define OGDF_CLUSTERER_MODULE_H
#include <ogdf/basic/Graph.h>
#include <ogdf/cluster/ClusterGraph.h>
#include <ogdf/basic/simple_graph_alg.h>
namespace ogdf {
//Helper classes to code a clustering, used as an interface to applications that
//need to build the clustergraph structure themselves
class SimpleCluster
{
public:
SimpleCluster(SimpleCluster* parent = 0) : m_size(0), m_parent(parent), m_index(-1) { }
//insert vertices and children
void pushBackVertex(node v) {m_nodes.pushBack(v);}
void pushBackChild(SimpleCluster* s) {m_children.pushBack(s);}
void setParent(SimpleCluster* parent) {m_parent = parent;}
SimpleCluster* getParent() {return m_parent;}
void setIndex(int index) {m_index = index;}
int getIndex() {return m_index;}
SList<node> &nodes() {return m_nodes;}
SList<SimpleCluster*> &children() {return m_children;}
int m_size; //preliminary: allowed to be inconsistent with real vertex number to
//allow lazy vertex addition (should therefore be local Array?)
private:
SList<node> m_nodes;
SList<SimpleCluster*> m_children;
SimpleCluster* m_parent;
int m_index; //index of the constructed cluster
};//class SimpleCluster
/**
* \brief Interface for algorithms that compute a clustering for a
* given graph
*
* The class ClustererModule is the base class for clustering
* classes that allow to compute some hierarchical clustering
*/
class OGDF_EXPORT ClustererModule
{
public:
//Constructor taking a graph G to be clustered
explicit ClustererModule(const Graph &G) : m_pGraph(&G) {OGDF_ASSERT(isConnected(G));}
//! Default constructor, initializes a clustering module.
// Allows to cluster multiple
// graphs with the same instance of the Clusterer
ClustererModule() {}
/**
* \brief Sets the graph to be clustered
*
* @param G is the input graph
*
*/
void setGraph(const Graph &G) {OGDF_ASSERT(isConnected(G));m_pGraph = &G;}
//! Returns the graph to be clustered
const Graph& getGraph() const {return *m_pGraph;}
/**
* \brief compute some kind of clustering on the graph m_pGraph
*
* This is the algorithm call that has to be implemented by derived classes
*
* @param sl is the resulting list of clusters
*/
virtual void computeClustering(SList<SimpleCluster*> &sl) = 0;
//! translate computed clustering into cluster hierarchy in cluster graph C
virtual void createClusterGraph(ClusterGraph &C) = 0;
//! compute a clustering index for each vertex
virtual double computeCIndex(const Graph & G, node v) = 0;
//! compute a clustering index for each vertex
virtual double computeCIndex(node v) = 0;
//! compute the average clustering index for the given graph
virtual double averageCIndex()
{
return averageCIndex(*m_pGraph);
}
virtual double averageCIndex(const Graph &G)
{
node v;
double ciSum = 0.0;
forall_nodes(v, G)
{
ciSum += computeCIndex(G, v);
}
return ciSum / (G.numberOfNodes());
}
protected:
const Graph* m_pGraph; //the graph to be clustered
OGDF_MALLOC_NEW_DELETE
};//class ClustererModule
} //end namespace ogdf
#endif /*CLUSTERERMODULE_H_*/
|