Skip to content

Commit

Permalink
K-medoids
Browse files Browse the repository at this point in the history
  • Loading branch information
billDrett committed Jan 25, 2017
0 parents commit 09b0c3b
Show file tree
Hide file tree
Showing 50 changed files with 17,457 additions and 0 deletions.
224 changes: 224 additions & 0 deletions List.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
#include <iostream>
#include <cstdlib>
#include "List.h"
#include "Node.h"

//dn xreiazontai an kanw include to .cpp file
#include "dataTypes.h"
#include "euclideanNode.h"
#include "clusterNode.h"
#include "kMedoids.h"

using namespace std;

template <class T>
List<T>::List()
{
listSize = 0;
start = NULL;
last = NULL;
}

template <class T>
List<T>::~List()
{
Node<T>* tmp = start;
Node<T>* del;

while(tmp != NULL)//diagrafoume enan enan tous komvous
{
del = tmp;
tmp = tmp->get_next();
listSize--;
delete del;
}
}

template <class T>
bool List<T>::checkEmpty()
{
return(listSize == 0);
}

template <class T>
int List<T>::getSize()
{
return listSize;
}

template <class T>
Node<T>* List<T>::get_begin()
{
return start;
}

template <class T>
Node<T>* List<T>::get_last()
{
return last;
}

template <class T>
Node<T>* List<T>::insertBeginning(T item) //epistrefei to node pou dhmiourghthike
{
Node<T>* node = new Node<T>(item);

if(checkEmpty()) //an einai to monadiko stoixeio prepei na allaksw ton deikti start kai last
{
start = node;
last = node;
listSize++;
return node;
}
//alliws eisodos stin arxi
node->set_next(start);
start->set_prev(node);

start = node;
listSize++;

return node;
}

template <class T>
Node<T>* List<T>::insertEnd(T item)
{
Node<T>* node = new Node<T>(item);

if(checkEmpty()) //an einai to monadiko stoixeio prepei na allaksw ton deikti start kai last
{
start = node;
last = node;
listSize++;
return node;
}
//alliws eisodos sto telos ths listas
last->set_next(node);
node->set_next(NULL);
node->set_prev(last);

last = node;
listSize++;
return node;
}

template <class T>
T List<T>::deleteFirstNode()
{
Node<T>* tmp;
T tmpAccount;
if(checkEmpty())
{
return 0;
}

tmp = start;
start = start->get_next();

if(listSize == 1) last = NULL; //arxi kai telos deixnoun sto idio, epomenos i lista exei mono ena stoixeio
else start->set_prev(NULL);

tmpAccount = tmp->get_data();
delete tmp;
listSize--;
return tmpAccount;
}

template <class T>
T List<T>::deleteLastNode()
{
Node<T>* tmp;
T tmpAccount;
if(checkEmpty())
{
return 0;
}

if(listSize == 1) //an exei mono ena stoixeio tote prepei na allaksei kai o deiktis start
{
tmpAccount = start->get_data();
delete start;
start = NULL;
last = NULL;
listSize--;
return tmpAccount;
}

tmpAccount = last->get_data();
tmp = last;
last = last->get_prev();
last->set_next(NULL);

delete tmp;
listSize--;
return tmpAccount;
}

template <class T>
T List<T>::deleteNode(Node<T>* node) //diagrafei tou sigekrimenou node
{
Node<T>* tmp;
T data;

if(checkEmpty() == true)
{
return 0;
}

if(start == node) // an einai o prwtos 'h o monadikos komvos
{
return this->deleteFirstNode();
}

if(last == node) //an o teleutaios
{
return this->deleteLastNode();
}

//elenxos gia sfalma
if(node->get_next() == NULL || node->get_prev()== NULL) return 0; //afou dn einai to prwto 'h teleutaio stoixeio dn prepei na einai null oi deiktes

tmp = node->get_prev();
tmp->set_next(node->get_next());
node->get_next()->set_prev(tmp);

data = node->get_data();
listSize--;
delete node;
return data;
}

template <class T>
T List<T>::getPoint(int pos) //epistrefei to tyxaio simeio
{
int count = 0;

for(Node<T>* i = start; i != NULL; i = i->get_next())
{
if(count == pos)
{
return i->get_data();
}

count++;
}
}

template class List<int>;
template class List<double>;
template class List<string>;

template class List<Vector* >;
template class List<Hamming* >;
template class List<EuclideanNode* >;
template class List<MatrixPoint* >;

template class List<ClusterNode<Vector*>*>;
template class List<ClusterNode<Hamming*>*>;
template class List<ClusterNode<EuclideanNode*>*>;
template class List<ClusterNode<MatrixPoint*>*>;

template class List<LshAssingNode<Vector*>*>;
template class List<LshAssingNode<Hamming*>*>;
template class List<LshAssingNode<EuclideanNode*>*>;
template class List<LshAssingNode<MatrixPoint*>*>;
36 changes: 36 additions & 0 deletions List.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef Included_List_H
#define Included_List_H

#include "Node.h"

template <class T>
class List
{
private:
int listSize;
Node<T>* start;
Node<T>* last;

public:
List();
~List();

bool checkEmpty();
int getSize();
Node<T>* get_begin();
Node<T>* get_last();

T getPoint(int pos);

Node<T>* insertEnd(T item);
Node<T>* insertBeginning(T item);
T deleteFirstNode();
T deleteLastNode();
T deleteNode(Node<T>* node);



void printList();
};
#endif

70 changes: 70 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# In order to execute this "Makefile " just type "make "
OBJS = main.o euclideanNode.o hashFunction.o List.o Node.o hashFunctionCosine.o hashFunctionEuclidean.o hashFunctionMatrix.o hashtable.o lsh.o psedoRandomNumbers.o readFile.o distancesCalculations.o centroid.o clusterNode.o generalFunctions.o initialization.o kMedoids.o
SOURCE = main.cpp euclideanNode.cpp hashFunction.cpp List.cpp Node.cpp hashFunctionCosine.cpp hashFunctionEuclidean.cpp hashFunctionMatrix.cpp hashtable.cpp lsh.cpp psedoRandomNumbers.cpp readFile.cpp distancesCalculations.cpp centroid.cpp clusterNode.cpp generalFunctions.cpp initialization.cpp kMedoids.cpp
HEADER = dataTypes.h euclideanNode.h hashFunction.h List.h Node.h hashFunctionCosine.h hashFunctionEuclidean.h hashFunctionMatrix.h hashtable.h lsh.h psedoRandomNumbers.h readFile.h distancesCalculations.h centroid.h clusterNode.h generalFunctions.h initialization.h kMedoids.h
OUT = medoids
CC = g++
FLAGS = -g -c
# -g option enables debugging mode
# -c flag generates object code for separate files
all: $(OBJS)
$(CC) -g $(OBJS) -o $(OUT)
# create/ compile the individual files >> separately <<

main.o: main.cpp $(HEADER)
$(CC) $(FLAGS) main.cpp

euclideanNode.o: euclideanNode.cpp euclideanNode.h
$(CC) $(FLAGS) euclideanNode.cpp

centroid.o: centroid.cpp centroid.h
$(CC) $(FLAGS) centroid.cpp

clusterNode.o: clusterNode.cpp clusterNode.h
$(CC) $(FLAGS) clusterNode.cpp

generalFunctions.o: generalFunctions.cpp generalFunctions.h
$(CC) $(FLAGS) generalFunctions.cpp

initialization.o: initialization.cpp initialization.h
$(CC) $(FLAGS) initialization.cpp

kMedoids.o: kMedoids.cpp kMedoids.h
$(CC) $(FLAGS) kMedoids.cpp

distancesCalculations.o: distancesCalculations.cpp distancesCalculations.h
$(CC) $(FLAGS) distancesCalculations.cpp

hashFunction.o: hashFunction.cpp hashFunction.h
$(CC) $(FLAGS) hashFunction.cpp

hashtable.o: hashtable.cpp hashtable.h
$(CC) $(FLAGS) hashtable.cpp

List.o: List.cpp List.h
$(CC) $(FLAGS) List.cpp

Node.o: Node.cpp Node.h
$(CC) $(FLAGS) Node.cpp

hashFunctionCosine.o: hashFunctionCosine.cpp hashFunctionCosine.h
$(CC) $(FLAGS) hashFunctionCosine.cpp

hashFunctionEuclidean.o: hashFunctionEuclidean.cpp hashFunctionEuclidean.h
$(CC) $(FLAGS) hashFunctionEuclidean.cpp

hashFunctionMatrix.o: hashFunctionMatrix.cpp hashFunctionMatrix.h
$(CC) $(FLAGS) hashFunctionMatrix.cpp

lsh.o: lsh.cpp lsh.h
$(CC) $(FLAGS) lsh.cpp

psedoRandomNumbers.o: psedoRandomNumbers.cpp psedoRandomNumbers.h
$(CC) $(FLAGS) psedoRandomNumbers.cpp

readFile.o: readFile.cpp readFile.h
$(CC) $(FLAGS) readFile.cpp

# clean house
clean :
rm -f $(OBJS) $(OUT)
Loading

0 comments on commit 09b0c3b

Please sign in to comment.