summaryrefslogtreecommitdiff
path: root/trunk/glagen/algo_distribue/Distribue.hh
diff options
context:
space:
mode:
authorhugues <hugues@0f7e0d06-a6f9-0310-a55f-d5f984f55e4c>2005-02-10 23:10:51 +0000
committerhugues <hugues@0f7e0d06-a6f9-0310-a55f-d5f984f55e4c>2005-02-10 23:10:51 +0000
commitc50bc6329ff6e336de47efa7b2275c77e85a75a1 (patch)
treeeca3a8af85bcf95047caa027aa01d9cfc47a0cff /trunk/glagen/algo_distribue/Distribue.hh
parent42d83a68fc1cd45019ddbebee041962d2a1783b9 (diff)
Initial revision
git-svn-id: file:///usr/local/opt/svn/repos/glagen@3 0f7e0d06-a6f9-0310-a55f-d5f984f55e4c
Diffstat (limited to 'trunk/glagen/algo_distribue/Distribue.hh')
-rw-r--r--trunk/glagen/algo_distribue/Distribue.hh97
1 files changed, 97 insertions, 0 deletions
diff --git a/trunk/glagen/algo_distribue/Distribue.hh b/trunk/glagen/algo_distribue/Distribue.hh
new file mode 100644
index 0000000..ff3b76d
--- /dev/null
+++ b/trunk/glagen/algo_distribue/Distribue.hh
@@ -0,0 +1,97 @@
+// Classe Distribue
+
+
+
+#ifndef DISTRIBUE_HH_
+# define DISTRIBUE_HH_
+
+#include "tree/tree.hh"
+#include "tree/node.hh"
+#include "network/data/Data.hh"
+#include "network/Server.hh"
+#include "tools/matrix.hh"
+
+template<class TYPENODE> class Distribue
+{
+public:
+ Distribue(const Tree<TYPENODE>& tree)
+ : _tree(tree),
+ _size(tree.get_node_root().get_number_node()),
+ _mat(new Matrix<int> (_size, _size))
+ {
+ unsigned int ptr1 = 0, ptr2 = 0;
+ std::list< Node<TYPENODE> > ptr_node = *new std::list< Node<TYPENODE> >;
+ ptr_node.push_back(tree.get_node_root());
+ while (ptr_node.size())
+ {
+ std::list< Node<TYPENODE> >::iterator childs = ptr_node.begin();
+ std::list< Node<TYPENODE> >::iterator child =
+ childs->get_childs()->begin();
+ for (; child != childs->get_childs()->end(); ++child)
+ {
+ ptr_node.push_back(*child);
+ (*_mat)(++ptr2, ptr1) = 1;
+ }
+ ptr_node.pop_front();
+ ptr1++;
+ }
+ }
+
+ void depend(std::list<TYPENODE>& data, const unsigned int& ptr)
+ {
+ data.push_back(_tree.get_node_root().get_node_course_width(ptr).get_data());
+ for (unsigned int i = 0; i < _size; ++i)
+ if ((*_mat)(i, ptr))
+ depend(data, i);
+ }
+
+ void transfer(Server& server)
+ {
+ // Calcul du nombre de client necessaire
+ unsigned int j = 0;
+ std::list< list<TYPENODE> > list_data =
+ *new std::list< list<TYPENODE> >;
+ std::list<TYPENODE> data = *new std::list<TYPENODE>;
+ for (unsigned int i = 1; i < _size; ++i)
+ {
+ if ((*_mat)(i, 0)) // Ne prend que les noeuds fils du noeud root
+ {
+ ++j;
+ this->depend(data, i);
+ list_data.push_back(data);
+ data = *new std::list<TYPENODE>;
+ }
+ }
+ if (server.get_nb_client() < j)
+ {
+ std::cout << "Need more client" << std::endl;
+ exit(-1);
+ }
+
+ std::list<int>::const_iterator fd_client =
+ server.get_list_fd()->begin();
+ data = *new std::list<TYPENODE>;
+ for (unsigned int i = 1; i < _size; ++i)
+ {
+ if ((*_mat)(i, 0)) // Ne prend que les noeuds fils du noeud root
+ {
+ ++j;
+ this->depend(data, i);
+ server.send_data(*fd_client++, Data<TYPENODE>(&data));
+ data = *new std::list<TYPENODE>;
+ }
+ }
+ }
+
+ Matrix<int>& get_matrix()
+ {
+ return (*_mat);
+ }
+
+private:
+ Tree<TYPENODE> _tree;
+ unsigned int _size;
+ Matrix<int> *_mat;
+};
+
+#endif // DISTRIBUTE_HH_