CluE  1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
doublesolution.h
Go to the documentation of this file.
1 #ifndef DOUBLESOLUTION_H
2 #define DOUBLESOLUTION_H
3 
4 #include "../base/solutionprovider.h"
5 #include "../base/proxyprovider.h"
6 #include "../base/partitionprovider.h"
7 
8 #include <vector>
9 
10 //TODO Derived documentation bug
11 
12 namespace CluE
13 {
14 
22 template<typename T> struct DoubleSolution : public SolutionProvider, public ProxyProvider<T>,
23  public PartitionProvider<T>
24 {
25 public:
27 
28  virtual ~DoubleSolution()
29  {
30  }
31 
32  virtual double computationtime() const;
33  virtual unsigned int number_of_solutions() const;
34  virtual unsigned int size_of_solution(unsigned int) const;
35 
36  virtual T proxy(unsigned int n, unsigned int c) const;
37  virtual std::vector<T> proxies(unsigned int n) const;
38 
39  virtual unsigned int clustersize(unsigned int, unsigned int) const;
40  virtual T* element(unsigned int, unsigned int, unsigned int) const;
41  virtual std::vector<T*> cluster(unsigned int, unsigned int) const;
42  virtual std::vector<std::vector<T*> > clustering(unsigned int) const;
43 
44  double seconds;
45  std::vector<std::vector<T> > proxysets;
46  std::vector<std::vector<std::vector<T*> > > partitions;
47 };
48 
49 template<typename T> DoubleSolution<T>::DoubleSolution() : seconds()
50 {
51 }
52 
53 template<typename T> double DoubleSolution<T>::computationtime() const
54 {
55  return seconds;
56 }
57 
58 template<typename T> unsigned int DoubleSolution<T>::number_of_solutions() const
59 {
60  unsigned int proxynum = this->proxysets.size();
61  unsigned int partitionnum = this->partitions.size();
62  return proxynum<partitionnum?proxynum:partitionnum;
63 }
64 
65 template<typename T> unsigned int DoubleSolution<T>::size_of_solution(unsigned int i) const
66 {
67  if (i<this->number_of_solutions())
68  {
69  unsigned int proxysize = this->proxysets[i].size();
70  unsigned int partitionsize = this->partitions[i].size();
71  return proxysize<partitionsize?proxysize:partitionsize;
72  }
73  return 0;
74 }
75 
76 template<typename T> T DoubleSolution<T>::proxy(unsigned int n, unsigned int c) const
77 {
78  if (n<this->proxysets.size())
79  if (c<this->proxysets[n].size())
80  return this->proxysets[n][c];
81 
82  std::cerr << "DoubleSolution<T>::proxy(" << n << "," << c << "): requested proxy not available"
83  << std::endl;
84  throw "ILLEGAL STATE";
85 }
86 
87 template<typename T> std::vector<T> DoubleSolution<T>::proxies(unsigned int n) const
88 {
89  if (n<this->proxysets.size())
90  return this->proxysets[n];
91  return std::vector<T>();
92 }
93 
94 template<typename T> unsigned int DoubleSolution<T>::clustersize(unsigned int g, unsigned int c) const
95 {
96  if (g<this->partitions.size())
97  if (c<this->partitions[g].size())
98  return this->partitions[g][c].size();
99  return 0;
100 }
101 
102 template<typename T> T* DoubleSolution<T>::element(unsigned int g, unsigned int c, unsigned int n) const
103 {
104  if (g<this->partitions.size())
105  if (c<this->partitions[g].size())
106  if (n<this->partitions[g][c].size())
107  return this->partitions[g][c][n];
108  return NULL;
109 }
110 
111 template<typename T> std::vector<T*> DoubleSolution<T>::cluster(unsigned int g, unsigned int c) const
112 {
113  if (g<this->partitions.size())
114  if (c<this->partitions[g].size())
115  return this->partitions[g][c];
116  return std::vector<T*>();
117 }
118 
119 template<typename T> std::vector<std::vector<T*> > DoubleSolution<T>::clustering(unsigned int g) const
120 {
121  if (g<this->partitions.size())
122  return this->partitions[g];
123  return std::vector<std::vector<T*> >();
124 }
125 
126 }
127 
128 #endif
Data structure for partitions and proxies.
Abstract base class to access results of proxy / center based clustering algorithms.
Definition: proxyprovider.h:14
virtual std::vector< std::vector< T * > > clustering(unsigned int) const
Returns the specified clustering as a vector of vector of pointers to the elements.
virtual unsigned int number_of_solutions() const
returns the number of available solutions
virtual double computationtime() const
returns the time needed for the last computation
virtual T proxy(unsigned int n, unsigned int c) const
returns the proxy for the specified clustering and cluster
virtual unsigned int size_of_solution(unsigned int) const
returns the size of a particular solution
virtual std::vector< T > proxies(unsigned int n) const
returns the proxies for the specified clustering
virtual std::vector< T * > cluster(unsigned int, unsigned int) const
Returns a vector of pointers to the elements of a particular cluster from the specified clustering...
virtual T * element(unsigned int, unsigned int, unsigned int) const
Returns a pointer to a particular element from the specified cluster and clustering.
Abstract base class to access results of partition based clustering algorithms.
std::vector< std::vector< T > > proxysets
virtual unsigned int clustersize(unsigned int, unsigned int) const
Returns the cardinality of the specified cluster from the computed clustering.
std::vector< std::vector< std::vector< T * > > > partitions
Abstract base class for algorithm solutions.