浏览代码

Modifications importantes : gggp_pond refondu et découpé en sous fonction (ajout d'un critère permetant l'accés à des parties non connexes), ajout de plusieurs fonctiond de modification du ratio de coupe, mise en place de politique de création de fichier txt pour visualisation, modifiation et correction de quelques fonctions mineures, refonte totale de la fonction d'affinage (ajout d'une fonction utilisant le critère de kernighan lin), ajout d'une fonction de tirage suivant poids maximum (non valide pour le moment) [beaucoup de commentaire à supprimer mais utile a la validation pour le moment]

totofeh 11 年之前
父节点
当前提交
2ce6f4355a

+ 41 - 8
src/tests/boost_graph/graph_builder.hpp

@@ -336,16 +336,18 @@ public:
 		/*
 		/*
 		 * *** Graphe créé différent du graphe obtenu dans graph_partitioning ! Solution ? *** 
 		 * *** Graphe créé différent du graphe obtenu dans graph_partitioning ! Solution ? *** 
 		 */
 		 */
-		 
+		
+        /*
+        const char *texte = new const char();
+        texte = "enregistrement.txt";
+        Graph_constructor_txt(texte, &graph);*/
         OrientedGraph graph;
         OrientedGraph graph;
-        unsigned int edge_number = 3000;
-        std::vector<int> levels;
-        levels.push_back(4);
-        levels.push_back(3);
-        levels.push_back(2);
-        unsigned int source_number = 5;
+        unsigned int edge_number = 6000;
+        std::vector<int> levels = {5, 4, 3, 2 };
+        
+        unsigned int source_number = edge_number/100*1;
         unsigned int min_neigh = 2;
         unsigned int min_neigh = 2;
-        unsigned int max_neigh = 4;
+        unsigned int max_neigh = 3;
 
 
         build_generator_graph(&graph,edge_number,source_number,min_neigh,max_neigh,levels);
         build_generator_graph(&graph,edge_number,source_number,min_neigh,max_neigh,levels);
         graphs.push_back(graph);
         graphs.push_back(graph);
@@ -353,6 +355,37 @@ public:
 
 
 };
 };
 
 
+class RandomLinkedFlatGraphBuilder
+{
+public:
+    RandomLinkedFlatGraphBuilder()
+    { }
+
+    void build(OrientedGraphs& graphs, InputEdgeList& ,
+               OutputEdgeList& ,
+               Connections& )
+    {
+		/*
+		 * *** Graphe créé différent du graphe obtenu dans graph_partitioning ! Solution ? *** 
+		 */
+		
+        /*
+        const char *texte = new const char();
+        texte = "enregistrement.txt";
+        Graph_constructor_txt(texte, &graph);*/
+        OrientedGraph graph;
+        unsigned int edge_number = 6000;
+        unsigned int levels = 60;
+        
+        unsigned int min_neigh = 2;
+        unsigned int max_neigh = 3;
+
+        build_generator_graph_linked(&graph,edge_number,levels,min_neigh,max_neigh);
+        graphs.push_back(graph);
+    }
+
+};
+
 
 
 } } } // namespace paradevs tests boost_graph
 } } } // namespace paradevs tests boost_graph
 
 

+ 29 - 1
src/tests/boost_graph/graph_generator.hpp

@@ -57,7 +57,10 @@ public:
 
 
     virtual void generate(OrientedGraph& go)
     virtual void generate(OrientedGraph& go)
     {
     {
-        build_generator_graph(&go, edge_number, source_number, min_neigh,
+        /*const char *texte = new const char();
+        texte = "enregistrement.txt";
+        Graph_constructor_txt(texte,&go);*/
+       build_generator_graph(&go, edge_number, source_number, min_neigh,
                               max_neigh, levels);
                               max_neigh, levels);
     }
     }
 
 
@@ -69,6 +72,30 @@ private:
     unsigned int max_neigh;
     unsigned int max_neigh;
 };
 };
 
 
+class RandomLinkedGraphGenerator : public GraphGenerator
+{
+public:
+    RandomLinkedGraphGenerator(unsigned int edge_number,
+                         unsigned int levels,
+                         unsigned int min_neigh,
+                         unsigned int max_neigh) :
+        edge_number(edge_number), levels(levels),
+        min_neigh(min_neigh), max_neigh(max_neigh)
+    { }
+
+    virtual void generate(OrientedGraph& go)
+    {
+       build_generator_graph_linked(&go, edge_number, levels , min_neigh,
+                              max_neigh);
+    }
+
+private:
+    unsigned int edge_number;
+    unsigned int levels;
+    unsigned int min_neigh;
+    unsigned int max_neigh;
+};
+
 class ArtificialGraphGenerator : public GraphGenerator
 class ArtificialGraphGenerator : public GraphGenerator
 {
 {
 public:
 public:
@@ -92,6 +119,7 @@ public:
     virtual void generate(OrientedGraph& go)
     virtual void generate(OrientedGraph& go)
     {
     {
         //build_corsen_graph(go);
         //build_corsen_graph(go);
+        
     }
     }
 };
 };
 
 

+ 4 - 4
src/tests/boost_graph/graph_partitioning.hpp

@@ -71,16 +71,16 @@ public:
                                  g, &graph_origin, &go,
                                  g, &graph_origin, &go,
                                  cluster_number,10, "HEM",
                                  cluster_number,10, "HEM",
                                  partitioning_method_name,
                                  partitioning_method_name,
-                                 "cut", "ratio", edge_partie ,
+                                 "diff", "ratio", edge_partie ,
                                  output_edges, input_edges,
                                  output_edges, input_edges,
-                                 parent_connections, Cut/*,3*/);
+                                 parent_connections,false, Cut, 2);
         } else {
         } else {
             graphs = Multiniveau(contraction_coef, g, &graph_origin, &go,
             graphs = Multiniveau(contraction_coef, g, &graph_origin, &go,
                                  cluster_number,10, "HEM",
                                  cluster_number,10, "HEM",
                                  partitioning_method_name,
                                  partitioning_method_name,
-                                 "cut", "ratio", edge_partie ,
+                                 "diff", "ratio", edge_partie ,
                                  output_edges, input_edges,
                                  output_edges, input_edges,
-                                 parent_connections, Cut/*,3*/);
+                                 parent_connections,false, Cut, 2);
         }
         }
 
 
         // std::cout << "*********************************" << std::endl;
         // std::cout << "*********************************" << std::endl;

+ 723 - 448
src/tests/boost_graph/partitioning/gggp.cpp

@@ -25,7 +25,7 @@
  */
  */
 
 
 #include <tests/boost_graph/partitioning/gggp.hpp>
 #include <tests/boost_graph/partitioning/gggp.hpp>
-
+#include <boost/timer.hpp>
 #include <algorithm>
 #include <algorithm>
 #include <iostream>
 #include <iostream>
 #include <fstream>
 #include <fstream>
@@ -39,31 +39,35 @@ extern OrientedGraph::vertex_iterator vertexIto, vertexEndo;
 extern OrientedGraph::adjacency_iterator neighbourIto, neighbourEndo;
 extern OrientedGraph::adjacency_iterator neighbourIto, neighbourEndo;
 
 
 void ggp(UnorientedGraph *g, Entiers *sommetsSource,
 void ggp(UnorientedGraph *g, Entiers *sommetsSource,
-               Entiers *sommetsDestination, EntiersEntiers &Partition, int rand, int distance)
+               Entiers *sommetsDestination, EntiersEntiers &Partition, int rand, int &index_partition, int distance)
 {
 {
-    //std::cout<<""<<std::endl;
-    //int val;
     Entiers sommets_adj;
     Entiers sommets_adj;
     if(sommetsSource->size()==1){
     if(sommetsSource->size()==1){
-        //val=0;
-        //std::cout<<"Entré dans le debug ! "<<std::endl;
         Entiers tailles;
         Entiers tailles;
         for(uint i=0;i<Partition.size();i++){
         for(uint i=0;i<Partition.size();i++){
             tailles.push_back(Partition.at(i)->size());
             tailles.push_back(Partition.at(i)->size());
         }
         }
         uint tmp=*max_element(tailles.begin(),tailles.end());
         uint tmp=*max_element(tailles.begin(),tailles.end());
         for(uint i=0; i<Partition.size();i++){
         for(uint i=0; i<Partition.size();i++){
-            if(Partition.at(i)->size()==tmp)
+            if(Partition.at(i)->size() == tmp)
             {
             {
-                ggp(g, Partition[i], sommetsDestination, Partition, rand_fini(0,Partition.at(i)->size()),
-					distance);
+				sommetsSource->clear();
+				for(int id = 0; id < Partition.at(i)->size();id++){
+					sommetsSource->push_back(Partition.at(i)->at(id));
+				}
+				index_partition = i;
+				if(distance != -1){
+					ggp(g, sommetsSource, sommetsDestination, Partition, Partition.at(i)->at(rand_fini(0,Partition.at(i)->size())), 
+						index_partition, distance);
+				}else{
+					ggp(g, sommetsSource, sommetsDestination, Partition, rand_fini(0,Partition.at(i)->size()),
+						index_partition, distance);
+				}
                 return;
                 return;
             }
             }
         }
         }
     }
     }
-   // else
-       // val=rand_fini(0,sommetsSource->size()-1);//Tirage aléatoire de l'indice du premier sommet entre 0 et taille du tableau -1
-        //std::cout<<"val : "<<sommetsSource->at(val)<<std::endl;
+    
     double poids_max=0;
     double poids_max=0;
     for(uint i=0;i<sommetsSource->size();i++){
     for(uint i=0;i<sommetsSource->size();i++){
         poids_max+=(*g)[sommetsSource->at(i)]._weight;
         poids_max+=(*g)[sommetsSource->at(i)]._weight;
@@ -83,44 +87,32 @@ void ggp(UnorientedGraph *g, Entiers *sommetsSource,
 	}
 	}
 	
 	
     int cpt = 0;
     int cpt = 0;
-   // std::cout<<"taille sommetsSource avant le while : "<<sommetsSource->size()<<std::endl;
     while(poids<poids_max && sommetsSource->size()>1)
     while(poids<poids_max && sommetsSource->size()>1)
     {
     {
-        //std::cout<<"taille sommetsSource dans le while "<<sommetsSource->size()<<std::endl;
-        if(cpt<sommetsDestination->size() )
+        if(cpt<sommetsDestination->size()){
             adjacence_ggp(sommetsDestination->at(cpt),sommets_adj,g);
             adjacence_ggp(sommetsDestination->at(cpt),sommets_adj,g);
-        else{
+		} else{
             int val=rand_fini(0,sommetsSource->size()-1);
             int val=rand_fini(0,sommetsSource->size()-1);
             sommetsDestination->push_back(sommetsSource->at(val));
             sommetsDestination->push_back(sommetsSource->at(val));
             sommetsSource->erase(sommetsSource->begin() + val);
             sommetsSource->erase(sommetsSource->begin() + val);
             adjacence_ggp(sommetsDestination->at(cpt),sommets_adj,g);
             adjacence_ggp(sommetsDestination->at(cpt),sommets_adj,g);
         }
         }
-        /*std::cout<<"adj :"<<std::endl;
-        for(uint a = 0; a<sommets_adj.size(); a++){
-            std::cout<<sommets_adj.at(a)<<std::endl;
-        }*/
-        if(sommets_adj.size()==0)
+        if(sommets_adj.size() == 0)
         {
         {
-            //std::cout<<"Je suis sorti car pas de voisin !!!! "<<std::endl;
-            /*for (uint i=0; i<sommetsSource->size();i++)
-            {
-                for (uint j=0; j<sommetsDestination->size();j++)
-                {
-                    remove_edge(sommetsSource->at(i),sommetsDestination->at(j),*g);
-                }
-            }*/
             sort(sommetsDestination->begin(), sommetsDestination->end());
             sort(sommetsDestination->begin(), sommetsDestination->end());
             return;
             return;
         }
         }
         else{
         else{
             for(uint i =0; i<sommets_adj.size(); i++){
             for(uint i =0; i<sommets_adj.size(); i++){
-                if(In_tab(*sommetsDestination,sommets_adj.at(i))!=1 && sommetsSource->size()!=1){
+                if(In_tab(*sommetsDestination,sommets_adj.at(i)) != 1 && sommetsSource->size()!=1){
                     sommetsDestination->push_back(sommets_adj.at(i));
                     sommetsDestination->push_back(sommets_adj.at(i));
                     poids+=(*g)[sommets_adj.at(i)]._weight;
                     poids+=(*g)[sommets_adj.at(i)]._weight;
                     suprim_val(*sommetsSource, sommets_adj[i]);
                     suprim_val(*sommetsSource, sommets_adj[i]);
                 }
                 }
-                if(poids>poids_max || sommetsSource->size()==1)
-                    break;
+                else if(poids>=poids_max || sommetsSource->size() == 1){
+					sort(sommetsDestination->begin(), sommetsDestination->end());
+					return;
+				}
             }
             }
 
 
             /*std::cout<<"Sommets_source :"<<std::endl;
             /*std::cout<<"Sommets_source :"<<std::endl;
@@ -133,50 +125,297 @@ void ggp(UnorientedGraph *g, Entiers *sommetsSource,
                 std::cout<<sommetsDestination->at(i)<<",";
                 std::cout<<sommetsDestination->at(i)<<",";
             }
             }
             std::cout<<std::endl;*/
             std::cout<<std::endl;*/
+        }
+        sommets_adj.clear();
+        cpt++;
+
+    }
+    
+    sort(sommetsDestination->begin(), sommetsDestination->end());
+}
+
+void Transfert_vertex_bissection(UnorientedGraph *g, Entiers *sommetsSource, Entiers *sommetsDestination, Entiers &sommets_adj, const std::string &name, double &poids, double &cut){
+	std::vector<double> sommets_cut;
+	sort(sommets_adj.begin(), sommets_adj.end());
+	for(uint i=0;i<sommets_adj.size();i++)
+	{
+		double tmp_cut = cut;
+		if(name == "cut"){
+			sommets_cut.push_back(modif_Cout_coupe(*sommetsDestination,sommets_adj.at(i),tmp_cut,g)); 
+		}else if(name == "ratio"){
+			//std::cout<<"adj : "<<(*g)[sommets_adj.at(i)]._index<<" cut = "<<Modif_ratio_cut(g, sommetsSource, sommetsDestination, sommets_adj.at(i), tmp_cut)<<std::endl;
+			sommets_cut.push_back(Modif_ratio_cut(g, sommetsSource, sommetsDestination, sommets_adj.at(i), tmp_cut));
+		}
+	}
+	
+	cut = *min_element(sommets_cut.begin(),sommets_cut.end());
+	//std::cout<<"*** Passage 3 cut ***** : "<<cut<<std::endl;
+	//std::cout<<"Meilleur voisin : "<<(*g)[sommets_adj.at(recherche_val_double(sommets_cut,*min_element(sommets_cut.begin(),sommets_cut.end())))]._index<<std::endl;
+	sommetsDestination->push_back(sommets_adj[recherche_val_double(sommets_cut,*min_element(sommets_cut.begin(),sommets_cut.end()))]);
+	//std::cout<<"*** Passage 3 cuta ***"<<std::endl;
+	poids+=(*g)[sommets_adj[recherche_val_double(sommets_cut,*min_element(sommets_cut.begin(),sommets_cut.end()))]]._weight;
+	//std::cout<<"*** Passage 3 cutb ***"<<std::endl;
+	suprim_val(*sommetsSource, sommets_adj[recherche_val_double(sommets_cut,*min_element(sommets_cut.begin(),sommets_cut.end()))]);
+	suprim_val(sommets_adj, sommets_adj[recherche_val_double(sommets_cut,*min_element(sommets_cut.begin(),sommets_cut.end()))]);
+	
+	//std::cout<<"*** Passage 3 fin ***"<<std::endl;
+	
+}
+
+void Tirage_transfert_vertex_bissection(UnorientedGraph *g, Entiers *sommetsSource, Entiers *sommetsDestination, const std::string &name, double &poids, double &cut){
+	double diff = -100.;
+	int tmp_tir;
+	while(diff != 0){
+		tmp_tir = sommetsSource->at(rand_fini(0,sommetsSource->size()));
+		diff = Diff_cut_ratio_bissection(g, sommetsSource, tmp_tir, name);
+	}
+	poids += (*g)[tmp_tir]._weight;
+	if(name == "cut"){
+		cut = modif_Cout_coupe(*sommetsDestination,tmp_tir,cut,g);
+	}else{
+		cut = Modif_ratio_cut(g, sommetsSource, sommetsDestination, tmp_tir, cut);
+	}
+	sommetsDestination->push_back(tmp_tir);
+	suprim_val(*sommetsSource,tmp_tir);
+}
 
 
-            if(poids>poids_max  || sommetsSource->size()==1){
-                /*for (uint i=0; i<sommetsSource->size();i++)
-                {
-                    for (uint j=0; j<sommetsDestination->size();j++)
-                    {
-                        remove_edge(sommetsSource->at(i),sommetsDestination->at(j),*g);
-                    }
-                }*/
-                sort(sommetsDestination->begin(), sommetsDestination->end());
+bool Best_transfert_vertex_bissection(UnorientedGraph *g, Entiers *sommetsSource, Entiers *sommetsDestination, Entiers &sommets_adj,
+									  const std::string &name, double &poids, double poids_max, double PC, int stop, int &cpt, double &cut){
+    Liste_Voisin(*sommetsDestination,sommets_adj,*g);
+    //sort(sommets_adj.begin(), sommets_adj.end());
+	if(sommets_adj.size() == 0 & cpt<stop & sommetsSource->size()>1)
+	{
+		cpt++;
+		//std::cout<<"*** Passage 1 ***"<<std::endl;
+		if(poids < (poids_max - poids_max*PC/100)){
+			//std::cout<<"*** Passage 1a ***"<<std::endl;
+			Tirage_transfert_vertex_bissection(g, sommetsSource, sommetsDestination, name, poids, cut);
+			if(poids < (poids_max - poids_max*PC/100) & sommetsSource->size()>1){
+				Best_transfert_vertex_bissection(g, sommetsSource, sommetsDestination, sommets_adj,
+												name, poids, poids_max, PC, stop, cpt, cut);	
+			}else{			
+				//std::cout<<"*** Passage 1ac ***"<<std::endl;
+				return true;
+			}			       
+		}else{	
+			//std::cout<<"*** Passage 1b ***"<<std::endl;
+			return true;
+		}
+		
+	}
+	else if (sommets_adj.size() == 0 & cpt>=stop){
+		//std::cout<<"*** Passage 2 ***"<<std::endl;
+		return true;
+	}else if (sommetsSource->size()==1){
+		//std::cout<<"*** Passage 4 ***"<<std::endl;
+		return true;
+	}else{
+		//std::cout<<"*** Passage 3 *** : "<<cut<<std::endl;
+		Transfert_vertex_bissection(g, sommetsSource, sommetsDestination, sommets_adj, name, poids, cut);
+		return false;
+	}
+}
+
+void gggp_pond(UnorientedGraph *g, Entiers *sommetsSource, Entiers *sommetsDestination,
+				EntiersEntiers &Partition, int rand, int &index_partition, const std::string &name, int distance)
+{
+	//std::cout<<"bissec"<<std::endl;
+    Entiers sommets_adj;
+    double poids_max = 0;
+    double poids, cut;
+    
+    if(sommetsSource->size()==1){
+		//std::cout<<"Changement de Partition"<<std::endl;
+        Entiers tailles;
+        for(uint i=0;i<Partition.size();i++){
+            tailles.push_back(Partition.at(i)->size());
+        }
+        uint tmp=*max_element(tailles.begin(),tailles.end());
+        for(int i=0; i<Partition.size();i++){
+            if(Partition.at(i)->size()==tmp)
+            {
+				sommetsSource->clear();
+				for(int id = 0; id < Partition.at(i)->size();id++){
+					sommetsSource->push_back(Partition.at(i)->at(id));
+				}
+				index_partition = i;
+				if(distance != -1){
+					gggp_pond(g,sommetsSource,sommetsDestination,Partition,
+							  Partition.at(i)->at(rand_fini(0,Partition.at(i)->size())),index_partition ,name, distance);
+				}else{
+					gggp_pond(g,sommetsSource,sommetsDestination,Partition,
+							  rand_fini(0,Partition.at(i)->size()),index_partition, name ,distance);
+				}
                 return;
                 return;
             }
             }
-
-            sommets_adj.clear();
-            cpt++;
         }
         }
+    }
 
 
+    for(uint i=0;i<sommetsSource->size();i++){
+        poids_max+=(*g)[sommetsSource->at(i)]._weight;
     }
     }
+    poids_max/=2.;
+    //std::cout<<"Poids total : "<<poids_max<<std::endl;
+   
+    if(distance == -1){
+		//std::cout<<"Sommet de départ : "<<(*g)[sommetsSource->at(rand)]._index<<std::endl;
+		poids=(*g)[sommetsSource->at(rand)]._weight;
+		if(name == "cut"){
+			cut = Degree(*g,sommetsSource->at(rand));
+		}else if(name == "ratio"){
+			cut = Degree(*g,sommetsSource->at(rand));
+			double tmp_cut = cut/2./(*g)[sommetsSource->at(rand)]._weight 
+				   + cut/2./(Cluster_Weight(*g,*sommetsSource)-(*g)[sommetsSource->at(rand)]._weight);
+			cut = tmp_cut;
+		}
+		sommetsDestination->push_back(sommetsSource->at(rand));
+		sommetsSource->erase(sommetsSource->begin() + rand);
+	}else{
+		//std::cout<<"Sommet de départ : "<<(*g)[rand]._index<<std::endl;
+		poids=(*g)[rand]._weight;
+		cut = Degree(*g,rand);
+		if(name == "ratio"){
+			double tmp_cut = cut/2./(*g)[rand]._weight + cut/2./(Cluster_Weight(*g,*sommetsSource)-(*g)[rand]._weight);
+			cut = tmp_cut;
+		}
+		sommetsDestination->push_back(rand);
+		suprim_val(*sommetsSource,rand);
+	}
 
 
-    /*for (uint i=0; i<sommetsSource->size();i++)
+    while(poids<poids_max && sommetsSource->size()>1)
     {
     {
-        for (uint j=0; j<sommetsDestination->size();j++)
-        {
-            remove_edge(sommetsSource->at(i),sommetsDestination->at(j),*g);
-        }
-    }*/
+		int cpt = 0;
+        bool next = Best_transfert_vertex_bissection(g, sommetsSource, sommetsDestination, sommets_adj,
+													name, poids, poids_max, 20, 2, cpt, cut);
+		if(next == true){
+			sort(sommetsDestination->begin(), sommetsDestination->end());
+			return;
+		}										
+    }
     sort(sommetsDestination->begin(), sommetsDestination->end());
     sort(sommetsDestination->begin(), sommetsDestination->end());
 }
 }
 
 
+/*Liste_Voisin(*sommetsDestination,sommets_adj,*g);
+if(sommets_adj.size()==0)
+{
+	std::cout<<"*** Passage ***"<<std::endl;
+	if(poids < (poids_max - poids_max*40/100)){
+		Tirage_transfert_vertex_bissection(g, sommetsSource, sommetsDestination, name, poids);
+		
+		Liste_Voisin(*sommetsDestination,sommets_adj,*g);
+		if(sommets_adj.size() != 0){
+			Transfert_vertex_bissection(g, sommetsSource, sommetsDestination, sommets_adj, name, poids);
+		}else{
+			sort(sommetsDestination->begin(), sommetsDestination->end());
+			return;
+		}
+	}else{
+		sort(sommetsDestination->begin(), sommetsDestination->end());
+		return;
+	}
+	
+}
+else{
+	Transfert_vertex_bissection(g, sommetsSource, sommetsDestination, sommets_adj, name, poids);
+}*/
+
 
 
 void Iter_2l(EntiersEntiers &part, int nbr_parties, UnorientedGraph *g,
 void Iter_2l(EntiersEntiers &part, int nbr_parties, UnorientedGraph *g,
              const std::string &nom_cut, int nbr_tirage, const std::string &nom_strat, int distance)
              const std::string &nom_cut, int nbr_tirage, const std::string &nom_strat, int distance)
 {
 {
-			
+	/*std::vector<std::string> color;
+	color.push_back("[color=blue2, fontcolor=blue2];");
+	color.push_back("[color=red, fontcolor=red];");
+	color.push_back("[color=green, fontcolor=green];");
+	color.push_back("[color=turquoise, fontcolor=turquoise];");
+	color.push_back("[color=saddlebrown, fontcolor=saddlebrown];");
+	color.push_back("[color=indigo, fontcolor=indigo];");
+	color.push_back("[color=yellow, fontcolor=yellow2];");
+	color.push_back("[color=orange, fontcolor=orange];");
+	color.push_back("[color=olivedrab, fontcolor=olivedrab];");
+	color.push_back("[color=gold, fontcolor=gold];");
+	color.push_back("[color=slateblue2, fontcolor=slateblue2];");
+	color.push_back("[color=dimgrey, fontcolor=dimgrey];");
+	color.push_back("[color=cyan, fontcolor=cyan];");
+	color.push_back("[color=purple1, fontcolor=purpule1];");
+	color.push_back("[color=crimson, fontcolor=crimson];");
+	color.push_back("[color=black, fontcolor=black];");*/
+	
+	UnorientedGraph copy_graph;
+	boost::copy_graph(*g,copy_graph);
+	
+	/*std::vector<char* > nom;
+	char * tmp_nom1 = new char();
+	tmp_nom1 = "../../sortie_graphe/Tests/Graphes/Evolution_bissection/bissection_1.txt";
+	nom.push_back(tmp_nom1);
+	char * tmp_nom2 = new char();
+	tmp_nom2 = "../../sortie_graphe/Tests/Graphes/Evolution_bissection/bissection_2.txt";
+	nom.push_back(tmp_nom2);
+	char * tmp_nom3 = new char();
+	tmp_nom3= "../../sortie_graphe/Tests/Graphes/Evolution_bissection/bissection_3.txt";
+	nom.push_back(tmp_nom3);
+	char * tmp_nom4 = new char();
+	tmp_nom4= "../../sortie_graphe/Tests/Graphes/Evolution_bissection/bissection_4.txt";
+	nom.push_back(tmp_nom4);
+	char * tmp_nom5 = new char();
+	tmp_nom5= "../../sortie_graphe/Tests/Graphes/Evolution_bissection/bissection_5.txt";
+	nom.push_back(tmp_nom5);	
+	char * tmp_nom6 = new char();
+	tmp_nom6= "../../sortie_graphe/Tests/Graphes/Evolution_bissection/bissection_6.txt";
+	nom.push_back(tmp_nom6);
+	char * tmp_nom7 = new char();
+	tmp_nom7= "../../sortie_graphe/Tests/Graphes/Evolution_bissection/bissection_7.txt";
+	nom.push_back(tmp_nom7);
+	char * tmp_nom8 = new char();
+	tmp_nom8= "../../sortie_graphe/Tests/Graphes/Evolution_bissection/bissection_8.txt";
+	nom.push_back(tmp_nom8);
+	char * tmp_nom9 = new char();
+	tmp_nom9= "../../sortie_graphe/Tests/Graphes/Evolution_bissection/bissection_9.txt";
+	nom.push_back(tmp_nom9);
+	char * tmp_nom10 = new char();
+	tmp_nom10= "../../sortie_graphe/Tests/Graphes/Evolution_bissection/bissection_10.txt";
+	nom.push_back(tmp_nom10);
+	int cpt = 0;*/
+	
 	for(int i = 0; i<floor(log(nbr_parties)/log(2)); i++)
 	for(int i = 0; i<floor(log(nbr_parties)/log(2)); i++)
     {
     {
 		for(int j = 0; j< pow(2,i);j++)
 		for(int j = 0; j< pow(2,i);j++)
         {
         {
 			if(distance == -1){
 			if(distance == -1){
-				Optimisation_method_neighbour(g,part,j,nbr_tirage, nom_cut, nom_strat);
+				if(nbr_tirage != 0){
+					Optimisation_method_neighbour(g,part,j,nbr_tirage, nom_cut, nom_strat);
+				}else{
+					Optimisation_method_neighbour_minweight(g,part,j, nom_cut, nom_strat);
+				}
 			}else{
 			}else{
 				Optimisation_method_neighbour_distance(g,part,j,nbr_tirage, distance, nom_cut, nom_strat);
 				Optimisation_method_neighbour_distance(g,part,j,nbr_tirage, distance, nom_cut, nom_strat);
 			}
 			}
 			
 			
+	    		/*std::ofstream GRAPH2 (nom.at(cpt), std::ios::out);
+				GRAPH2<<"graph G {"<<std::endl;   
+				tie(vertexIt, vertexEnd) = vertices(copy_graph);
+				for (; vertexIt != vertexEnd; ++vertexIt) {
+					GRAPH2<<(copy_graph)[*vertexIt]._index<<" -- {";
+					tie(neighbourIt, neighbourEnd) = adjacent_vertices(*vertexIt,
+	    			copy_graph);
+					for (; neighbourIt != neighbourEnd; ++neighbourIt){
+						if((copy_graph)[*neighbourIt]._index>(copy_graph)[*vertexIt]._index)
+							GRAPH2<<(copy_graph)[*neighbourIt]._index<<";";
+					}
+					GRAPH2<<"}"<<std::endl;
+				}   
+				
+				for(uint k=0; k<part.size(); k++){
+					for(uint t=0; t<part.at(k)->size(); t++)
+					{
+						GRAPH2<<(copy_graph)[part.at(k)->at(t)]._index<<color.at(k)<<std::endl;
+					}
+				}
+	    
+				GRAPH2<<"}";	
+				GRAPH2.close();
+				
+				cpt ++;*/
         }
         }
     }
     }
 }
 }
@@ -184,6 +423,7 @@ void Iter_2l(EntiersEntiers &part, int nbr_parties, UnorientedGraph *g,
 void bissectionRec(UnorientedGraph *g, EntiersEntiers &Partition,
 void bissectionRec(UnorientedGraph *g, EntiersEntiers &Partition,
                    int nbr_parties, const std::string &nom_cut, int nbr_tirage, const std::string &nom_strat, int distance)
                    int nbr_parties, const std::string &nom_cut, int nbr_tirage, const std::string &nom_strat, int distance)
 {
 {
+	
     if((nbr_parties&(nbr_parties-1))==0)
     if((nbr_parties&(nbr_parties-1))==0)
     {
     {
         //std::cout<<"C'est de la forme 2l : "<<nbr_parties<<std::endl;
         //std::cout<<"C'est de la forme 2l : "<<nbr_parties<<std::endl;
@@ -212,290 +452,27 @@ void bissectionRec(UnorientedGraph *g, EntiersEntiers &Partition,
         for(int j = 0; j<nbr_parties-pow(2,puissance_2-1);j++)
         for(int j = 0; j<nbr_parties-pow(2,puissance_2-1);j++)
         {
         {
 			if(distance == -1){
 			if(distance == -1){
-				Optimisation_method_neighbour(g,Partition,j,nbr_tirage, nom_cut, nom_strat);
+				if(nbr_tirage != 0){
+					Optimisation_method_neighbour(g,Partition,j,nbr_tirage, nom_cut, nom_strat);
+				}else{
+					Optimisation_method_neighbour_degree(g,Partition,j, nom_cut, nom_strat);
+				}
 			}else{
 			}else{
 				Optimisation_method_neighbour_distance(g,Partition,j,nbr_tirage, distance, nom_cut, nom_strat);
 				Optimisation_method_neighbour_distance(g,Partition,j,nbr_tirage, distance, nom_cut, nom_strat);
 			}
 			}
+			
+			/*for(int x =0; x<Partition.size(); x++){
+				std::cout<<"** ";
+				for(int y =0; y<Partition.at(x)->size();y++){
+					std::cout<<Partition.at(x)->at(y)<<" ";
+				}
+				std::cout<<std::endl;
+			}
+			std::cout<<std::endl;*/
         }
         }
     }
     }
 }
 }
 
 
-void gggp_pond(UnorientedGraph *g, Entiers *sommetsSource,
-               Entiers *sommetsDestination, EntiersEntiers &Partition, int rand, int distance)
-{
-    Entiers sommets_adj;
-    if(sommetsSource->size()==1){
-        Entiers tailles;
-        for(uint i=0;i<Partition.size();i++){
-            tailles.push_back(Partition.at(i)->size());
-        }
-        uint tmp=*max_element(tailles.begin(),tailles.end());
-        for(uint i=0; i<Partition.size();i++){
-            if(Partition.at(i)->size()==tmp)
-            {
-                gggp_pond(g,Partition[i],sommetsDestination,Partition,rand_fini(0,Partition.at(i)->size()),distance);
-                return;
-            }
-        }
-    }
-
-    double poids_max=0;
-    for(uint i=0;i<sommetsSource->size();i++){
-        poids_max+=(*g)[sommetsSource->at(i)]._weight;
-    }
-    poids_max/=2.;
-    double poids;
-    std::vector<float> sommets_cut;
-    float cut;
-    if(distance == -1){
-		poids=(*g)[sommetsSource->at(rand)]._weight;
-		cut = Degree(*g,sommetsSource->at(rand));
-		//std::cout<<"verif rand : "<<rand<<std::endl;
-		sommetsDestination->push_back(sommetsSource->at(rand));
-		sommetsSource->erase(sommetsSource->begin() + rand);
-		
-	}else{
-		poids=(*g)[rand]._weight;
-		cut = Degree(*g,rand);
-		sommetsDestination->push_back(rand);
-		suprim_val(*sommetsSource,rand);
-	}
-
-    while(poids<poids_max && sommetsSource->size()>1)
-    {
-        Liste_Voisin(*sommetsDestination,sommets_adj,*g);
-        if(sommets_adj.size()==0)
-        {
-            for (uint i=0; i<sommetsSource->size();i++)
-            {
-                for (uint j=0; j<sommetsDestination->size();j++)
-                {
-                    remove_edge(sommetsSource->at(i),sommetsDestination->at(j),*g);
-                }
-            }
-            sort(sommetsDestination->begin(), sommetsDestination->end());
-            return;
-        }
-        else{
-            sort(sommets_adj.begin(), sommets_adj.end());
-
-            for(uint i=0;i<sommets_adj.size();i++)
-            {
-                sommets_cut.push_back(modif_Cout_coupe(*sommetsDestination,sommets_adj.at(i),cut,g));
-            }
-
-            cut = *min_element(sommets_cut.begin(),sommets_cut.end());
-            sommetsDestination->push_back(sommets_adj[recherche_val2(sommets_cut,*min_element(sommets_cut.begin(),sommets_cut.end()))]);
-            poids+=(*g)[sommets_adj[recherche_val2(sommets_cut,*min_element(sommets_cut.begin(),sommets_cut.end()))]]._weight;
-            suprim_val(*sommetsSource, sommets_adj[recherche_val2(sommets_cut,*min_element(sommets_cut.begin(),sommets_cut.end()))]);
-            suprim_val(sommets_adj, sommets_adj[recherche_val2(sommets_cut,*min_element(sommets_cut.begin(),sommets_cut.end()))]);
-
-            sommets_cut.clear();
-
-        }
-    }
-    
-    sort(sommetsDestination->begin(), sommetsDestination->end());
-
-    /*for (uint i=0; i<sommetsSource->size();i++)
-    {
-        for (uint j=0; j<sommetsDestination->size();j++)
-        {
-            remove_edge(sommetsSource->at(i),sommetsDestination->at(j),*g);
-        }
-    }*/
-    
-}
-
-// void gggp_pond(UnorientedGraph *g, Entiers *sommetsSource,
-//                Entiers *sommetsDestination, EntiersEntiers &Partition)
-// {
-//     int val;
-//     Entiers sommets_adj;
-//     if(sommetsSource->size()==1){
-//         val=0;
-//         //std::cout<<"Entré dans le debug ! "<<std::endl;
-//         Entiers tailles;
-//         for(uint i=0;i<Partition.size();i++){
-//             tailles.push_back(Partition.at(i)->size());
-//         }
-//         uint tmp=*max_element(tailles.begin(),tailles.end());
-//         for(uint i=0; i<Partition.size();i++){
-//             if(Partition.at(i)->size()==tmp)
-//             {
-//                 gggp_pond(g,Partition[i],sommetsDestination,Partition);
-//             	return;
-//             }
-//         }
-//     }
-//     else
-//         val=rand_fini(0,sommetsSource->size()-1);//Tirage aléatoire de l'indice du premier sommet entre 0 et taille du tableau -1
-//     	//std::cout<<"val : "<<sommetsSource->at(val)<<std::endl;
-//     double poids_max=0;
-//     for(uint i=0;i<sommetsSource->size();i++){
-//         poids_max+=(*g)[sommetsSource->at(i)]._weight;
-//     }
-//     poids_max/=2.;
-//     double poids=(*g)[sommetsSource->at(val)]._weight;
-//     std::vector<float> sommets_cut;
-//     float  cut = Degree(*g,sommetsSource->at(val));
-
-//     sommetsDestination->push_back(sommetsSource->at(val));
-//     sommetsSource->erase(sommetsSource->begin() + val);
-
-//    // std::cout<<"taille sommetsSource avant le while : "<<sommetsSource->size()<<std::endl;
-//     while(poids<poids_max && sommetsSource->size()>1)
-//     {
-//     	//std::cout<<"taille sommetsSource dans le while "<<sommetsSource->size()<<std::endl;
-//         Liste_Voisin(*sommetsDestination,sommets_adj,*g);
-//         if(sommets_adj.size()==0)
-//         {
-//             //std::cout<<"Je suis sorti car pas de voisin !!!! "<<std::endl;
-//             for (uint i=0; i<sommetsSource->size();i++)
-//             {
-//                 for (uint j=0; j<sommetsDestination->size();j++)
-//                 {
-//                     remove_edge(sommetsSource->at(i),sommetsDestination->at(j),*g);
-//                 }
-//             }
-//             sort(sommetsDestination->begin(), sommetsDestination->end());
-//             return;
-//         }
-//         else{
-//             sort(sommets_adj.begin(), sommets_adj.end());
-
-//             /*std::cout<<"adj :"<<std::endl;
-//             for(uint a = 0; a<sommets_adj.size(); a++){
-//             	std::cout<<sommets_adj.at(a)<<std::endl;
-//             }
-//             std::cout<<std::endl;*/
-
-//             for(uint i=0;i<sommets_adj.size();i++)
-//             {
-//                 sommets_cut.push_back(modif_Cout_coupe(*sommetsDestination, sommets_adj.at(i), cut, g));
-//                 // sommets_cut.push_back(Cout_coupe_pond(*sommetsDestination,sommets_adj[i],*g));
-//             }
-//             /*std::cout<<"cut :"<<std::endl;
-//             for(uint a = 0; a<sommets_cut.size(); a++){
-//             	std::cout<<sommets_cut.at(a)<<std::endl;
-//             }
-//             std::cout<<std::endl;*/
-//             sommetsDestination->push_back(sommets_adj[recherche_val2(sommets_cut,*min_element(sommets_cut.begin(),sommets_cut.end()))]);
-//             //std::cout<<"Sommet deplacé : "<<sommets_adj[recherche_val2(sommets_cut,*min_element(sommets_cut.begin(),sommets_cut.end()))]<<std::endl;
-//             poids+=(*g)[sommets_adj[recherche_val2(sommets_cut,*min_element(sommets_cut.begin(),sommets_cut.end()))]]._weight;
-//             suprim_val(*sommetsSource, sommets_adj[recherche_val2(sommets_cut,*min_element(sommets_cut.begin(),sommets_cut.end()))]);
-//             suprim_val(sommets_adj, sommets_adj[recherche_val2(sommets_cut,*min_element(sommets_cut.begin(),sommets_cut.end()))]);
-
-//             sommets_cut.clear();
-
-//         }
-
-//         /*for(uint i =0; i<sommetsSource->size();i++){
-//         	std::cout<<sommetsSource->at(i)<<",";
-//         }
-//         std::cout<<std::endl;
-//         for(uint i =0; i<sommetsDestination->size();i++){
-//         	std::cout<<sommetsDestination->at(i)<<",";
-//         }
-//         std::cout<<std::endl;*/
-
-//     }
-
-//     for (uint i=0; i<sommetsSource->size();i++)
-//     {
-//         for (uint j=0; j<sommetsDestination->size();j++)
-//         {
-//             remove_edge(sommetsSource->at(i),sommetsDestination->at(j),*g);
-//         }
-//     }
-//     sort(sommetsDestination->begin(), sommetsDestination->end());
-
-//     //std::cout<<"fin du gggp_pond"<<std::endl;
-// }
-
-// void Iter_2l(EntiersEntiers &part, int nbr_parties, UnorientedGraph *g,
-//              const std::string &nom)
-// {
-//     if (nom!="gggp_pond"){
-//         //std::cout<<"je jsuis dans gggp"<<std::endl;
-
-//         for(int i = 0; i<floor(log(nbr_parties)/log(2)); i++)
-//         {
-//             //std::cout<<"Et un tours de plus !!!! "<<std::endl;
-//             for(int j = 0; j< pow(2,i);j++)
-//             {
-//                 Entiers *Q = new Entiers();
-//                 gggp(g,part[j],Q,part);
-//                 part.push_back(Q);
-//             }
-
-//         }
-//     } else {
-//         //std::cout<<"je jsuis dans gggp_pond"<<std::endl;
-
-//         for(int i = 0; i<floor(log(nbr_parties)/log(2)); i++)
-//         {
-//             //std::cout<<"Et un tours de plus !!!! "<<std::endl;
-//             for(int j = 0; j< pow(2,i);j++)
-//             {
-//                 Entiers *Q = new Entiers();
-//                 gggp_pond(g,part.at(j),Q,part);
-//                 //std::clog<<"sortie du gggp_pond"<<std::endl;
-//                 part.push_back(Q);
-//             }
-//             //std::cout<<"\n"<<std::endl;
-
-//         }
-//     }
-// }
-
-// void bissectionRec(UnorientedGraph *g, EntiersEntiers &Partition,
-//                    int nbr_parties, const std::string &nom)
-// {
-//     if((nbr_parties&(nbr_parties-1))==0)
-//     {
-//         //std::cout<<"C'est de la forme 2l : "<<nbr_parties<<std::endl;
-//         Iter_2l(Partition,nbr_parties,g,nom);
-//     }
-//     else
-//     {
-//         int puissance_2=0;
-
-//         Entiers tailles;
-
-//         while(pow(2,puissance_2)<nbr_parties)
-//             puissance_2++;
-
-//         Iter_2l(Partition,pow(2,puissance_2-1),g,nom);
-
-//         for(unsigned int i = 0; i< Partition.size() -1 ; i++)
-//         {
-//             for(EntiersEntiers::iterator it1 = Partition.begin() + i ; it1!=Partition.end(); it1++)
-//             {
-//                 if((*it1)->size() > Partition.at(i)->size())
-//                     Partition.at(i)->swap(**it1);
-//             }
-//         }
-
-//         for(int j = 0; j<nbr_parties-pow(2,puissance_2-1);j++)
-//         {
-//             Entiers *Q = new Entiers();
-//             if(nom!="gggp_pond")
-//                 gggp(g,Partition.at(j),Q,Partition);
-//             else
-//                 gggp_pond(g,Partition.at(j),Q,Partition);
-//             Partition.push_back(Q);
-//         }
-//     }
-//     // std::cout<<"Partition avant affinage "<<std::endl;
-//     // for(uint i = 0 ; i<Partition.size(); i++){
-//     // 	for(uint j = 0 ; j<Partition.at(i)->size(); j++){
-//     // 		std::cout<<Partition.at(i)->at(j)<<" ";
-//     // 	}
-//     // 	std::cout<<"\n"<<std::endl;
-//     // }
-// }
-
 /**
 /**
  * Fonction réalisant un partitionnement pseudo aléatoire suivant un voisinage.
  * Fonction réalisant un partitionnement pseudo aléatoire suivant un voisinage.
  * @param *g : adresse d'un graphe de type boost graphe undirected
  * @param *g : adresse d'un graphe de type boost graphe undirected
@@ -646,9 +623,31 @@ OrientedGraphs Multiniveau(uint niveau_contraction,
                            Edges& /* edge_partie */,
                            Edges& /* edge_partie */,
                            OutputEdgeList& outputedgelist,
                            OutputEdgeList& outputedgelist,
                            InputEdgeList& inputedgelist,
                            InputEdgeList& inputedgelist,
-                           Connections& connections,
+                           Connections& connections, bool rec,
                            std::vector<double> &Cut, int distance)
                            std::vector<double> &Cut, int distance)
 {
 {
+	std::vector<std::string> color;
+	if(rec == true){
+		color.push_back("[color=blue2, fontcolor=blue2];");
+		color.push_back("[color=red, fontcolor=red];");
+		color.push_back("[color=green, fontcolor=green];");
+		color.push_back("[color=yellow, fontcolor=yellow2];");
+		color.push_back("[color=saddlebrown, fontcolor=saddlebrown];");
+		color.push_back("[color=turquoise, fontcolor=turquoise];");
+		color.push_back("[color=orange, fontcolor=orange];");
+		color.push_back("[color=olivedrab, fontcolor=olivedrab];");
+		color.push_back("[color=indigo, fontcolor=indigo];");
+		color.push_back("[color=gold, fontcolor=gold];");
+		color.push_back("[color=slateblue2, fontcolor=slateblue2];");
+		color.push_back("[color=dimgrey, fontcolor=dimgrey];");
+		color.push_back("[color=cyan, fontcolor=cyan];");
+		color.push_back("[color=purple1, fontcolor=purpule1];");
+		color.push_back("[color=crimson, fontcolor=crimson];");
+		color.push_back("[color=black, fontcolor=black];");
+    }
+    
+    boost::timer t; 
+    
     EntiersEntiers Partition;
     EntiersEntiers Partition;
     Entiers *part = new Entiers();
     Entiers *part = new Entiers();
     Base_Graph baseg;
     Base_Graph baseg;
@@ -672,6 +671,21 @@ OrientedGraphs Multiniveau(uint niveau_contraction,
         cpt++;
         cpt++;
     }
     }
     
     
+    if(rec == true){
+		std::ofstream GRAPHp ("../../sortie_graphe/Tests/Graphes/Evolution_bissection/poids_graphe.txt", std::ios::out);
+		GRAPHp<<"Poids du graphe contracté : "<<std::endl;   
+		tie(vertexIt, vertexEnd) = vertices(*baseg.at(baseg.size()-1));
+		for (; vertexIt != vertexEnd; ++vertexIt) {
+			GRAPHp<<(*baseg.at(baseg.size()-1))[*vertexIt]._index<<" --> "<<(*baseg.at(baseg.size()-1))[*vertexIt]._weight<<std::endl;;
+		}   
+		
+		GRAPHp<<"}";	
+		GRAPHp.close();
+	}
+
+    double t2 = t.elapsed();
+    std::cout << "Contraction duration : " << t2 << " seconds" << std::endl;
+    
     for(int i = 0; i<num_vertices(*baseg.at(baseg.size() - 1)); i++){
     for(int i = 0; i<num_vertices(*baseg.at(baseg.size() - 1)); i++){
 		part->push_back(i);
 		part->push_back(i);
 	}
 	}
@@ -679,33 +693,75 @@ OrientedGraphs Multiniveau(uint niveau_contraction,
 	
 	
 	UnorientedGraph copy_graph;
 	UnorientedGraph copy_graph;
 	boost::copy_graph(*baseg.at(baseg.size()-1),copy_graph);
 	boost::copy_graph(*baseg.at(baseg.size()-1),copy_graph);
-    // std::cout<<"Graphe contracté : "<<std::endl;
-    // for (uint i = 0; i< baseg.size(); i++) {
-    //     tie(vertexIt, vertexEnd) = vertices(*baseg[i]);
-    //     for (; vertexIt != vertexEnd; ++vertexIt) {
-    //         std::cout << (*baseg[i])[*vertexIt]._index
-    //                   << " est connecté avec ";
-    //         tie(neighbourIt, neighbourEnd) = adjacent_vertices(*vertexIt,
-    //         		*baseg[i]);
-    //         for (; neighbourIt != neighbourEnd; ++neighbourIt)
-    //             std::cout << (*baseg[i])[*neighbourIt]._index << " ";
-    //         std::cout << " et son poids est de "
-    //                   << (*baseg[i])[*vertexIt]._weight<<std::endl;
-    //     }
-    //     std::cout << std::endl;
-    // }
+	
+	if(rec == true){
+		std::ofstream GRAPH ("../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/contraction_final.txt", std::ios::out);
+		GRAPH<<"graph G {"<<std::endl;   
+		tie(vertexIt, vertexEnd) = vertices(*baseg.at(baseg.size()-1));
+		for (; vertexIt != vertexEnd; ++vertexIt) {
+			GRAPH<<(*baseg.at(baseg.size()-1))[*vertexIt]._index<<" -- {";
+			tie(neighbourIt, neighbourEnd) = adjacent_vertices(*vertexIt,
+					*baseg.at(baseg.size()-1));
+			for (; neighbourIt != neighbourEnd; ++neighbourIt){
+				if((*baseg.at(baseg.size()-1))[*neighbourIt]._index>(*baseg.at(baseg.size()-1))[*vertexIt]._index)
+					GRAPH<<(*baseg.at(baseg.size()-1))[*neighbourIt]._index<<";";
+			}
+			GRAPH<<"}"<<std::endl;
+		}   
+		
+		GRAPH<<"}";	
+		GRAPH.close();
+	}
     
     
     if(type_methode == "gggp" || type_methode == "ggp"){
     if(type_methode == "gggp" || type_methode == "ggp"){
 		bissectionRec(baseg.at(baseg.size()-1),Partition,nbr_parties,type_cut,nbr_tirage,type_methode, distance);
 		bissectionRec(baseg.at(baseg.size()-1),Partition,nbr_parties,type_cut,nbr_tirage,type_methode, distance);
-		double best_cut = Cut_cluster(Partition,copy_graph,type_cut);
-		Cut.push_back(best_cut);
-		//std::cout<<"Meilleur coût de coupe : "<<best_cut<<std::endl;
-		//std::cout<<std::endl;
+		double tcut = Cut_cluster(Partition,copy_graph,type_cut);
+		/*std::cout<<tcut<<std::endl;
+		std::cout<<"Meilleur coût de coupe : "<<best_cut<<std::endl;
+		std::cout<<std::endl;*/
     }
     }
     else
     else
     	Partition = Random_partitioning(baseg.at(baseg.size()-1),nbr_parties);
     	Partition = Random_partitioning(baseg.at(baseg.size()-1),nbr_parties);
-    // std::cout<<std::endl;
-
+    
+    double t3 = t.elapsed();
+    std::cout << "Partitioning duration : " << (t3 - t2) << " seconds" << std::endl;
+    
+    if(rec == true){
+		std::ofstream GRAPH3 ("../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/contraction_final_partition.txt", std::ios::out);
+		GRAPH3<<"graph G {"<<std::endl;   
+		tie(vertexIt, vertexEnd) = vertices(copy_graph);
+		for (; vertexIt != vertexEnd; ++vertexIt) {
+			GRAPH3<<(copy_graph)[*vertexIt]._index<<" -- {";
+			tie(neighbourIt, neighbourEnd) = adjacent_vertices(*vertexIt,
+			copy_graph);
+			for (; neighbourIt != neighbourEnd; ++neighbourIt){
+				if((copy_graph)[*neighbourIt]._index>(copy_graph)[*vertexIt]._index)
+				GRAPH3<<(copy_graph)[*neighbourIt]._index<<";";
+			}
+			GRAPH3<<"}"<<std::endl;
+		}   
+		
+		for(uint k=0; k<Partition.size(); k++){
+			for(uint j=0; j<Partition.at(k)->size(); j++)
+			{
+	     		GRAPH3<<(copy_graph)[Partition.at(k)->at(j)]._index<<color.at(k)<<std::endl;
+			}
+	    }
+	
+		GRAPH3<<"}";	
+		GRAPH3.close();
+	}
+			
+	double poids_moy = 0.;
+	for(uint i =0; i < Partition.size(); i++){
+		poids_moy += Cluster_Weight(copy_graph,*Partition.at(i));
+	}
+	poids_moy/=Partition.size();
+	
+	poids_moy = -1;
+	
+	/*poids_moy = -1 implique un respect du poids faible*/
+	
     ListEntiersEntiers::iterator lit(liste_corr.end());
     ListEntiersEntiers::iterator lit(liste_corr.end());
     bool proj;
     bool proj;
     uint taille_list = liste_corr.size();
     uint taille_list = liste_corr.size();
@@ -718,89 +774,224 @@ OrientedGraphs Multiniveau(uint niveau_contraction,
     	proj = false;
     	proj = false;
     }
     }
 
 
+	//std::cout<<"Nombre de contraction : "<<taille_list<<std::endl;
+	std::vector<char* > nom;
+	std::vector<char* > nom_a;
+	if(rec == true){
+		char * tmp_nom1 = new char();
+		tmp_nom1 = "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_1.txt";
+		nom.push_back(tmp_nom1);
+		char * tmp_nom_a1 = new char();
+		tmp_nom_a1 = "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_affine_1.txt";
+		nom_a.push_back(tmp_nom_a1);
+		char * tmp_nom2 = new char();
+		tmp_nom2 = "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_2.txt";
+		nom.push_back(tmp_nom2);
+		char * tmp_nom_a2 = new char();
+		tmp_nom_a2 = "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_affine_2.txt";
+		nom_a.push_back(tmp_nom_a2);
+		char * tmp_nom3 = new char();
+		tmp_nom3= "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_3.txt";
+		nom.push_back(tmp_nom3);
+		char * tmp_nom_a3 = new char();
+		tmp_nom_a3 = "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_affine_3.txt";
+		nom_a.push_back(tmp_nom_a3);
+		char * tmp_nom4 = new char();
+		tmp_nom4= "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_4.txt";
+		nom.push_back(tmp_nom4);
+		char * tmp_nom_a4 = new char();
+		tmp_nom_a4 = "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_affine_4.txt";
+		nom_a.push_back(tmp_nom_a4);
+		char * tmp_nom5 = new char();
+		tmp_nom5= "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_5.txt";
+		nom.push_back(tmp_nom5);
+		char * tmp_nom_a5 = new char();
+		tmp_nom_a5 = "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_affine_5.txt";
+		nom_a.push_back(tmp_nom_a5);
+		char * tmp_nom6 = new char();
+		tmp_nom6= "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_6.txt";
+		nom.push_back(tmp_nom6);
+		char * tmp_nom_a6 = new char();
+		tmp_nom_a6 = "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_affine_6.txt";
+		nom_a.push_back(tmp_nom_a6);
+		char * tmp_nom7 = new char();
+		tmp_nom7= "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_7.txt";
+		nom.push_back(tmp_nom7);
+		char * tmp_nom_a7 = new char();
+		tmp_nom_a7 = "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_affine_7.txt";
+		nom_a.push_back(tmp_nom_a7);
+		char * tmp_nom8 = new char();
+		tmp_nom8= "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_8.txt";
+		nom.push_back(tmp_nom8);
+		char * tmp_nom_a8 = new char();
+		tmp_nom_a8 = "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_affine_8.txt";
+		nom_a.push_back(tmp_nom_a8);
+		char * tmp_nom9 = new char();
+		tmp_nom9= "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_9.txt";
+		nom.push_back(tmp_nom9);
+		char * tmp_nom_a9 = new char();
+		tmp_nom_a9 = "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_affine_9.txt";
+		nom_a.push_back(tmp_nom_a9);
+		char * tmp_nom10 = new char();
+		tmp_nom10= "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_10.txt";
+		nom.push_back(tmp_nom10);
+		char * tmp_nom_a10 = new char();
+		tmp_nom_a10 = "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_affine_10.txt";
+		nom_a.push_back(tmp_nom_a10);
+		char * tmp_nom11 = new char();
+		tmp_nom11= "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_11.txt";
+		nom.push_back(tmp_nom11);
+		char * tmp_nom_a11 = new char();
+		tmp_nom_a11 = "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_affine_11.txt";
+		nom_a.push_back(tmp_nom_a11);
+		char * tmp_nom12 = new char();
+		tmp_nom12= "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_12.txt";
+		nom.push_back(tmp_nom12);
+		char * tmp_nom_a12 = new char();
+		tmp_nom_a12 = "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_affine_12.txt";
+		nom_a.push_back(tmp_nom_a12);
+		char * tmp_nom13 = new char();
+		tmp_nom13= "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_13.txt";
+		nom.push_back(tmp_nom13);
+		char * tmp_nom_a13 = new char();
+		tmp_nom_a13 = "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_affine_13.txt";
+		nom_a.push_back(tmp_nom_a13);
+		char * tmp_nom14 = new char();
+		tmp_nom14= "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_14.txt";
+		nom.push_back(tmp_nom14);
+		char * tmp_nom_a14 = new char();
+		tmp_nom_a14 = "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_affine_14.txt";
+		nom_a.push_back(tmp_nom_a14);
+		char * tmp_nom15 = new char();
+		tmp_nom15= "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_15.txt";
+		nom.push_back(tmp_nom15);
+		char * tmp_nom_a15 = new char();
+		tmp_nom_a15 = "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_affine_15.txt";
+		nom_a.push_back(tmp_nom_a15);
+		char * tmp_nom16 = new char();
+		tmp_nom16= "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_16.txt";
+		nom.push_back(tmp_nom16);
+		char * tmp_nom_a16 = new char();
+		tmp_nom_a16 = "../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/projection_partition_affine_16.txt";
+		nom_a.push_back(tmp_nom_a16);
+	}
     for(uint y =0; y<taille_list;y++){
     for(uint y =0; y<taille_list;y++){
     	if(proj != true){
     	if(proj != true){
-    		// std::cout<<"Projection "<<std::endl;
     		projection(Partition,lit);
     		projection(Partition,lit);
-    		// std::cout<<std::endl;
+    		
+    		if(rec == true){
+	    		std::ofstream GRAPH2 (nom.at(y), std::ios::out);
+				GRAPH2<<"graph G {"<<std::endl;   
+				tie(vertexIt, vertexEnd) = vertices(*baseg.at(baseg.size()-2-y));
+				for (; vertexIt != vertexEnd; ++vertexIt) {
+					GRAPH2<<(*baseg.at(baseg.size()-2-y))[*vertexIt]._index<<" -- {";
+					tie(neighbourIt, neighbourEnd) = adjacent_vertices(*vertexIt,
+	    			*baseg.at(baseg.size()-2-y));
+					for (; neighbourIt != neighbourEnd; ++neighbourIt){
+						if((*baseg.at(baseg.size()-2-y))[*neighbourIt]._index>(*baseg.at(baseg.size()-2-y))[*vertexIt]._index)
+							GRAPH2<<(*baseg.at(baseg.size()-2-y))[*neighbourIt]._index<<";";
+					}
+					GRAPH2<<"}"<<std::endl;
+				}   
+				
+				for(uint k=0; k<Partition.size(); k++){
+					for(uint j=0; j<Partition.at(k)->size(); j++)
+					{
+						GRAPH2<<(*baseg.at(baseg.size()-2-y))[Partition.at(k)->at(j)]._index<<color.at(k)<<std::endl;
+					}
+				}
+	    
+				GRAPH2<<"}";	
+				GRAPH2.close();
+			}
+
     		double cut = Cut_cluster(Partition,*baseg.at(baseg.size()-2-y),type_cut);
     		double cut = Cut_cluster(Partition,*baseg.at(baseg.size()-2-y),type_cut);
     		//std::cout<<"Cout de coupe avant affinage : "<<cut<<std::endl;
     		//std::cout<<"Cout de coupe avant affinage : "<<cut<<std::endl;
-    		//std::cout<<std::endl;
-    		//std::cout<<"Affinage "<<std::endl;
-    		if(choix_affinage=="charge")
+    		if(choix_affinage == "charge")
     			Affinage_equilibrage_charge(baseg.at(baseg.size()-2-y),Partition);
     			Affinage_equilibrage_charge(baseg.at(baseg.size()-2-y),Partition);
-    		else
-    			Affinage_recherche_locale(baseg.at(baseg.size()-2-y),Partition,cut,type_cut);
-
+    		else if(choix_affinage == "locale"){
+    			Affinage_recherche_locale(baseg.at(baseg.size()-2-y),Partition,cut,type_cut);}
+    		else	
+    			Affinache_gain_diff(baseg.at(baseg.size()-2-y), Partition, cut, type_cut, poids_moy);
+			//std::cout<<"Cout de coupe après affinage : "<<cut<<std::endl;
+			
+			if(rec == true){
+	    		std::ofstream GRAPH4 (nom_a.at(y), std::ios::out);
+				GRAPH4<<"graph G {"<<std::endl;   
+				tie(vertexIt, vertexEnd) = vertices(*baseg.at(baseg.size()-2-y));
+				for (; vertexIt != vertexEnd; ++vertexIt) {
+					GRAPH4<<(*baseg.at(baseg.size()-2-y))[*vertexIt]._index<<" -- {";
+					tie(neighbourIt, neighbourEnd) = adjacent_vertices(*vertexIt,
+	    			*baseg.at(baseg.size()-2-y));
+					for (; neighbourIt != neighbourEnd; ++neighbourIt){
+						if((*baseg.at(baseg.size()-2-y))[*neighbourIt]._index>(*baseg.at(baseg.size()-2-y))[*vertexIt]._index)
+							GRAPH4<<(*baseg.at(baseg.size()-2-y))[*neighbourIt]._index<<";";
+					}
+					GRAPH4<<"}"<<std::endl;
+				}   
+				
+				for(uint k=0; k<Partition.size(); k++){
+					for(uint j=0; j<Partition.at(k)->size(); j++)
+					{
+						GRAPH4<<(*baseg.at(baseg.size()-2-y))[Partition.at(k)->at(j)]._index<<color.at(k)<<std::endl;
+					}
+				}
+	    
+				GRAPH4<<"}";	
+				GRAPH4.close();
+			}
+			
     		lit--;
     		lit--;
     	}
     	}
     	else{
     	else{
     		//std::cout<<"Pas de projection "<<std::endl;
     		//std::cout<<"Pas de projection "<<std::endl;
-    		// std::cout<<std::endl;
-
-    		/*if(nbr_parties != num_vertices(*g)){
-    			// std::cout<<"Affinage "<<std::endl;
-        		double cut = Cut_cluster(Partition,*graph_origin,type_cut);
-        		std::cout<<"Cout de coupe avant affinage : "<<cut<<std::endl;
-    			if(choix_affinage=="charge")
-    				Affinage_equilibrage_charge(graph_origin,Partition);
-    			else{
-    				Affinage_recherche_locale(graph_origin,Partition,cut,type_cut);
-    				std::cout<<"Cout de coupe après affinage : "<<cut<<std::endl;
-    			}
-    		}*/
-    		// else
-    			// std::cout<<"Pas d'affinage "<<std::endl;
     	}
     	}
 
 
     }
     }
-
-    OrientedGraphs Graphes = Graph_Partition(Partition, go, graph_origin, outputedgelist,
-                                             inputedgelist, connections);
-	std::vector<std::string> color;
-    color.push_back("[color=blue2, fontcolor=blue2];");
-    color.push_back("[color=red, fontcolor=red];");
-    color.push_back("[color=green, fontcolor=green];");
-    color.push_back("[color=yellow, fontcolor=yellow2];");
-    color.push_back("[color=saddlebrown, fontcolor=saddlebrown];");
-    color.push_back("[color=turquoise, fontcolor=turquoise];");
-    color.push_back("[color=orange, fontcolor=orange];");
-    color.push_back("[color=olivedrab, fontcolor=olivedrab];");
-    color.push_back("[color=indigo, fontcolor=indigo];");
-    color.push_back("[color=gold, fontcolor=gold];");
-    color.push_back("[color=slateblue2, fontcolor=slateblue2];");
-    color.push_back("[color=dimgrey, fontcolor=dimgrey];");
-    color.push_back("[color=cyan, fontcolor=cyan];");
-    color.push_back("[color=purple1, fontcolor=purpule1];");
-    color.push_back("[color=crimson, fontcolor=crimson];");
-    color.push_back("[color=black, fontcolor=black];");
     
     
-   /*std::ofstream fichier2 ("../../sortie_graphe/graph_partition_38_4_1.txt", std::ios::out);
-   fichier2<<"digraph G {"<<std::endl;   
-   tie(vertexIto, vertexEndo) = vertices(*go);
-   for (; vertexIto != vertexEndo; ++vertexIto) {
-	fichier2<<(*go)[*vertexIto]._index<<"-> {";
-    	tie(neighbourIto, neighbourEndo) = adjacent_vertices(*vertexIto,
-    			*go);
-    	for (; neighbourIto != neighbourEndo; ++neighbourIto){
-    		fichier2<<(*go)[*neighbourIto]._index<<";";
-    	}
-    	fichier2<<"}"<<std::endl;
-    }
+    double t4 = t.elapsed();
+    std::cout << "Affinage duration : " << (t4 - t3) << " seconds" << std::endl;
     
     
-    for(uint k=0; k<Partition.size(); k++){
-		for(uint j=0; j<Partition.at(k)->size(); j++)
-		{
-     		fichier2<<Partition.at(k)->at(j)<<color.at(k)<<std::endl;
+    /*std::cout<<"Partition : "<<std::endl;
+	for(int x =0; x<Partition.size(); x++){
+		std::cout<<"*"<<x<<"* ";
+		for(int y =0; y<Partition.at(x)->size();y++){
+			std::cout<<Partition.at(x)->at(y)<<" ";
 		}
 		}
-    }   
-    
-	fichier2<<"}";	
-	fichier2.close();*/
-
-	//double cut = Cut_cluster(Partition,*graph_origin,"cut");
-	// std::cout<<"Cout de coupe engendré par le partitionnement: "<<cut<<std::endl;
+		std::cout<<std::endl;
+	}
+	std::cout<<std::endl;*/
+			
+	double best_cut = Cut_cluster(Partition,*graph_origin,type_cut);
+	Cut.push_back(best_cut);
 
 
+    OrientedGraphs Graphes = Graph_Partition(Partition, go, graph_origin, outputedgelist,
+                                             inputedgelist, connections);
+	
+	if(rec == true){
+	    std::ofstream fichier2 ("../../sortie_graphe/Tests/Graphes/txt/Niveau_contraction/résultat_partitionnement.txt", std::ios::out);
+	    fichier2<<"digraph G {"<<std::endl;   
+	    tie(vertexIto, vertexEndo) = vertices(*go);
+	    for (; vertexIto != vertexEndo; ++vertexIto) {
+			fichier2<<(*go)[*vertexIto]._index<<"-> {";
+	    	tie(neighbourIto, neighbourEndo) = adjacent_vertices(*vertexIto,
+	    			*go);
+	    	for (; neighbourIto != neighbourEndo; ++neighbourIto){
+	    		fichier2<<(*go)[*neighbourIto]._index<<";";
+	    	}
+	    	fichier2<<"}"<<std::endl;
+		}
+	    
+	    for(uint k=0; k<Partition.size(); k++){
+			for(uint j=0; j<Partition.at(k)->size(); j++)
+			{
+	     		fichier2<<Partition.at(k)->at(j)<<color.at(k)<<std::endl;
+			}
+	    }   
+	    
+		fichier2<<"}";	
+		fichier2.close();
+	}
 
 
     for(EntiersEntiers::iterator it = Partition.begin(); it != Partition.end(); it++)
     for(EntiersEntiers::iterator it = Partition.begin(); it != Partition.end(); it++)
     {
     {
@@ -833,7 +1024,7 @@ void Optimisation_method_neighbour(UnorientedGraph *g, EntiersEntiers &Partition
 	Entiers *part2_cons = new Entiers();
 	Entiers *part2_cons = new Entiers();
 	Entiers *part_cour_cons = new Entiers();
 	Entiers *part_cour_cons = new Entiers();
 	Entiers Random_list_vertices;
 	Entiers Random_list_vertices;
-	double cut=1000000000.;
+	double cut = 1000000000.;
 	//boost::copy_graph(*g,*copy_g_ref);
 	//boost::copy_graph(*g,*copy_g_ref);
 
 
 	for (int i=0 ; i<Partition.at(index_partition)->size() ; i++)
 	for (int i=0 ; i<Partition.at(index_partition)->size() ; i++)
@@ -845,6 +1036,11 @@ void Optimisation_method_neighbour(UnorientedGraph *g, EntiersEntiers &Partition
 		Random_list_vertices[rand_pos] = tmp;
 		Random_list_vertices[rand_pos] = tmp;
 	}
 	}
 	
 	
+	/*for(uint i = 0; i < Partition.at(index_partition)->size(); i++){
+		std::cout<<Partition.at(index_partition)->at(i)<<" ";
+	}
+	std::cout<<std::endl;*/
+		
 	if(Partition.at(index_partition)->size()< nbr_tirage)
 	if(Partition.at(index_partition)->size()< nbr_tirage)
 		nbr_tirage = Partition.at(index_partition)->size();
 		nbr_tirage = Partition.at(index_partition)->size();
 		
 		
@@ -861,41 +1057,18 @@ void Optimisation_method_neighbour(UnorientedGraph *g, EntiersEntiers &Partition
 			tmp_part->push_back(Partition.at(index_partition)->at(t));
 			tmp_part->push_back(Partition.at(index_partition)->at(t));
 		}
 		}
 		
 		
-		/*std::cout<<"Ensembles verification  !!! "<<std::endl;
-		std::cout<<"Ensemble 1 : ";
-		for(uint i = 0; i < tmp_part->size(); i++){
-			std::cout<<tmp_part->at(i)<<" ";
-		}
-		std::cout<<std::endl;
-		std::cout<<"Ensemble 2 : ";
-		for(uint j = 0; j < part2->size(); j++){
-			std::cout<<part2->at(j)<<" ";
-		}
-		std::cout<<std::endl;*/
-		
-		//gggp_pond(copy_g,tmp_part,part2,Partition);
-
+		//std::cout<<"Sommet de départ : "<<(*g)[Random_list_vertices.at(k)]._index<<std::endl;
 		if(name_strat == "gggp"){
 		if(name_strat == "gggp"){
-			gggp_pond(g,tmp_part,part2,Partition,Random_list_vertices.at(k),-1);
+			gggp_pond(g,tmp_part,part2,Partition,Random_list_vertices.at(k),index_partition, name_cut ,-1);
 		} else if(name_strat == "ggp"){
 		} else if(name_strat == "ggp"){
-			ggp(g,tmp_part,part2,Partition,Random_list_vertices.at(k),-1);
+			ggp(g,tmp_part,part2,Partition,Random_list_vertices.at(k), index_partition ,-1);
 		} else {
 		} else {
 			std::cout<<"Nom de stratégie de partitionnement non valide ! "<<std::endl;
 			std::cout<<"Nom de stratégie de partitionnement non valide ! "<<std::endl;
 		}
 		}
 		
 		
-		/*std::cout<<"Ensemble 1 : ";
-		for(uint i = 0; i < tmp_part->size(); i++){
-			std::cout<<tmp_part->at(i)<<" ";
-		}
-		std::cout<<std::endl;
-		std::cout<<"Ensemble 2 : ";
-		for(uint j = 0; j < part2->size(); j++){
-			std::cout<<part2->at(j)<<" ";
-		}
-		std::cout<<std::endl;
-		std::cout<<std::endl;*/
 		new_cut = Best_Cut_cluster(Partition, tmp_part, part2, index_partition,*g,name_cut);
 		new_cut = Best_Cut_cluster(Partition, tmp_part, part2, index_partition,*g,name_cut);
-		//std::cout<<"Cout de coupe initial : "<<cut<<" "<<"Résutlat : "<<new_cut<<std::endl;
+		
+		//std::cout<<"Cout de coupe : "<<new_cut<<std::endl;
 		//std::cout<<std::endl;
 		//std::cout<<std::endl;
 		if(new_cut<cut){ /*conservation de l'information en cas d'amélioration de la contrainte*/
 		if(new_cut<cut){ /*conservation de l'information en cas d'amélioration de la contrainte*/
 			cut = new_cut;
 			cut = new_cut;
@@ -917,10 +1090,26 @@ void Optimisation_method_neighbour(UnorientedGraph *g, EntiersEntiers &Partition
             remove_edge(part_cour_cons->at(i),part2_cons->at(j),*g);
             remove_edge(part_cour_cons->at(i),part2_cons->at(j),*g);
         }
         }
     }
     }
+    
+    /*std::cout<<"Ensemble 1 : ";
+		for(uint i = 0; i < part_cour_cons->size(); i++){
+			std::cout<<part_cour_cons->at(i)<<" ";
+		}
+		std::cout<<std::endl;
+		std::cout<<"Ensemble 2 : ";
+		for(uint j = 0; j < part2_cons->size(); j++){
+			std::cout<<part2_cons->at(j)<<" ";
+		}
+		std::cout<<std::endl;
+		std::cout<<std::endl;*/
 	/*Modification des informations*/
 	/*Modification des informations*/
 	Partition.at(index_partition)=part_cour_cons;
 	Partition.at(index_partition)=part_cour_cons;
 	Partition.push_back(part2_cons);
 	Partition.push_back(part2_cons);
 	//g=copy_g_ref;
 	//g=copy_g_ref;
+	
+	/*std::cout<<std::endl;
+	std::cout<<"Bissection réalisé"<<std::endl;
+	std::cout<<std::endl;*/
 }
 }
 
 
 void Optimisation_method_neighbour_distance(UnorientedGraph *g, EntiersEntiers &Partition, int index_partition, int nbr_tirage, int distance,
 void Optimisation_method_neighbour_distance(UnorientedGraph *g, EntiersEntiers &Partition, int index_partition, int nbr_tirage, int distance,
@@ -976,9 +1165,9 @@ void Optimisation_method_neighbour_distance(UnorientedGraph *g, EntiersEntiers &
 		
 		
 		//std::cout<<"Sommet tirée avant entré dans gggp : "<<*Iter<<std::endl;
 		//std::cout<<"Sommet tirée avant entré dans gggp : "<<*Iter<<std::endl;
 		if(name_strat == "gggp"){
 		if(name_strat == "gggp"){
-			gggp_pond(g,tmp_part,part2,Partition,val,distance);
+			gggp_pond(g,tmp_part,part2,Partition,val,index_partition, name_cut, distance);
 		} else if(name_strat == "ggp"){
 		} else if(name_strat == "ggp"){
-			ggp(g,tmp_part,part2,Partition,val,distance);
+			ggp(g,tmp_part,part2,Partition,val,index_partition, distance);
 		} else {
 		} else {
 			std::cout<<"Nom de stratégie de partitionnement non valide ! "<<std::endl;
 			std::cout<<"Nom de stratégie de partitionnement non valide ! "<<std::endl;
 		}
 		}
@@ -1027,6 +1216,92 @@ void Optimisation_method_neighbour_distance(UnorientedGraph *g, EntiersEntiers &
 	std::cout<<std::endl;*/
 	std::cout<<std::endl;*/
 }
 }
 
 
+void Optimisation_method_neighbour_degree(UnorientedGraph *g, EntiersEntiers &Partition, int index_partition,
+	const std::string &name_cut, const std::string &name_strat){
+	
+	std::vector<double> vertex_degree;
+	Entiers *part2 = new Entiers();
+	
+	for(uint i =0; i<Partition.at(index_partition)->size(); i++){
+		vertex_degree.push_back(Degree(*g, Partition.at(index_partition)->at(i)));
+	}
+	
+	uint best_cpt = 0;
+	double  best_degree = vertex_degree.at(0);
+	
+	for(uint i =1; i<vertex_degree.size(); i++){
+		if(vertex_degree.at(i)>best_degree){
+			best_degree = vertex_degree.at(i);
+			best_cpt = i;
+		}
+	}
+	
+	if(name_strat == "gggp"){
+		gggp_pond(g,Partition.at(index_partition),part2,Partition,best_cpt,index_partition,name_cut,-1);
+	} else if(name_strat == "ggp"){
+		ggp(g,Partition.at(index_partition),part2,Partition,best_cpt,index_partition,-1);
+	} else {
+		std::cout<<"Nom de stratégie de partitionnement non valide ! "<<std::endl;
+	}
+	
+	for (uint i=0; i<Partition.at(index_partition)->size();i++)
+    {
+        for (uint j=0; j<part2->size();j++)
+        {
+			remove_edge(Partition.at(index_partition)->at(i),part2->at(j),*g);
+        }
+    }
+
+	Partition.push_back(part2);
+	
+}
+
+void Optimisation_method_neighbour_minweight(UnorientedGraph *g, EntiersEntiers &Partition, int index_partition,
+	const std::string &name_cut, const std::string &name_strat){
+	
+	std::vector<double> vertex_weight;
+	Entiers *part2 = new Entiers();
+	
+	for(uint i =0; i<Partition.at(index_partition)->size(); i++){
+		vertex_weight.push_back((*g)[Partition.at(index_partition)->at(i)]._weight);
+	}
+	
+	uint best_cpt = 0;
+	double  best_weight = vertex_weight.at(0);
+	
+	for(uint i =1; i<vertex_weight.size(); i++){
+		if(vertex_weight.at(i)>best_weight){
+			best_weight = vertex_weight.at(i);
+			best_cpt = i;
+		}
+	}
+	
+	if(name_cut == "ratio"){
+		int tmp_best_cpt;
+		tmp_best_cpt = Partition.at(index_partition)->at(best_cpt);
+		best_cpt = tmp_best_cpt;
+	}
+	
+	if(name_strat == "gggp"){
+		gggp_pond(g,Partition.at(index_partition),part2,Partition,best_cpt,index_partition,name_cut,-1);
+	} else if(name_strat == "ggp"){
+		ggp(g,Partition.at(index_partition),part2,Partition,best_cpt,index_partition,-1);
+	} else {
+		std::cout<<"Nom de stratégie de partitionnement non valide ! "<<std::endl;
+	}
+	
+	for (uint i=0; i<Partition.at(index_partition)->size();i++)
+    {
+        for (uint j=0; j<part2->size();j++)
+        {
+			remove_edge(Partition.at(index_partition)->at(i),part2->at(j),*g);
+        }
+    }
+
+	Partition.push_back(part2);
+	
+}
+
 void tirage_distance(UnorientedGraph *g, int tirage, std::list<int> &vertex_list, int distance){
 void tirage_distance(UnorientedGraph *g, int tirage, std::list<int> &vertex_list, int distance){
 	std::vector<std::list<int> > vertex_delete;
 	std::vector<std::list<int> > vertex_delete;
 	std::list<int> liste1;
 	std::list<int> liste1;

+ 8 - 3
src/tests/boost_graph/partitioning/gggp.hpp

@@ -33,10 +33,10 @@
 namespace paradevs { namespace tests { namespace boost_graph {
 namespace paradevs { namespace tests { namespace boost_graph {
 
 
 void ggp(UnorientedGraph *g, Entiers *sommetsSource,
 void ggp(UnorientedGraph *g, Entiers *sommetsSource,
-         Entiers *sommetsDestination, EntiersEntiers &Partition,int rand);
+         Entiers *sommetsDestination, EntiersEntiers &Partition, int rand , int &index_partition, int distance);
 
 
 void gggp_pond(UnorientedGraph *g, Entiers *sommetsSource,
 void gggp_pond(UnorientedGraph *g, Entiers *sommetsSource,
-               Entiers *sommetsDestination, EntiersEntiers &Partition, int rand, int distance);
+               Entiers *sommetsDestination, EntiersEntiers &Partition, int rand, int &index_partition, const std::string &name , int distance);
 
 
 void Iter_2l(EntiersEntiers &part, int nbr_parties, UnorientedGraph *g,
 void Iter_2l(EntiersEntiers &part, int nbr_parties, UnorientedGraph *g,
              const std::string &nom_cut, int nbr_tirage, const std::string &nom_strat, int distance = -1);
              const std::string &nom_cut, int nbr_tirage, const std::string &nom_strat, int distance = -1);
@@ -59,10 +59,15 @@ OrientedGraphs Multiniveau(uint niveau_contraction, UnorientedGraph *g, Unorient
                            Edges &edge_partie,
                            Edges &edge_partie,
                            OutputEdgeList &outputedgeslist,
                            OutputEdgeList &outputedgeslist,
                            InputEdgeList &inputedgelist,
                            InputEdgeList &inputedgelist,
-                           Connections &connections, std::vector<double> &Cut, int distance = -1);
+                           Connections &connections,
+                           bool rec, std::vector<double> &Cut,
+                           int distance = -1);
 void Optimisation_method_neighbour(UnorientedGraph *g, EntiersEntiers &Partition, int index_partition, int nbr_tirage, const std::string &name_cut, const std::string &name_strat);
 void Optimisation_method_neighbour(UnorientedGraph *g, EntiersEntiers &Partition, int index_partition, int nbr_tirage, const std::string &name_cut, const std::string &name_strat);
 void Optimisation_method_neighbour_distance(UnorientedGraph *g, EntiersEntiers &Partition, int index_partition, int nbr_tirage, int distance, const std::string &name_cut, 
 void Optimisation_method_neighbour_distance(UnorientedGraph *g, EntiersEntiers &Partition, int index_partition, int nbr_tirage, int distance, const std::string &name_cut, 
 	const std::string &name_strat);
 	const std::string &name_strat);
+void Optimisation_method_neighbour_degree(UnorientedGraph *g, EntiersEntiers &Partition, int index_partition,const std::string &name_cut, const std::string &name_strat);
+void Optimisation_method_neighbour_minweight(UnorientedGraph *g, EntiersEntiers &Partition, int index_partition,
+	const std::string &name_cut, const std::string &name_strat);
 void tirage_distance(UnorientedGraph *g, int tirage, std::list<int> &vertex_list, int distance);
 void tirage_distance(UnorientedGraph *g, int tirage, std::list<int> &vertex_list, int distance);
 
 
 } } } // namespace paradevs tests boost_graph
 } } } // namespace paradevs tests boost_graph

+ 251 - 13
src/tests/boost_graph/partitioning/graph_build.cpp

@@ -47,23 +47,23 @@ void build_graph(OrientedGraph& og, unsigned int edge_number)
 		vertex_to v9 = boost::add_vertex(og);
 		vertex_to v9 = boost::add_vertex(og);
 		vertex_to v10 = boost::add_vertex(og);
 		vertex_to v10 = boost::add_vertex(og);
 
 
-		add_edge(v1, v0, EdgeProperties(1.), og);
-		add_edge(v2, v0, EdgeProperties(1.), og);
-		add_edge(v3, v0, EdgeProperties(1.), og);
-		add_edge(v1, v2, EdgeProperties(1.), og);
-		add_edge(v4, v1, EdgeProperties(1.), og);
-		add_edge(v5, v1, EdgeProperties(1.), og);
-		add_edge(v6, v1, EdgeProperties(1.), og);
-		add_edge(v6, v2, EdgeProperties(1.), og);
+		add_edge(v1, v0, EdgeProperties(2.), og);
+		add_edge(v2, v0, EdgeProperties(1.5), og);
+		add_edge(v3, v0, EdgeProperties(1.5), og);
+		add_edge(v1, v2, EdgeProperties(3.), og);
+		add_edge(v4, v1, EdgeProperties(3.), og);
+		add_edge(v5, v1, EdgeProperties(3.), og);
+		add_edge(v6, v1, EdgeProperties(3.), og);
+		add_edge(v6, v2, EdgeProperties(2.), og);
 		add_edge(v2, v3, EdgeProperties(1.), og);
 		add_edge(v2, v3, EdgeProperties(1.), og);
 		add_edge(v9, v3, EdgeProperties(1.), og);
 		add_edge(v9, v3, EdgeProperties(1.), og);
 		add_edge(v10, v3, EdgeProperties(1.), og);
 		add_edge(v10, v3, EdgeProperties(1.), og);
-		add_edge(v4, v5, EdgeProperties(1.), og);
-		add_edge(v5, v6, EdgeProperties(1.), og);
+		add_edge(v4, v5, EdgeProperties(1.5), og);
+		add_edge(v5, v6, EdgeProperties(1.5), og);
 		add_edge(v7, v4, EdgeProperties(1.), og);
 		add_edge(v7, v4, EdgeProperties(1.), og);
 		add_edge(v8, v4, EdgeProperties(1.), og);
 		add_edge(v8, v4, EdgeProperties(1.), og);
-		add_edge(v7, v8, EdgeProperties(1.), og);
-		add_edge(v9, v10, EdgeProperties(1.), og);
+		add_edge(v7, v8, EdgeProperties(1.5), og);
+		add_edge(v9, v10, EdgeProperties(2.), og);
 
 
 		og[v6] = VertexProperties(6, 1.5, NORMAL_PIXEL);
 		og[v6] = VertexProperties(6, 1.5, NORMAL_PIXEL);
 		og[v8] = VertexProperties(8, 1., NORMAL_PIXEL);
 		og[v8] = VertexProperties(8, 1., NORMAL_PIXEL);
@@ -236,6 +236,57 @@ void modify_file_paths(std::string& absolutePath,
     }
     }
 }
 }
 
 
+void build_graph_cyclique(OrientedGraph& og)
+{
+		vertex_to v0 = boost::add_vertex(og);
+		vertex_to v1 = boost::add_vertex(og);
+		vertex_to v2 = boost::add_vertex(og);
+		vertex_to v3 = boost::add_vertex(og);
+		vertex_to v4 = boost::add_vertex(og);
+		vertex_to v5 = boost::add_vertex(og);
+		vertex_to v6 = boost::add_vertex(og);
+		vertex_to v7 = boost::add_vertex(og);
+		vertex_to v8 = boost::add_vertex(og);
+		vertex_to v9 = boost::add_vertex(og);
+		vertex_to v10 = boost::add_vertex(og);
+
+		add_edge(v0, v1, EdgeProperties(1.), og);
+		add_edge(v0, v2, EdgeProperties(1.), og);
+		add_edge(v0, v3, EdgeProperties(1.), og);
+		add_edge(v1, v3, EdgeProperties(1.), og);
+		add_edge(v2, v1, EdgeProperties(1.), og);
+		add_edge(v2, v3, EdgeProperties(1.), og);
+		add_edge(v2, v4, EdgeProperties(1.), og);
+		add_edge(v2, v5, EdgeProperties(1.), og);
+		add_edge(v2, v7, EdgeProperties(1.), og);
+		add_edge(v2, v9, EdgeProperties(1.), og);
+		add_edge(v3, v4, EdgeProperties(1.), og);
+		add_edge(v3, v5, EdgeProperties(1.), og);
+		add_edge(v3, v7, EdgeProperties(1.), og);
+		add_edge(v3, v9, EdgeProperties(1.), og);
+		add_edge(v4, v6, EdgeProperties(1.), og);
+		add_edge(v5, v4, EdgeProperties(1.), og);
+		add_edge(v5, v6, EdgeProperties(1.), og);
+		add_edge(v6, v7, EdgeProperties(1.), og);
+		add_edge(v7, v8, EdgeProperties(1.), og);
+		add_edge(v7, v10, EdgeProperties(1.), og);
+		add_edge(v8, v9, EdgeProperties(1.), og);
+		add_edge(v8, v10, EdgeProperties(1.), og);
+		add_edge(v9, v10, EdgeProperties(1.), og);
+		add_edge(v10, v0, EdgeProperties(1.), og);
+
+		og[v6] = VertexProperties(6, 1, NORMAL_PIXEL);
+		og[v8] = VertexProperties(8, 1, NORMAL_PIXEL);
+		og[v10] = VertexProperties(10, 1, NORMAL_PIXEL);
+		og[v0] = VertexProperties(0, 1, NORMAL_PIXEL);
+		og[v1] = VertexProperties(1, 1, NORMAL_PIXEL);
+		og[v2] = VertexProperties(2, 1, NORMAL_PIXEL);
+		og[v3] = VertexProperties(3, 1, NORMAL_PIXEL);
+		og[v4] = VertexProperties(4, 1, NORMAL_PIXEL);
+		og[v5] = VertexProperties(5, 1, NORMAL_PIXEL);
+		og[v7] = VertexProperties(7, 1, NORMAL_PIXEL);
+		og[v9] = VertexProperties(9, 1, NORMAL_PIXEL);
+}
 /*void build_corsen_graph(OrientedGraph& graph)
 /*void build_corsen_graph(OrientedGraph& graph)
 {
 {
     std::string absolutePath(
     std::string absolutePath(
@@ -339,7 +390,7 @@ void brhtg_source(OrientedGraph *go,int nbr_vertex, int nbr_source, int nbr_v_mi
 					while(cpt!=nbr_voisin){
 					while(cpt!=nbr_voisin){
 						int val;
 						int val;
 						if(j<branche.at(i)+nbr_source){ // Les sommets sont des sources donc imossible de recevoir des données
 						if(j<branche.at(i)+nbr_source){ // Les sommets sont des sources donc imossible de recevoir des données
-							val = rand_fini(j + nbr_source, j + nbr_v_max + nbr_passe);
+							val = rand_fini(j + 4, j + nbr_v_max + nbr_passe);
 						}
 						}
 						else if(j>=branche.at(i)+nbr_npb-nbr_passe && i!= (branche.size()-2)){ // Les sommets sont en fin de branche, nécessité de raccordement avec les autres branches
 						else if(j>=branche.at(i)+nbr_npb-nbr_passe && i!= (branche.size()-2)){ // Les sommets sont en fin de branche, nécessité de raccordement avec les autres branches
 							val = rand_fini(branche.at(branche.size()-1)-4, branche.at(branche.size()-1));
 							val = rand_fini(branche.at(branche.size()-1)-4, branche.at(branche.size()-1));
@@ -684,5 +735,192 @@ void build_generator_graph(OrientedGraph *go, int nbr_vertex, int nbr_source, in
 
 
 }
 }
 
 
+void build_generator_graph_linked(OrientedGraph *go, int nbr_vertex, int nbr_couche, int nbr_v_min, int nbr_v_max){
+	std::vector<vertex_to> Vertexs;
+	for(int i =0; i<nbr_vertex; i++){
+		vertex_to vo = boost::add_vertex(*go);
+		Vertexs.push_back(vo);
+	}
+	
+	/*Création du vecteur contenant le nombre de sommets par couche*/
+	int midel_couche = nbr_couche-2;
+	int top_couche;
+	if(nbr_couche>5){
+		top_couche = floor(nbr_vertex/floor(midel_couche/2));
+	}else{
+		top_couche = floor(nbr_vertex/2);
+	}
+	int nbr_vertex_midel_couche = nbr_vertex - top_couche -1;
+	int tmp = 0;
+	std::vector<int> nbr_som_couche;
+	nbr_som_couche.push_back(1);
+	
+	for(int i = 1; i <= midel_couche; i++){
+		tmp += i;
+	}
+	
+	for(int i = 0; i < midel_couche; i++){
+		nbr_som_couche.push_back(floor((i+1)*nbr_vertex_midel_couche/tmp));
+	}
+	
+	nbr_som_couche.push_back(top_couche);
+	
+	int sum = 0;
+	for(int i = 0; i < nbr_som_couche.size(); i++){
+		sum += nbr_som_couche.at(i);
+	}
+	int reste = nbr_vertex - sum;
+	
+	/*std::cout<<"sum : "<<sum<<std::endl;
+	std::cout<<"midel_couche : "<<midel_couche<<std::endl;
+	std::cout<<"top_couche : "<<top_couche<<std::endl;
+	std::cout<<"nbr_vertex_midel_couche : "<<nbr_vertex_midel_couche<<std::endl;
+	std::cout<<"tmp : "<<tmp<<std::endl;
+	std::cout<<"reste : "<<reste<<std::endl;
+	
+	for(int i =0; i < nbr_som_couche.size(); i++){
+		std::cout<<nbr_som_couche.at(i)<<" ";
+	}
+	std::cout<<std::endl;*/
+	
+	while(reste != 0){
+		for(int i = 1; i <nbr_som_couche.size(); i++){
+			nbr_som_couche.at(i) += 1;
+			reste --;
+			if(reste == 0){
+				break;
+			}
+		}
+	}
+	
+	/*for(int i =0; i < nbr_som_couche.size(); i++){
+		std::cout<<nbr_som_couche.at(i)<<" ";
+	}
+	std::cout<<std::endl;*/
+	
+	/*Génération du graphe*/
+	std::vector<int> tab_couche_som;
+	tab_couche_som.push_back(0);
+	
+	for(int i =1; i<nbr_som_couche.size(); i++){
+		tab_couche_som.push_back(tab_couche_som.at(i-1)+nbr_som_couche.at(i));
+	}
+	
+	/*for(int i =0; i < tab_couche_som.size(); i++){
+		std::cout<<tab_couche_som.at(i)<<" ";
+	}
+	std::cout<<std::endl;*/
+	int nbr_vois = nbr_v_max+2;
+	
+	int cpt = 0;
+	for(int i = tab_couche_som.at(tab_couche_som.size()-2)+1; i <= tab_couche_som.at(tab_couche_som.size()-1); i++){
+		std::vector<int> vertex_tmp;
+		int rand = rand_fini(nbr_v_min,nbr_v_max+1);
+		int neigh_cpt = 0;
+		while(neigh_cpt != rand){
+			int val;
+			if(cpt<nbr_vois){
+				val = rand_fini(tab_couche_som.at(tab_couche_som.size()-3)+cpt+1,tab_couche_som.at(tab_couche_som.size()-3)+cpt+1+nbr_vois);
+				//std::cout<<"val1 : "<<val<<std::endl;
+			}else if(cpt>nbr_vois && cpt<(tab_couche_som.at(tab_couche_som.size()-2)-tab_couche_som.at(tab_couche_som.size()-3)+1-nbr_vois)){
+				val = rand_fini(tab_couche_som.at(tab_couche_som.size()-3)+cpt+1-nbr_vois,tab_couche_som.at(tab_couche_som.size()-3)+cpt+1+nbr_vois);
+				//std::cout<<"val2 : "<<val<<std::endl;
+			}else{
+				val = rand_fini(tab_couche_som.at(tab_couche_som.size()-2)+1-2*nbr_vois,tab_couche_som.at(tab_couche_som.size()-2)+1);
+				//std::cout<<"val3 : "<<val<<std::endl;
+			}
+			if(In_tab(vertex_tmp,val) != 1){
+				boost::add_edge(Vertexs.at(i), Vertexs.at(val), EdgeProperties(1.), *go);
+				vertex_tmp.push_back(val);
+				neigh_cpt ++;
+			}
+		}
+		cpt ++;
+	}
+	//std::cout<<"Passage !"<<std::endl;
+	
+	for(int j = 2; j < tab_couche_som.size()-1; j++){
+		cpt = 0;
+		for(int i = tab_couche_som.at(tab_couche_som.size()-1-j)+1; i <= tab_couche_som.at(tab_couche_som.size()-1-(j-1)); i++){
+			std::vector<int> vertex_tmp;
+			int rand = rand_fini(nbr_v_min,nbr_v_max+1);
+			//std::cout<<"rand : "<<rand<<std::endl;
+			int neigh_cpt = 0;
+			while(neigh_cpt != rand){
+				int val;
+				if((tab_couche_som.at(tab_couche_som.size()-2-(j-1))-tab_couche_som.at(tab_couche_som.size()-2-j))>2*nbr_vois){
+					if(cpt<nbr_vois){
+						val = rand_fini(tab_couche_som.at(tab_couche_som.size()-2-j)+cpt+1,tab_couche_som.at(tab_couche_som.size()-2-j)+cpt+1+nbr_vois);
+						//std::cout<<"val1 : "<<val<<std::endl;
+					}else if(cpt>nbr_vois && cpt<(tab_couche_som.at(tab_couche_som.size()-2-(j-1))-tab_couche_som.at(tab_couche_som.size()-2-j)+1-nbr_vois)){
+						val = rand_fini(tab_couche_som.at(tab_couche_som.size()-2-j)+cpt+1-nbr_vois,tab_couche_som.at(tab_couche_som.size()-2-j)+cpt+1+nbr_vois);
+						//std::cout<<"val2 : "<<val<<std::endl;
+					}else{
+						if(2*nbr_vois<(tab_couche_som.at(tab_couche_som.size()-2-(j-1))-tab_couche_som.at(tab_couche_som.size()-2-j)+1)){
+							val = rand_fini(tab_couche_som.at(tab_couche_som.size()-2-(j-1))+1-2*nbr_vois,tab_couche_som.at(tab_couche_som.size()-2-(j-1))+1);
+						}else{
+							val = rand_fini(tab_couche_som.at(tab_couche_som.size()-2-(j-1))+1-nbr_vois,tab_couche_som.at(tab_couche_som.size()-2-(j-1))+1);
+						}
+						//std::cout<<"val3 : "<<val<<std::endl;
+					}
+				}else{
+					val = rand_fini(tab_couche_som.at(tab_couche_som.size()-2-j)+1,tab_couche_som.at(tab_couche_som.size()-2-(j-1))+1);
+				}
+				//int val = rand_fini(tab_couche_som.at(tab_couche_som.size()-2-j)+1,tab_couche_som.at(tab_couche_som.size()-2-(j-1))+1);
+				if(In_tab(vertex_tmp,val) != 1){
+					boost::add_edge(Vertexs.at(i), Vertexs.at(val), EdgeProperties(1.), *go);
+					vertex_tmp.push_back(val);
+					neigh_cpt ++;	
+				}
+			}
+			cpt ++;
+		}
+	}
+	//std::cout<<"Passage2 !"<<std::endl;
+	
+	for(int i = tab_couche_som.at(0)+1; i <= tab_couche_som.at(1); i++){
+		//int val = rand_fini(0,2);
+		//if(val == 0){
+			boost::add_edge(Vertexs.at(i), Vertexs.at(0), EdgeProperties(1.), *go);
+		//}
+	}
+	//std::cout<<"Passage3 !"<<std::endl;
+	
+	std::vector < int > dg_in_vertex_list;
+	std::vector <vertex_to> dg_vertex_list;
+	OrientedGraph::vertex_iterator it_dg, end_dg;
+
+	tie(it_dg, end_dg) = vertices(*go);
+	for (uint i = 0; it_dg != end_dg; ++it_dg, ++i) {
+		dg_in_vertex_list.push_back(0);
+		dg_vertex_list.push_back(*it_dg);
+	}
+
+	tie(it_dg, end_dg) = vertices(*go);
+	for (uint i = 0; it_dg != end_dg; ++it_dg, ++i) {
+		OrientedGraph::adjacency_iterator neighbour_it, neighbour_end;
+
+		tie(neighbour_it, neighbour_end) = adjacent_vertices(*it_dg, *go);
+		for (; neighbour_it != neighbour_end; ++neighbour_it) {
+			uint index = 0;
+
+			while (dg_vertex_list[index] != *neighbour_it) {
+				++index;
+			}
+			++dg_in_vertex_list[index];
+		}
+	}
+	
+	for(uint i = 0; i<num_vertices(*go); i++){
+		if(dg_in_vertex_list.at(i) == 0){
+			(*go)[i] = VertexProperties(i, 1, TOP_PIXEL);
+		}else{
+			(*go)[i] = VertexProperties(i, 1, NORMAL_PIXEL);
+		}
+	}
+	
+	
+}
+
 
 
 } } } // namespace paradevs tests boost_graph
 } } } // namespace paradevs tests boost_graph

+ 2 - 0
src/tests/boost_graph/partitioning/graph_build.hpp

@@ -33,6 +33,8 @@ namespace paradevs { namespace tests { namespace boost_graph {
 
 
 void build_graph(OrientedGraph& og, unsigned int edge_number);
 void build_graph(OrientedGraph& og, unsigned int edge_number);
 void build_generator_graph(OrientedGraph *go, int nbr_vertex, int nbr_source, int nbr_v_min, int nbr_v_max,const std::vector<int> &niveau);
 void build_generator_graph(OrientedGraph *go, int nbr_vertex, int nbr_source, int nbr_v_min, int nbr_v_max,const std::vector<int> &niveau);
+void build_generator_graph_linked(OrientedGraph *go, int nbr_vertex, int nbr_couche, int nbr_v_min, int nbr_v_max);
+void build_graph_cyclique(OrientedGraph& og);
 //void build_corsen_graph(OrientedGraph& graph);
 //void build_corsen_graph(OrientedGraph& graph);
 
 
 } } } // namespace paradevs tests boost_graph;
 } } } // namespace paradevs tests boost_graph;

+ 192 - 25
src/tests/boost_graph/partitioning/main.cpp

@@ -46,13 +46,103 @@ int main()
 
 
     srand((unsigned)time(NULL));
     srand((unsigned)time(NULL));
 
 
+	/*std::vector<std::pair < double, int >> tab_diff;
+	
+	for(int i =0; i<5; i++){
+		std::pair<double, int> diff(rand_fini(0,15)+0.426,i);
+		tab_diff.push_back(diff);
+		std::cout<<tab_diff.at(i).first<<" "<<tab_diff.at(i).second<<std::endl;
+	}
+	std::cout<<std::endl;
+	sort(tab_diff.begin(),tab_diff.end());
+	for(int i =0; i<5; i++){
+		std::cout<<tab_diff.at(i).first<<" "<<tab_diff.at(i).second<<std::endl;
+	}
+	
+	std::vector<int> Diff;
+	for(int i =0; i<tab_diff.size(); i++){
+		Diff.push_back(tab_diff.at(i).second);
+	}
+	
+	for(int i =0; i<tab_diff.size(); i++){
+		std::cout<<Diff.at(i)<<std::endl;
+	}*/
 	
 	
     OrientedGraph* go = new OrientedGraph();
     OrientedGraph* go = new OrientedGraph();
-    UnorientedGraph graph_origin;
+    /*UnorientedGraph graph_origin;
+    build_graph(*go, 11);
+    
+    UnorientedGraph *g = new UnorientedGraph();
+	make_unoriented_graph(*go, *g);
+	
+    EntiersEntiers Partition;
+    Entiers *part1 = new Entiers();
+    Entiers *part2 = new Entiers();
+    for(uint i = 0; i<11; i ++){
+		part1->push_back(i);
+	}
+    Partition.push_back(part1);
+    
+	int node = 1;
+	int index = 0;
+    gggp_pond(g, part1, part2, Partition, node, index, "cut", 2);
+    Partition.push_back(part2);
+    
+    double cut = Cut_cluster(Partition, *g, "cut");
+    
+    for(int x =0; x<Partition.size(); x++){
+		std::cout<<"** ";
+		for(int y =0; y<Partition.at(x)->size();y++){
+			std::cout<<Partition.at(x)->at(y)<<" ";
+		}
+		std::cout<<std::endl;
+	}
+	std::cout<<std::endl;
+	
+	std::cout<<"cut : "<<cut<<std::endl;
+	
+	for(EntiersEntiers::iterator it = Partition.begin(); it != Partition.end(); it++)
+    {
+        delete *it;
+        *it = NULL;
+    }
+    
+    EntiersEntiers Partition2;
+	Entiers *part3 = new Entiers();
+    Entiers *part4 = new Entiers();
+    
+    for(uint i = 0; i<11; i ++){
+		part3->push_back(i);
+	}
+    Partition2.push_back(part3);
+
+    gggp_pond(g, part3, part4, Partition2, node, index, "ratio", 2);
+    Partition2.push_back(part4);
+    
+	cut = Cut_cluster(Partition2, *g, "ratio");
+    
+    for(int x =0; x<Partition2.size(); x++){
+		std::cout<<"** ";
+		for(int y =0; y<Partition2.at(x)->size();y++){
+			std::cout<<Partition2.at(x)->at(y)<<" ";
+		}
+		std::cout<<std::endl;
+	}
+	std::cout<<std::endl;
+	
+	std::cout<<"cut : "<<cut<<std::endl;
+	
+	for(EntiersEntiers::iterator it = Partition2.begin(); it != Partition2.end(); it++)
+    {
+        delete *it;
+        *it = NULL;
+    }*/
+
     std::vector<std::string> color;
     std::vector<std::string> color;
     color.push_back("node [color=lightblue2, style=filled];");
     color.push_back("node [color=lightblue2, style=filled];");
     color.push_back("node [color=red, style=filled];");
     color.push_back("node [color=red, style=filled];");
     color.push_back("node [color=limegreen, style=filled];");
     color.push_back("node [color=limegreen, style=filled];");
+    color.push_back("node [color=plum, style=filled];");
     color.push_back("node [color=orange, style=filled];");
     color.push_back("node [color=orange, style=filled];");
     color.push_back("node [color=yellow2, style=filled];");
     color.push_back("node [color=yellow2, style=filled];");
     color.push_back("node [color=slateblue1, style=filled];");
     color.push_back("node [color=slateblue1, style=filled];");
@@ -66,22 +156,100 @@ int main()
     color.push_back("node [color=cyan, style=filled];");
     color.push_back("node [color=cyan, style=filled];");
     color.push_back("node [color=crimson, style=filled];");
     color.push_back("node [color=crimson, style=filled];");
     color.push_back("node [color=lightsalmon, style=filled];");
     color.push_back("node [color=lightsalmon, style=filled];");
-    int nbr_parties = 4;
+    
+    
+    int nbr_sommets = 10000;
+    int nbr_sources = nbr_sommets/100*1; // 1% des sommets sont des sources
+    Entiers niveau = {5,4,3,2};
+    
+    //build_graph(*go, 38);
+    //build_generator_graph(go, nbr_sommets, nbr_sources , 2 , 3 ,niveau);
+    build_generator_graph_linked(go, nbr_sommets, 100 , 2, 3);
+    //build_graph_cyclique(*go);
+    //const char *texte = new const char();
+    //texte = "../../sortie_graphe/enregistrement_100.txt";
+    //Text_generator_graph(texte,go);
+    //Graph_constructor_txt(texte, go);
+    
+    std::ofstream fichier ("../../sortie_graphe/Tests/Graphes/txt/graph_linked_200_30.txt", std::ios::out);
+    fichier<<"digraph G {"<<std::endl;
+    tie(vertexIto, vertexEndo) = vertices(*go);
+    for (; vertexIto != vertexEndo; ++vertexIto) {
+    	fichier<<(*go)[*vertexIto]._index<<"-> {";
+    	//std::cout<<(*go)[*vertexIto]._index<<" -> ";
+    	tie(neighbourIto, neighbourEndo) = adjacent_vertices(*vertexIto,
+    			*go);
+    	for (; neighbourIto != neighbourEndo; ++neighbourIto){
+    		fichier<<(*go)[*neighbourIto]._index<<";";
+    		//std::cout<<(*go)[*neighbourIto]._index<<" ";
+    	}
+    	fichier<<"}"<<std::endl;
+    	//std::cout<<std::endl;
+    }
+	fichier<<"}";
+	fichier.close();
+	//std::cout<<std::endl;
+	
+
+	int nbr_parties = 50;
+	int niveau_contraction = num_vertices(*go)/50;
+	std::vector<double> Cut;
+	int nbr_tirage = 20;
+	
+	for(uint i =0; i<nbr_tirage; i++){
+	Edges edge_partie;
+	OutputEdgeList outputedgeslist(nbr_parties);
+	InputEdgeList inputedgelist;
+	Connections connections;
+	UnorientedGraph *g = new UnorientedGraph();
+	UnorientedGraph graph_origin;
+	make_unoriented_graph(*go, *g);
+	boost::copy_graph(*g, graph_origin);
+
+	OrientedGraphs graphs = Multiniveau(niveau_contraction, g, &graph_origin, go, nbr_parties, 10,"HEM", "gggp",
+									"diff", "ratio", edge_partie ,
+									outputedgeslist, inputedgelist,
+									connections,false,Cut,2);  	
+									//std::cout<<std::endl;
+									//std::cout<<std::endl;				
+	}
+	
+	//std::ofstream fichier_cut ("../../sortie_graphe/Tests/Cut/cut_s200_nc10_d0_c1_t10_p8_gggp.txt", std::ios::out);
+	double moy = 0.;
+	
+	for(int cpt = 0; cpt <Cut.size(); cpt ++){
+		//if(cpt!=Cut.size()-1)
+			//fichier_cut<<Cut.at(cpt)<<";";
+		//else
+			//fichier_cut<<Cut.at(cpt);
+		moy += Cut.at(cpt);
+		//std::cout<<Cut.at(cpt)<<std::endl;
+	}
+	//fichier_cut.close();
+	
+	moy/= Cut.size();
+	std::cout<<moy<<std::endl;
+	
+    /*int nbr_parties = 20;
+    int nbr_sommets = 200;
+    int nbr_sources = nbr_sommets/100*1; // 1% des sommets sont des sources
+    const char *texte = new const char();
+    texte = "../../sortie_graphe/enregistrement_200.txt";
     
     
 
 
 
 
     //build_graph(*go, 38);
     //build_graph(*go, 38);
-    Entiers niveau;
-    niveau.push_back(2);
-    niveau.push_back(3);   
-    niveau.push_back(2);
-	//niveau.push_back(2);
-    //niveau.push_back(2);
-    
-    build_generator_graph(go, 2000, 5 , 2 , 5 ,niveau);
+    Entiers niveau = {2,2};
+    
+    //build_generator_graph(go, nbr_sommets, nbr_sources , 2 , 3 ,niveau);
+    
+
+    //Text_generator_graph(texte,go);
+    Graph_constructor_txt(texte, go);
+	
     //make_unoriented_graph(*go, *g);
     //make_unoriented_graph(*go, *g);
     
     
-    std::ofstream fichier ("../../sortie_graphe/graph_38.txt", std::ios::out);
+    std::ofstream fichier ("../../sortie_graphe/Tests/arbre_s200_n22_tests.txt", std::ios::out);
     fichier<<"digraph G {"<<std::endl;
     fichier<<"digraph G {"<<std::endl;
     tie(vertexIto, vertexEndo) = vertices(*go);
     tie(vertexIto, vertexEndo) = vertices(*go);
     for (; vertexIto != vertexEndo; ++vertexIto) {
     for (; vertexIto != vertexEndo; ++vertexIto) {
@@ -97,37 +265,35 @@ int main()
 	fichier.close();
 	fichier.close();
 	
 	
 	std::vector<double> Cut;
 	std::vector<double> Cut;
-	int niveau_contraction = num_vertices(*go)/10;
+	int niveau_contraction = num_vertices(*go)/1;
 	
 	
-	for(uint i =0; i<100; i++){
+	for(uint i =0; i<500; i++){
 		Edges edge_partie;
 		Edges edge_partie;
 		OutputEdgeList outputedgeslist(nbr_parties);
 		OutputEdgeList outputedgeslist(nbr_parties);
 		InputEdgeList inputedgelist;
 		InputEdgeList inputedgelist;
 		Connections connections;
 		Connections connections;
-		UnorientedGraph* g = new UnorientedGraph();
+		UnorientedGraph *g = new UnorientedGraph();
 		make_unoriented_graph(*go, *g);
 		make_unoriented_graph(*go, *g);
 		boost::copy_graph(*g, graph_origin);
 		boost::copy_graph(*g, graph_origin);
     
     
-		OrientedGraphs graphs = Multiniveau(niveau_contraction, g, &graph_origin, go, nbr_parties, 8,"HEM", "gggp",
+		OrientedGraphs graphs = Multiniveau(niveau_contraction, g, &graph_origin, go, nbr_parties, 20,"HEM", "ggp",
                                         "cut", "ratio", edge_partie ,
                                         "cut", "ratio", edge_partie ,
                                         outputedgeslist, inputedgelist,
                                         outputedgeslist, inputedgelist,
-                                        connections,Cut,3);  
+                                        connections,Cut,4);  
                                         
                                         
 	}
 	}
 	
 	
-	std::ofstream fichier_cut ("../../sortie_graphe/graphe_cut.txt", std::ios::out);
-	fichier_cut<<"x<-c(";
+	std::ofstream fichier_cut ("../../sortie_graphe/Tests/Cut/cut_s200_n22_d4-20_c1_t500_p20_ggp.txt", std::ios::out);
 	double moy = 0.;
 	double moy = 0.;
 	
 	
 	for(int cpt = 0; cpt <Cut.size(); cpt ++){
 	for(int cpt = 0; cpt <Cut.size(); cpt ++){
 		if(cpt!=Cut.size()-1)
 		if(cpt!=Cut.size()-1)
-			fichier_cut<<Cut.at(cpt)<<",";
+			fichier_cut<<Cut.at(cpt)<<";";
 		else
 		else
 			fichier_cut<<Cut.at(cpt);
 			fichier_cut<<Cut.at(cpt);
 		moy += Cut.at(cpt);
 		moy += Cut.at(cpt);
-		std::cout<<Cut.at(cpt)<<std::endl;
+		//std::cout<<Cut.at(cpt)<<std::endl;
 	}
 	}
-	fichier_cut<<")"<<std::endl;
 	fichier_cut.close();
 	fichier_cut.close();
 	
 	
 	moy/= Cut.size();
 	moy/= Cut.size();
@@ -143,7 +309,7 @@ int main()
 	std::cout<<"Cout de coupe normalisé moyen : "<<moy<<std::endl;
 	std::cout<<"Cout de coupe normalisé moyen : "<<moy<<std::endl;
 	std::cout<<"Étendu du coût de coupe : "<<etendu<<std::endl;
 	std::cout<<"Étendu du coût de coupe : "<<etendu<<std::endl;
     std::cout << "Duration : " << t.elapsed() << " seconds" << std::endl;
     std::cout << "Duration : " << t.elapsed() << " seconds" << std::endl;
-	std::cout << std::endl;
+	std::cout << std::endl;*/
 	
 	
 	     
 	     
    /*for(int i =0; i<graphs.size(); i++){
    /*for(int i =0; i<graphs.size(); i++){
@@ -166,10 +332,11 @@ int main()
 	}
 	}
 	fichier2<<"}"<<std::endl;
 	fichier2<<"}"<<std::endl;
 	fichier2.close();
 	fichier2.close();
-	*/
+	
 
 
 
 
-	delete go;
+	delete go;*/
 	
 	
-	std::cout << "Duration : " << t.elapsed()/100 << " seconds" << std::endl;
+	std::cout << "Duration : " << t.elapsed()/nbr_tirage << " seconds" << std::endl;
+	return 0;
 }
 }

+ 701 - 38
src/tests/boost_graph/partitioning/utils.cpp

@@ -28,6 +28,7 @@
 
 
 #include <algorithm>
 #include <algorithm>
 #include <iostream>
 #include <iostream>
+#include <fstream>
 
 
 namespace paradevs { namespace tests { namespace boost_graph {
 namespace paradevs { namespace tests { namespace boost_graph {
 
 
@@ -49,6 +50,12 @@ struct myclass2
     { return Calcul_poids(i,g) < Calcul_poids(j,g); }
     { return Calcul_poids(i,g) < Calcul_poids(j,g); }
 } mon_tri;
 } mon_tri;
 
 
+struct myclass3
+{
+	bool operator() (Entiers *i, Entiers *j)
+	{ return i->size() > j->size(); }
+} myobject_taille;
+
 /**
 /**
  * Fonction de verification de la connexité d'un graphe
  * Fonction de verification de la connexité d'un graphe
  * @param *g : adresse d'un graphe de type boost graphe undirected
  * @param *g : adresse d'un graphe de type boost graphe undirected
@@ -420,7 +427,6 @@ Entiers Neigh_community(UnorientedGraph *g, EntiersEntiers &Partition, int verte
 
 
 void Affinage_recherche_locale(UnorientedGraph *g, EntiersEntiers &Partition, double &cut, std::string name)
 void Affinage_recherche_locale(UnorientedGraph *g, EntiersEntiers &Partition, double &cut, std::string name)
 {
 {
-
     Entiers random_orders(num_vertices(*g)); //gestion d'un tableau contenant tout les sommets et ranger de façon aléatoire
     Entiers random_orders(num_vertices(*g)); //gestion d'un tableau contenant tout les sommets et ranger de façon aléatoire
 
 
     for (uint i=0 ; i<num_vertices(*g) ; i++)
     for (uint i=0 ; i<num_vertices(*g) ; i++)
@@ -443,7 +449,7 @@ void Affinage_recherche_locale(UnorientedGraph *g, EntiersEntiers &Partition, do
     for(uint k = 0; k < Partition.size();k++){
     for(uint k = 0; k < Partition.size();k++){
         std::vector<double> tmp;
         std::vector<double> tmp;
         double vol = 0.;
         double vol = 0.;
-        double cut = Modif_Cut_one_cluster(*Partition.at(k), *g, vol);
+        double cut = Modif_Cut_one_cluster(*Partition.at(k), *g, vol, name);
         tmp.push_back(cut);
         tmp.push_back(cut);
         tmp.push_back(vol);
         tmp.push_back(vol);
         tabe_cut.push_back(tmp);
         tabe_cut.push_back(tmp);
@@ -476,7 +482,7 @@ void Affinage_recherche_locale(UnorientedGraph *g, EntiersEntiers &Partition, do
                     for(uint k = 0; k < Partition.size();k++){
                     for(uint k = 0; k < Partition.size();k++){
                         std::vector<double> tmp;
                         std::vector<double> tmp;
                         double vol = 0.;
                         double vol = 0.;
-                        double cut = Modif_Cut_one_cluster(*Partition.at(k), *g, vol);
+                        double cut = Modif_Cut_one_cluster(*Partition.at(k), *g, vol, name);
                         tmp.push_back(cut);
                         tmp.push_back(cut);
                         tmp.push_back(vol);
                         tmp.push_back(vol);
                         tabe_cut.push_back(tmp);
                         tabe_cut.push_back(tmp);
@@ -485,7 +491,7 @@ void Affinage_recherche_locale(UnorientedGraph *g, EntiersEntiers &Partition, do
                 }
                 }
             }
             }
 
 
-            //Modif_fonction_Gain_Cut(Partition,g,community,vertex,cut,name);
+            Modif_fonction_Gain_Cut(Partition,g,community,vertex,cut,name);
 
 
 
 
             /*if(Est_connexe(g,Partition,*Partition.at(comm))!=1)
             /*if(Est_connexe(g,Partition,*Partition.at(comm))!=1)
@@ -500,22 +506,36 @@ void Affinage_recherche_locale(UnorientedGraph *g, EntiersEntiers &Partition, do
     }
     }
 }
 }
 
 
-double Modif_Cut_one_cluster(Entiers &cluster, UnorientedGraph &g, double &vol)
+double Modif_Cut_one_cluster(Entiers &cluster, UnorientedGraph &g, double &vol, std::string name)
 {
 {
 	edge_t e1;
 	edge_t e1;
 	bool found;
 	bool found;
-	double cpt=0.;
-	for(uint i=0;i<cluster.size();i++){
-		tie(neighbourIt, neighbourEnd) = adjacent_vertices(cluster.at(i), g);
-		for (; neighbourIt != neighbourEnd; ++neighbourIt){
-			tie(e1,found)=edge(vertex(cluster[i],g),vertex(*neighbourIt,g),g);
-			if(In_tab(cluster,*neighbourIt)!=1){
-				cpt+=g[e1]._weight;
+	double cpt= 0.;
+	
+	if(name == "norm"){
+		for(uint i=0;i<cluster.size();i++){
+			tie(neighbourIt, neighbourEnd) = adjacent_vertices(cluster.at(i), g);
+			for (; neighbourIt != neighbourEnd; ++neighbourIt){
+				tie(e1,found)=edge(vertex(cluster[i],g),vertex(*neighbourIt,g),g);
+				if(In_tab(cluster,*neighbourIt)!=1){
+					cpt+=g[e1]._weight;
+				}
 			}
 			}
 		}
 		}
+		vol = Cluster_Degree(g,cluster);
+	} else if(name == "ratio"){
+		for(uint i=0;i<cluster.size();i++){
+			tie(neighbourIt, neighbourEnd) = adjacent_vertices(cluster.at(i), g);
+			for (; neighbourIt != neighbourEnd; ++neighbourIt){
+				tie(e1,found)=edge(vertex(cluster[i],g),vertex(*neighbourIt,g),g);
+				if(In_tab(cluster,*neighbourIt)!=1){
+					cpt+=g[e1]._weight;
+				}
+			}
+		}
+		vol = Cluster_Weight(g,cluster);
 	}
 	}
-	vol = Cluster_Degree(g,cluster);
-	return cpt/2.;
+	return cpt;
 
 
 }
 }
 
 
@@ -524,7 +544,7 @@ std::vector<double> modif_cut_tmp(UnorientedGraph *g, EntiersEntiers &Partition,
 	bool found;
 	bool found;
 	//std::cout<<"le sommet tiré est : "<<vertexs<<std::endl;
 	//std::cout<<"le sommet tiré est : "<<vertexs<<std::endl;
 
 
-	if(name!="norm")
+	if(name == "cut")
 	{
 	{
 		std::vector<double> modif_cut(community.size());
 		std::vector<double> modif_cut(community.size());
 		double cpt_comm_in;
 		double cpt_comm_in;
@@ -550,7 +570,7 @@ std::vector<double> modif_cut_tmp(UnorientedGraph *g, EntiersEntiers &Partition,
 		}
 		}
 		return modif_cut;
 		return modif_cut;
 	}
 	}
-	else{
+	else if(name == "norm"){
 		std::vector<double> modif_cut(community.size());
 		std::vector<double> modif_cut(community.size());
 		double cpt_comm_in;
 		double cpt_comm_in;
 		double cpt_comm_out;
 		double cpt_comm_out;
@@ -587,6 +607,45 @@ std::vector<double> modif_cut_tmp(UnorientedGraph *g, EntiersEntiers &Partition,
 				tmp_cut+=((tab_cut.at(j).at(0))/(tab_cut.at(j).at(1)));
 				tmp_cut+=((tab_cut.at(j).at(0))/(tab_cut.at(j).at(1)));
 			}
 			}
 
 
+			modif_cut.at(i)=tmp_cut;
+		}
+	}else if(name == "ratio"){
+		std::vector<double> modif_cut(community.size());
+		double cpt_comm_in;
+		double cpt_comm_out;
+		double tmp_cut;
+
+		for(uint i =0; i<community.size(); i++){
+			std::vector<std::vector<double> > tab_cut = tabe_cut;
+
+			tmp_cut =0.;
+			cpt_comm_in=0.;
+			cpt_comm_out=0.;
+
+			tie(neighbourIt, neighbourEnd) = adjacent_vertices(vertexs,*g);
+			for (; neighbourIt != neighbourEnd; ++neighbourIt){
+				tie(e1,found)=edge(vertex(vertexs,*g),vertex(*neighbourIt,*g),*g);
+				if(In_tab(*Partition.at(comm_in),*neighbourIt)==1)
+					cpt_comm_in+=(*g)[e1]._weight;
+				else if(In_tab(*Partition.at(community.at(i)),*neighbourIt)==1)
+					cpt_comm_out+=(*g)[e1]._weight;
+			}
+
+			/*cpt_comm_in/=2.;
+			cpt_comm_out/=2.;*/
+
+			tab_cut.at(comm_in).at(0)+=cpt_comm_in;
+			tab_cut.at(comm_in).at(0)-=cpt_comm_out;
+			tab_cut.at(comm_in).at(1)-= (*g)[vertexs]._weight;
+
+			tab_cut.at(community.at(i)).at(0)+=cpt_comm_in;
+			tab_cut.at(community.at(i)).at(0)-=cpt_comm_out;
+			tab_cut.at(community.at(i)).at(1)+= (*g)[vertexs]._weight;
+
+			for(uint j = 0; j < tab_cut.size();j++){
+				tmp_cut+=((tab_cut.at(j).at(0))/(tab_cut.at(j).at(1)));
+			}
+
 			modif_cut.at(i)=tmp_cut;
 			modif_cut.at(i)=tmp_cut;
 		}
 		}
 		return modif_cut;
 		return modif_cut;
@@ -661,8 +720,7 @@ void Modif_fonction_Gain_Cut(EntiersEntiers &Partition,UnorientedGraph *g, Entie
 }
 }
 
 
 bool contraction_HEM(UnorientedGraph *g, Base_Graph &baseg, ListEntiersEntiers &liste_corr, int val_reduc, int &val_cpt){
 bool contraction_HEM(UnorientedGraph *g, Base_Graph &baseg, ListEntiersEntiers &liste_corr, int val_reduc, int &val_cpt){
-	UnorientedGraph *gtmp = new UnorientedGraph();
-	*gtmp=*g;
+	UnorientedGraph *gtmp = new UnorientedGraph(*g);
 	Entiers Random_list_vertices; // Initialisation du tableau de sommets rangés aléatoirements
 	Entiers Random_list_vertices; // Initialisation du tableau de sommets rangés aléatoirements
 	EntiersEntiers *tableau_de_correspondance = new EntiersEntiers();
 	EntiersEntiers *tableau_de_correspondance = new EntiersEntiers();
 	edge_t e1,e2; // Iterateurs sur les arcs
 	edge_t e1,e2; // Iterateurs sur les arcs
@@ -694,7 +752,7 @@ bool contraction_HEM(UnorientedGraph *g, Base_Graph &baseg, ListEntiersEntiers &
 				/*
 				/*
 				 * S'il en existe au mois un sommet adjacent au sommet tiré qui n'est pas verrouillé, on
 				 * S'il en existe au mois un sommet adjacent au sommet tiré qui n'est pas verrouillé, on
 				 * choisi celui dont l'arc les reliants est le plus fort. Dans le cas où les arcs ont tous
 				 * choisi celui dont l'arc les reliants est le plus fort. Dans le cas où les arcs ont tous
-				 * le même poids, on selectionne le sommet d'identifiant le plus petit
+				 * le même poids, on selectionne le sommet d'index le plus petit
 				 */
 				 */
 				double poids_a = 0.;
 				double poids_a = 0.;
 				int best_vertexs = -1;
 				int best_vertexs = -1;
@@ -708,7 +766,7 @@ bool contraction_HEM(UnorientedGraph *g, Base_Graph &baseg, ListEntiersEntiers &
 
 
 
 
 				Entiers * couple = new Entiers(); // Initialisation du vecteur contenant le couple de sommet fusionné
 				Entiers * couple = new Entiers(); // Initialisation du vecteur contenant le couple de sommet fusionné
-				int vertex_delete = std::max(vertexs, best_vertexs); // Sommet d'indentifiant le plus grand (qui sera détruit)
+				int vertex_delete = std::max(vertexs, best_vertexs); // Sommet d'index le plus grand (qui sera détruit)
 				//std::cout<<"sommet détruit : "<<vertex_delete<<std::endl;
 				//std::cout<<"sommet détruit : "<<vertex_delete<<std::endl;
 				int vertex_save = std::min(vertexs,best_vertexs); // Sommet d'identifiant le plus petit (qui sera conservé)
 				int vertex_save = std::min(vertexs,best_vertexs); // Sommet d'identifiant le plus petit (qui sera conservé)
 				//std::cout<<"sommet sauvé : "<<vertex_save<<std::endl;
 				//std::cout<<"sommet sauvé : "<<vertex_save<<std::endl;
@@ -1192,7 +1250,7 @@ double Cut_one_cluster(const Entiers &cluster, UnorientedGraph &g, std::string n
 			}
 			}
 		}
 		}
 		double vol = Cluster_Weight(g,cluster);
 		double vol = Cluster_Weight(g,cluster);
-		return cpt/vol;
+		return (cpt/2.)/vol;
 	}
 	}
 	
 	
 	/*Vérification de la formule : doute sur le /2.*/
 	/*Vérification de la formule : doute sur le /2.*/
@@ -1261,6 +1319,16 @@ double Cluster_Degree(UnorientedGraph &g , const Entiers &cluster)
     return val;
     return val;
 }
 }
 
 
+double Cluster_Weight(UnorientedGraph &g , const Entiers &cluster)
+{
+    double val = 0.;
+
+    for(uint i = 0; i < cluster.size(); i++){
+        val += g[cluster.at(i)]._weight;;
+    }
+    return val;
+}
+
 void List_edge_partie(Entiers *Partie, OrientedGraph *go, Edges &edge_partie,
 void List_edge_partie(Entiers *Partie, OrientedGraph *go, Edges &edge_partie,
                       OutputEdges &outputedgespartie){
                       OutputEdges &outputedgespartie){
     edge_to e1;
     edge_to e1;
@@ -1390,18 +1458,6 @@ OrientedGraphs Graph_Partition(const EntiersEntiers& Partition,
     return graph_partie;
     return graph_partie;
 }
 }
 
 
-
-
-double Cluster_Weight(UnorientedGraph &g , const Entiers &cluster)
-{
-    double val = 0.;
-
-    for(uint i = 0; i < cluster.size(); i++){
-        val += g[cluster.at(i)]._weight;;
-    }
-    return val;
-}
-
 double Best_Cut_cluster(EntiersEntiers &tab_cluster,Entiers *cluster1, Entiers *cluster2, int index_cluster1, UnorientedGraph &g,std::string name)
 double Best_Cut_cluster(EntiersEntiers &tab_cluster,Entiers *cluster1, Entiers *cluster2, int index_cluster1, UnorientedGraph &g,std::string name)
 {
 {
 	tab_cluster.push_back(cluster2);
 	tab_cluster.push_back(cluster2);
@@ -1613,21 +1669,628 @@ void adjacence_ggp(int vertex, Entiers &sommets_adj, UnorientedGraph *g)
 
 
 }
 }
 
 
-float modif_Cout_coupe(const Entiers &P, int val, float cut, UnorientedGraph *g)
+double modif_Cout_coupe(const Entiers &P, int val, double cut, UnorientedGraph *g)
 {
 {
     //std::cout<<"Cout de coupe initiale : "<<cut<<std::endl;
     //std::cout<<"Cout de coupe initiale : "<<cut<<std::endl;
     //std::cout<<"degré du sommet tiré : "<<Degree(*g,val)<<std::endl;
     //std::cout<<"degré du sommet tiré : "<<Degree(*g,val)<<std::endl;
-    double cpt=0;
-    float new_cut;
+    double cpt = 0.;
+    double new_cut;
+    bool found;
+	edge_t e1;
     tie(neighbourIt, neighbourEnd) = adjacent_vertices(val, *g);
     tie(neighbourIt, neighbourEnd) = adjacent_vertices(val, *g);
     for (; neighbourIt != neighbourEnd; neighbourIt++){
     for (; neighbourIt != neighbourEnd; neighbourIt++){
         if(In_tab(P,*neighbourIt)==1){
         if(In_tab(P,*neighbourIt)==1){
-            cpt++;
+			tie(e1,found)=edge(vertex(val,*g),vertex(*neighbourIt,*g),*g);
+            cpt += (*g)[e1]._weight;
         }
         }
     }
     }
-    new_cut = cut + (Degree(*g,val) - (2 * cpt));
+    new_cut = cut + (Degree(*g,val) - 2*cpt);
     return new_cut;
     return new_cut;
 }
 }
 
 
+int decimal(int valeur){
+	int res;
+	switch(valeur){
+		case 0 ... 9 : res = 0;
+		break;
+		case 10 ... 99 : res = 1;
+		break;
+		case 100 ... 999 : res = 2;
+		break;
+		case 1000 ... 9999 : res = 3;
+		break;
+		case 10000 ... 99999 : res = 4;
+		break;
+		case 100000 ... 999999 : res = 5;
+		break;
+		case 1000000 ... 9999999 : res = 6;
+		break;
+		case 10000000 ... 99999999 : res = 7;
+		break;
+		case 100000000 ... 999999999 : res = 8;
+		break;
+	default : 
+		std::cout<<"L'interval n'est pas de taille suffisante"<<std::endl;
+		break;
+	}
+	return res;
+}
+
+void Graph_constructor_txt(const char* text, OrientedGraph * Og){
+	
+	//Traitement initial
+	std::ifstream fichier (text, std::ios::in);
+	int lines = std::count(std::istreambuf_iterator<char>( fichier ),
+	std::istreambuf_iterator<char>(),'\n' );
+	//std::cout<<"Nombre de ligne : "<<lines<<std::endl;
+	
+	fichier.seekg(0, std::ios::beg);
+	std::string caractere;
+	getline(fichier, caractere);
+	int caractere_size = caractere.size()+1;
+	
+	fichier.seekg(0, std::ios::beg);
+	int nbr_vertices;
+	fichier >> nbr_vertices;
+	//std::cout << "Nombre de sommets : "<< nbr_vertices<< std::endl;
+	
+	//Création des sommets
+	
+	std::vector<vertex_to> vect_vertex;
+	for(int i =0; i<nbr_vertices; i++){
+		vertex_to v0 = boost::add_vertex(*Og);
+		vect_vertex.push_back(v0);
+	}
+	
+	//Création des arcs
+	int deplacement_sup = 0;
+	for(int i = 0; i <(lines-nbr_vertices-1); i++){
+	fichier.seekg((8)*i+caractere_size+deplacement_sup, std::ios::beg);
+	int vertex_in, vertex_out;
+	double weight;
+	fichier >> vertex_in >> vertex_out >> weight ; 
+	add_edge(vect_vertex.at(vertex_in), vect_vertex.at(vertex_out), EdgeProperties(weight), *Og); 
+	//std::cout << vertex_in << " " << vertex_out << " " << weight << std::endl; 
+	int tmp = decimal(vertex_in) + decimal(vertex_out) + decimal(floor(weight));
+	deplacement_sup += tmp;
+	}
+	
+	//Pondération des sommets
+	int cpt =0;
+	for(int i = lines-nbr_vertices-1; i <lines-1; i++){
+	fichier.seekg((8)*(lines-nbr_vertices-1)+caractere_size+deplacement_sup, std::ios::beg);
+	double poids;
+	std::string txt;
+	fichier >> poids >> txt ;
+	DynamicsType type;
+	if(txt == "NORMAL_PIXEL"){
+		type = NORMAL_PIXEL; 
+	}else{
+		type = TOP_PIXEL;
+	}
+	(*Og)[vect_vertex.at(cpt)] = VertexProperties(cpt, poids, type);
+	//std::cout << poids << std::endl; 
+	int tmp = decimal(floor(poids)) + 17;
+	deplacement_sup += tmp;
+	cpt++;
+	}
+
+	fichier.close();
+}
+
+void Text_generator_graph(const char *texte, OrientedGraph *go){
+	
+	bool found;
+	edge_to e1;
+	std::ofstream fichier (texte, std::ios::out);
+    fichier<<num_vertices(*go)<<std::endl;
+    tie(vertexIto, vertexEndo) = vertices(*go);
+    for (; vertexIto != vertexEndo; ++vertexIto) {
+    	tie(neighbourIto, neighbourEndo) = adjacent_vertices(*vertexIto,
+    			*go);
+    	for (; neighbourIto != neighbourEndo; ++neighbourIto){
+			tie(e1,found)=edge(vertex(*vertexIto,*go),vertex(*neighbourIto,*go),*go);
+			if(((*go)[e1]._weight - floor((*go)[e1]._weight)) == 0 ){
+				fichier<<(*go)[*vertexIto]._index<<" "<<(*go)[*neighbourIto]._index<<" "<<(*go)[e1]._weight<<".0"<<std::endl;
+			}else{
+				fichier<<(*go)[*vertexIto]._index<<" "<<(*go)[*neighbourIto]._index<<" "<<(*go)[e1]._weight<<std::endl;
+			}
+    	}
+    }
+    tie(vertexIto, vertexEndo) = vertices(*go);
+    for (; vertexIto != vertexEndo; ++vertexIto) {
+		if(((*go)[*vertexIto]._weight - floor((*go)[*vertexIto]._weight)) == 0 && (*go)[*vertexIto]._type == TOP_PIXEL){
+			fichier<<(*go)[*vertexIto]._weight<<".0"<<" "<<"TOP_PIXEL"<<"   "<<std::endl;
+		}else if(((*go)[*vertexIto]._weight - floor((*go)[*vertexIto]._weight)) == 0 && (*go)[*vertexIto]._type == NORMAL_PIXEL){
+			fichier<<(*go)[*vertexIto]._weight<<".0"<<" "<<"NORMAL_PIXEL"<<std::endl;
+		}else if(((*go)[*vertexIto]._weight - floor((*go)[*vertexIto]._weight)) != 0 && (*go)[*vertexIto]._type == TOP_PIXEL){
+			fichier<<(*go)[*vertexIto]._weight<<" "<<"TOP_PIXEL"<<std::endl;
+		}else{
+			fichier<<(*go)[*vertexIto]._weight<<" "<<"NORMAL_PIXEL"<<std::endl;
+		}
+    }
+    
+	fichier.close();
+}
+
+double Diff_cut_ratio(UnorientedGraph *g, const EntiersEntiers &Partition, int partie, int node, std::string name){
+	double Dif;
+	double Int = 0.;
+	double Ext = 0.;
+	
+	edge_t e1;
+    bool found;
+
+    tie(neighbourIt, neighbourEnd) = adjacent_vertices(node, *g);
+    for (; neighbourIt != neighbourEnd; ++neighbourIt){
+		tie(e1, found) = edge(vertex(node, *g), vertex(*neighbourIt, *g), *g);
+		if(In_tab_dichotomie(*Partition.at(partie),*neighbourIt) == 1){
+			Int+= (*g)[e1]._weight;
+		}else{
+			Ext+= (*g)[e1]._weight;
+		}
+    }
+    
+	if(name == "ratio"){
+	    Int/=Cluster_Weight(*g,*Partition.at(partie));
+	    Ext/=Cluster_Weight(*g,*Partition.at(partie));
+	}
+	
+	Dif = Ext - Int;
+	return Dif;
+}
+
+double Diff_cut_ratio_bissection(UnorientedGraph *g, Entiers *part, int node, std::string name){
+	double Ext = 0.;
+	
+	edge_t e1;
+    bool found;
+
+    tie(neighbourIt, neighbourEnd) = adjacent_vertices(node, *g);
+    for (; neighbourIt != neighbourEnd; ++neighbourIt){
+		tie(e1, found) = edge(vertex(node, *g), vertex(*neighbourIt, *g), *g);
+		if(In_tab_dichotomie(*part,*neighbourIt) != 1){
+			Ext+= (*g)[e1]._weight;
+		}
+    }
+	
+	return Ext;
+}
+
+std::vector<std::vector<int>> Vector_diff_cut_ratio(UnorientedGraph *g, const EntiersEntiers &Partition, std::string name){
+	std::vector<std::vector<int>> Diff_vector;
+	
+	for(uint i = 0; i < Partition.size(); i++){
+		std::vector<std::pair<double,int>> D_vector;
+		for(uint j = 0; j < Partition.at(i)->size(); j++){
+			double gain_d = Diff_cut_ratio(g, Partition, i, Partition.at(i)->at(j), name);
+			//std::cout<<gain_d<<std::endl;
+			if(gain_d > 0){
+				std::pair<double, int> D;
+				D.first =  gain_d;
+				D.second = Partition.at(i)->at(j);
+				D_vector.push_back(D);		
+			}	
+		}
+		sort(D_vector.begin(),D_vector.end());
+		std::reverse(D_vector.begin(),D_vector.end());
+		std::vector<int> index_vector;
+		for(uint id = 0; id < D_vector.size(); id++){
+			index_vector.push_back(D_vector.at(id).second);
+		}
+		Diff_vector.push_back(index_vector);
+	}
+	
+	/*std::cout<<"Tableau des différences "<<std::endl;
+	for(uint i = 0; i<Diff_vector.size(); i++){
+		std::cout<<"*"<<i<<"* ";
+		for(uint j = 0; j<Diff_vector.at(i).size(); j++){
+			std::cout<<Diff_vector.at(i).at(j)<<" ";
+		}
+		std::cout<<std::endl;
+	}*/
+	
+	return Diff_vector;
+
+}
+
+std::vector<int> Vector_diff_cut_ratio_2(UnorientedGraph *g, const EntiersEntiers &Partition, std::string name){
+	std::vector<int> Diff_vector;
+	std::vector<std::pair<double,int>> D_vector;
+	for(uint i = 0; i < Partition.size(); i++){
+		for(uint j = 0; j < Partition.at(i)->size(); j++){
+			double gain_d = Diff_cut_ratio(g, Partition, i, Partition.at(i)->at(j), name);
+			//std::cout<<gain_d<<std::endl;
+			if(gain_d > 0){
+				std::pair<double, int> D;
+				D.first =  gain_d;
+				D.second = Partition.at(i)->at(j);
+				D_vector.push_back(D);		
+			}	
+		}
+	}
+	sort(D_vector.begin(),D_vector.end());
+	for(uint id = 0; id < D_vector.size(); id++){
+		Diff_vector.push_back(D_vector.at(id).second);
+	}
+	
+	/*std::cout<<"Tableau des différences "<<std::endl;
+	for(uint i = 0; i<Diff_vector.size(); i++){
+		std::cout<<"*"<<i<<"* ";
+		for(uint j = 0; j<Diff_vector.at(i).size(); j++){
+			std::cout<<Diff_vector.at(i).at(j)<<" ";
+		}
+		std::cout<<std::endl;
+	}*/
+	/*for(uint j = 0; j<Diff_vector.size(); j++){
+		std::cout<<Diff_vector.at(j)<<" ";
+	}
+	std::cout<<std::endl;*/
+	
+	return Diff_vector;
+
+}
+
+void Modif_vector_diff_cut_ratio_2(UnorientedGraph *g, const EntiersEntiers &Partition, std::vector<int> &Diff_vector, int node, std::string name){
+	std::vector<std::pair<double,int>> D_vector;
+	
+	tie(neighbourIt, neighbourEnd) = adjacent_vertices(node, *g);
+	for (; neighbourIt != neighbourEnd; ++neighbourIt){
+		//std::cout<<"node : "<<node<<std::endl;
+		//std::cout<<"voisin : "<<*neighbourIt<<std::endl;
+		int neigh_ind = In_community_dichotomie(Partition, *neighbourIt);
+		//std::cout<<"dans  : "<<neigh_ind<<std::endl;
+		double gain_d = Diff_cut_ratio(g, Partition, neigh_ind, *neighbourIt, name);
+		//std::cout<<"gain_d : "<<gain_d<<std::endl;
+		if(gain_d > 0){
+			std::pair<double, int> D;
+			D.first =  gain_d;
+			D.second = *neighbourIt;
+			D_vector.push_back(D);		
+		}
+		//suprim_val(Diff_vector,*neighbourIt);
+	}
+	
+	if(D_vector.size() == 0){
+		Diff_vector.erase(Diff_vector.begin());
+		return;
+	}
+	
+	//std::cout<<"**"<<std::endl;
+	sort(D_vector.begin(),D_vector.end());
+	for(uint id = 0; id < D_vector.size(); id++){
+		if(In_tab(Diff_vector,D_vector.at(id).second) != 1)
+			Diff_vector.push_back(D_vector.at(id).second);
+	}
+	//std::cout<<"***"<<std::endl;
+	Diff_vector.erase(Diff_vector.begin());
+	//std::cout<<"**!**"<<std::endl;
+	
+	sort(Diff_vector.begin(),Diff_vector.end());
+	
+	for(uint j = 0; j<Diff_vector.size(); j++){
+		std::cout<<Diff_vector.at(j)<<" ";
+	}
+	//std::cout<<std::endl;
+}
+
+void Modif_vector_diff_cut_ratio(UnorientedGraph *g, const EntiersEntiers &Partition, std::vector<std::vector<int>> &Diff_vector, int recalcul1, int recalcul2, std::string name){
+	
+	std::vector<std::pair<double,int>> D_vector;
+	for(uint j = 0; j < Partition.at(recalcul1)->size(); j++){
+		double gain_d = Diff_cut_ratio(g, Partition, recalcul1, Partition.at(recalcul1)->at(j), name);
+		//std::cout<<gain_d<<std::endl;
+		if(gain_d > 0){
+			std::pair<double, int> D;
+			D.first =  gain_d;
+			D.second = Partition.at(recalcul1)->at(j);
+			D_vector.push_back(D);		
+		}	
+	}
+	sort(D_vector.begin(),D_vector.end());
+	std::reverse(D_vector.begin(),D_vector.end());
+	std::vector<int> index_vector;
+	for(uint id = 0; id < D_vector.size(); id++){
+		index_vector.push_back(D_vector.at(id).second);
+	}
+	Diff_vector.at(recalcul1) = index_vector;
+	
+	std::vector<std::pair<double,int>> D_vector2;
+	for(uint j = 0; j < Partition.at(recalcul2)->size(); j++){
+		double gain_d = Diff_cut_ratio(g, Partition, recalcul2, Partition.at(recalcul2)->at(j), name);
+		//std::cout<<gain_d<<std::endl;
+		if(gain_d > 0){
+			std::pair<double, int> D;
+			D.first =  gain_d;
+			D.second = Partition.at(recalcul2)->at(j);
+			D_vector2.push_back(D);		
+		}	
+	}
+	sort(D_vector2.begin(),D_vector2.end());
+	std::reverse(D_vector2.begin(),D_vector2.end());
+	std::vector<int> index_vector2;
+	for(uint id = 0; id < D_vector2.size(); id++){
+		index_vector2.push_back(D_vector2.at(id).second);
+	}
+	Diff_vector.at(recalcul2) = index_vector2;
+	
+	/*std::cout<<"Tableau des différences modifié "<<std::endl;
+	for(uint i = 0; i<Diff_vector.size(); i++){
+		std::cout<<"*"<<i<<"* ";
+		for(uint j = 0; j<Diff_vector.at(i).size(); j++){
+			std::cout<<Diff_vector.at(i).at(j)<<" ";
+		}
+		std::cout<<std::endl;
+	}*/
+		
+}
+
+void Affinache_gain_diff(UnorientedGraph *g, EntiersEntiers &Partition, double &cut, std::string name, double poids_moy){
+	double old_cut = -1.;
+	
+	while(old_cut != cut){
+		//std::cout<<"Boucle d'ammélioration "<<std::endl;
+		old_cut = cut;
+		sort(Partition.begin(), Partition.end(), myobject_taille);
+		std::vector<std::vector<int>> diff_vector;
+		diff_vector = Vector_diff_cut_ratio(g, Partition, name);
+		
+		for(uint indice = 0; indice < diff_vector.size(); indice ++){
+			if(diff_vector.at(indice).size() != 0 && Partition.at(indice)->size() >1){
+				//for(uint i = 0; i < diff_vector.at(indice).size(); i++){
+				int i =0;
+				while(diff_vector.at(indice).size() != 0 && Partition.at(indice)->size() >1 && i < diff_vector.at(indice).size() && 
+				Cluster_Weight(*g,*Partition.at(indice)) > (poids_moy-poids_moy/Partition.size())){
+					//std::cout<<"Sommet de départ : "<< diff_vector.at(indice).at(i) <<" dans "<<indice<<std::endl;
+					Entiers neigh_part;
+					neigh_part = Neigh_community(g, Partition, diff_vector.at(indice).at(i), indice);
+					int best_neigh_part = neigh_part.at(0);
+					double gain = -10000000.;
+					for(uint ind_neigh = 0; ind_neigh < neigh_part.size(); ind_neigh++){
+						double tmp_gain;
+						if(name == "ratio"){
+							tmp_gain = Gain_ratio(g,Partition,indice,neigh_part.at(ind_neigh),diff_vector.at(indice).at(i),cut);
+						}else{
+							double Int = 0.;
+							double Ext = 0.;
+							edge_t e1;
+						    bool found;
+						
+						    tie(neighbourIt, neighbourEnd) = adjacent_vertices(diff_vector.at(indice).at(i), *g);
+						    for (; neighbourIt != neighbourEnd; ++neighbourIt){
+								tie(e1, found) = edge(vertex(diff_vector.at(indice).at(i), *g), vertex(*neighbourIt, *g), *g);
+								if(In_tab_dichotomie(*Partition.at(neigh_part.at(ind_neigh)),*neighbourIt) == 1){
+									Ext+= (*g)[e1]._weight;
+								}else if(In_tab_dichotomie(*Partition.at(indice),*neighbourIt) == 1){
+									Int+= (*g)[e1]._weight;
+								}
+						    }
+								tmp_gain = Ext - Int;
+						}
+						
+					    if(tmp_gain > gain & tmp_gain > 0){
+							gain = tmp_gain;
+							best_neigh_part = neigh_part.at(ind_neigh);
+						}
+					}
+					
+					//std::cout<<" Ensemble de déstination "<<best_neigh_part<<" gain de  : "<<gain<<std::endl;
+					if(gain > 0){
+						//std::cout<<"Modification"<<std::endl;
+						cut -= gain; /*Grosse modification a apporté de ce coté la*/
+						//std::cout<<"Ratio de coupe : "<<cut<<std::endl;
+						suprim_val(*Partition.at(indice),diff_vector.at(indice).at(i));
+						Partition.at(best_neigh_part)->push_back(diff_vector.at(indice).at(i));
+						sort(Partition.at(best_neigh_part)->begin(),Partition.at(best_neigh_part)->end());
+						//double cut2 = Cut_cluster(Partition,*g,"ratio");
+						//std::cout<<"Vrai ratio de coupe : "<<cut2<<std::endl;
+						Modif_vector_diff_cut_ratio(g,Partition,diff_vector,best_neigh_part,indice,name);
+						i = 0;
+					}else{
+						i++;
+					}			
+				}
+			}
+		}
+		//std::cout<<cut<<std::endl;
+	}
+}
+
+void Affinache_gain_diff_2(UnorientedGraph *g, EntiersEntiers &Partition, double &cut, std::string name, double poids_moy){
+	double old_cut = -1.;
+	
+	//while(old_cut != cut){
+		//std::cout<<"Boucle d'ammélioration "<<std::endl;
+		//old_cut = cut;
+		sort(Partition.begin(), Partition.end(), myobject_taille);
+		std::vector<int> diff_vector;
+		diff_vector = Vector_diff_cut_ratio_2(g, Partition, name);
+		
+		//for(uint indice = 0; indice < diff_vector.size(); indice ++){
+		int indice = 0;
+		while(/*indice < diff_vector.size() &&*/ diff_vector.size() != 0){
+			int com = In_community_dichotomie(Partition,diff_vector.at(indice));
+			std::cout<<" Ensemble de départ "<<com<<" sommet  : "<<diff_vector.at(indice)<<std::endl;
+			if(Partition.at(com)->size() >1 && Cluster_Weight(*g,*Partition.at(com)) > (poids_moy-poids_moy/Partition.size())){
+				Entiers neigh_part;
+				neigh_part = Neigh_community(g, Partition, diff_vector.at(indice), com);
+				int best_neigh_part = neigh_part.at(0);
+				double gain = -10000000.;
+				for(uint ind_neigh = 0; ind_neigh < neigh_part.size(); ind_neigh++){
+					double tmp_gain;
+					if(name == "ratio"){
+						tmp_gain = Gain_ratio(g,Partition,com,neigh_part.at(ind_neigh),diff_vector.at(indice),cut);
+					}else{
+						double Int = 0.;
+						double Ext = 0.;
+						edge_t e1;
+					    bool found;
+					
+					    tie(neighbourIt, neighbourEnd) = adjacent_vertices(diff_vector.at(indice), *g);
+					    for (; neighbourIt != neighbourEnd; ++neighbourIt){
+							tie(e1, found) = edge(vertex(diff_vector.at(indice), *g), vertex(*neighbourIt, *g), *g);
+							if(In_tab_dichotomie(*Partition.at(neigh_part.at(ind_neigh)),*neighbourIt) == 1){
+								Ext+= (*g)[e1]._weight;
+							}else if(In_tab_dichotomie(*Partition.at(com),*neighbourIt) == 1){
+								Int+= (*g)[e1]._weight;
+							}
+					    }
+							tmp_gain = Ext - Int;
+					}
+					
+				    if(tmp_gain > gain & tmp_gain > 0){
+						gain = tmp_gain;
+						best_neigh_part = neigh_part.at(ind_neigh);
+					}
+				}
+				
+				std::cout<<" Ensemble de déstination "<<best_neigh_part<<" gain de  : "<<gain<<std::endl;
+				if(gain > 0){
+					std::cout<<"Modification"<<std::endl;
+					cut -= gain; /*Grosse modification a apporté de ce coté la*/
+					std::cout<<"Ratio de coupe : "<<cut<<std::endl;
+					suprim_val(*Partition.at(com),diff_vector.at(indice));
+					Partition.at(best_neigh_part)->push_back(diff_vector.at(indice));
+					sort(Partition.at(best_neigh_part)->begin(),Partition.at(best_neigh_part)->end());
+					double cut2 = Cut_cluster(Partition,*g,"ratio");
+					std::cout<<"Vrai ratio de coupe : "<<cut2<<std::endl;
+					//Modif_vector_diff_cut_ratio_2(g,Partition,diff_vector,diff_vector.at(indice),name);
+					//indice = 0;
+					diff_vector.erase(diff_vector.begin());
+				}else{
+					diff_vector.erase(diff_vector.begin());
+				}
+			}
+		}
+		//std::cout<<cut<<std::endl;
+//	}
+}
+
+double Gain_ratio(UnorientedGraph *g,const EntiersEntiers &Partition, int in, int out, int node, double ratio){
+	double new_ratio = ratio;
+	double poids_in = Cluster_Weight(*g,*Partition.at(in));
+	double poids_out = Cluster_Weight(*g,*Partition.at(out));
+	double tmp_poids_in = poids_in - (*g)[node]._weight;
+	double tmp_poids_out = poids_out + (*g)[node]._weight;
+	//std::cout<<"tmp_poids_in "<< tmp_poids_in <<std::endl;
+	//std::cout<<"tmp_poids_out "<< tmp_poids_out <<std::endl;
+	
+	double cut_in = 0.;
+	double cut_out = 0.;
+	double tmp_cut_in = 0.;
+	double tmp_cut_out = 0.;
+	
+	edge_t e1;
+	bool found;
+	
+	for(uint i = 0; i < Partition.at(in)->size(); i++){
+		tie(neighbourIt, neighbourEnd) = adjacent_vertices(Partition.at(in)->at(i), *g);
+		for (; neighbourIt != neighbourEnd; ++neighbourIt){
+			tie(e1,found)=edge(vertex(Partition.at(in)->at(i),*g),vertex(*neighbourIt,*g),*g);
+			if(In_tab_dichotomie(*Partition.at(in),*neighbourIt) != 1){
+				if(Partition.at(in)->at(i) != node){
+					tmp_cut_in += (*g)[e1]._weight;
+				}
+				cut_in += (*g)[e1]._weight;
+			}else if(*neighbourIt == node){
+				tmp_cut_in += (*g)[e1]._weight;
+			}
+		}
+	}
+	
+	for(uint i = 0; i < Partition.at(out)->size(); i++){
+		tie(neighbourIt, neighbourEnd) = adjacent_vertices(Partition.at(out)->at(i), *g);
+		for (; neighbourIt != neighbourEnd; ++neighbourIt){
+			tie(e1,found)=edge(vertex(Partition.at(out)->at(i),*g),vertex(*neighbourIt,*g),*g);
+			if(In_tab_dichotomie(*Partition.at(out),*neighbourIt) != 1){
+				if(*neighbourIt != node){
+					tmp_cut_out += (*g)[e1]._weight;
+				}
+				cut_out += (*g)[e1]._weight;
+			}
+		}
+	}
+	tie(neighbourIt, neighbourEnd) = adjacent_vertices(node, *g);
+	for (; neighbourIt != neighbourEnd; ++neighbourIt){
+		tie(e1,found)=edge(vertex(node,*g),vertex(*neighbourIt,*g),*g);
+		if(In_tab_dichotomie(*Partition.at(out),*neighbourIt) != 1){
+			tmp_cut_out += (*g)[e1]._weight;
+		}
+	}
+	
+	//std::cout<<"tmp_cut_in "<< tmp_cut_in/2. <<std::endl;
+	//std::cout<<"tmp_cut_out "<< tmp_cut_out/2. <<std::endl;
+	new_ratio -= cut_in/2./poids_in;
+	new_ratio -= cut_out/2./poids_out;
+	new_ratio += tmp_cut_in/2./tmp_poids_in;
+	new_ratio += tmp_cut_out/2./tmp_poids_out;
+	
+	//std::cout<<"Nouveau ratio : " <<new_ratio<<std::endl;
+	return ratio - new_ratio;
+	
+}
+
+double Modif_ratio_cut(UnorientedGraph *g,Entiers *Ss, Entiers *Sd, int node, double ratio){/*Revoir cette fonction, modification psa forcement nécéssaire, plus simple !!!*/
+	double new_ratio;
+	double poids_in = Cluster_Weight(*g,*Ss);
+	double poids_out = Cluster_Weight(*g,*Sd);
+	double tmp_poids_in = poids_in - (*g)[node]._weight;
+	double tmp_poids_out = poids_out + (*g)[node]._weight;
+	//std::cout<<"tmp_poids_in "<< tmp_poids_in <<std::endl;
+	//std::cout<<"tmp_poids_out "<< tmp_poids_out <<std::endl;
+	
+	double new_cut = 0.;
+	//double new_cut_out = 0.;
+	//double tmp_cut_in = 0.;
+	//double tmp_cut_out = 0.;
+	
+	edge_t e1;
+	bool found;
+	
+	for(uint i = 0; i < Ss->size(); i++){
+		if(Ss->at(i) != node){
+			tie(neighbourIt, neighbourEnd) = adjacent_vertices(Ss->at(i), *g);
+			for (; neighbourIt != neighbourEnd; ++neighbourIt){
+				tie(e1,found)=edge(vertex(Ss->at(i),*g),vertex(*neighbourIt,*g),*g);
+				if(In_tab_dichotomie(*Ss,*neighbourIt) != 1){
+					new_cut += (*g)[e1]._weight;
+				}else if(*neighbourIt == node){
+					new_cut += (*g)[e1]._weight;
+				}
+			}
+		}
+	}
+	
+	/*for(uint i = 0; i < Sd->size(); i++){
+		tie(neighbourIt, neighbourEnd) = adjacent_vertices(Sd->at(i), *g);
+		for (; neighbourIt != neighbourEnd; ++neighbourIt){
+			tie(e1,found)=edge(vertex(Sd->at(i),*g),vertex(*neighbourIt,*g),*g);
+			if(In_tab(*Sd,*neighbourIt) != 1){
+				if(*neighbourIt != node){
+					tmp_cut_out += (*g)[e1]._weight;
+				}
+				cut_out += (*g)[e1]._weight;
+			}
+		}
+	}
+	tie(neighbourIt, neighbourEnd) = adjacent_vertices(node, *g);
+	for (; neighbourIt != neighbourEnd; ++neighbourIt){
+		tie(e1,found)=edge(vertex(node,*g),vertex(*neighbourIt,*g),*g);
+		if(In_tab(*Sd,*neighbourIt) != 1){
+			tmp_cut_out += (*g)[e1]._weight;
+		}
+	}*/
+	
+	//std::cout<<"tmp_cut_in "<< tmp_cut_in/2. <<std::endl;
+	//std::cout<<"tmp_cut_out "<< tmp_cut_out/2. <<std::endl;
+	new_ratio = new_cut/2./tmp_poids_in + new_cut/2./tmp_poids_out;
+	/*new_ratio -= cut_out/2./poids_out;
+	new_ratio += tmp_cut_in/2./tmp_poids_in;
+	new_ratio += tmp_cut_out/2./tmp_poids_out;*/
+	
+	//std::cout<<"Nouveau ratio : " <<new_ratio<<std::endl;
+	return new_ratio;
+	
+}
 
 
 } } } // namespace paradevs tests boost_graph
 } } } // namespace paradevs tests boost_graph

+ 15 - 2
src/tests/boost_graph/partitioning/utils.hpp

@@ -47,7 +47,7 @@ void List_edge_partie(Entiers *Partie, OrientedGraph *go, Edges &edge_partie,
 
 
 void construire_graph(UnorientedGraph *g, OrientedGraph *graph);
 void construire_graph(UnorientedGraph *g, OrientedGraph *graph);
 
 
-double Modif_Cut_one_cluster(Entiers &cluster, UnorientedGraph &g, double &vol);
+double Modif_Cut_one_cluster(Entiers &cluster, UnorientedGraph &g, double &vol, std::string name);
 
 
 std::vector<double> modif_cut_tmp(UnorientedGraph *g, EntiersEntiers &Partition,
 std::vector<double> modif_cut_tmp(UnorientedGraph *g, EntiersEntiers &Partition,
                              std::vector<std::vector<double> > tabe_cut,
                              std::vector<std::vector<double> > tabe_cut,
@@ -107,10 +107,23 @@ void make_unoriented_graph(const OrientedGraph& og, UnorientedGraph& uog);
 
 
 void adjacence_ggp(int vertex, Entiers &sommets_adj, UnorientedGraph *g);
 void adjacence_ggp(int vertex, Entiers &sommets_adj, UnorientedGraph *g);
 
 
-float modif_Cout_coupe(const Entiers &P, int val, float cut, UnorientedGraph *g);
+double modif_Cout_coupe(const Entiers &P, int val, double cut, UnorientedGraph *g);
 double Cluster_Weight(UnorientedGraph &g , const Entiers &cluster);
 double Cluster_Weight(UnorientedGraph &g , const Entiers &cluster);
 double Best_Cut_cluster(EntiersEntiers &tab_cluster,Entiers *cluster1, Entiers *cluster2, int index_cluster1, UnorientedGraph &g,std::string name);
 double Best_Cut_cluster(EntiersEntiers &tab_cluster,Entiers *cluster1, Entiers *cluster2, int index_cluster1, UnorientedGraph &g,std::string name);
 
 
+void Text_generator_graph(const char *texte, OrientedGraph *go);
+void Graph_constructor_txt(const char* text, OrientedGraph * Og);
+int decimal(int valeur);
+double Diff_cut_ratio(UnorientedGraph *g, const EntiersEntiers &Partition, int partie, int node, std::string name);
+std::vector<std::vector<int>> Vector_diff_cut_ratio(UnorientedGraph *g, const EntiersEntiers &Partition, std::string name);
+void Affinache_gain_diff(UnorientedGraph *g, EntiersEntiers &Partition, double &cut, std::string name, double poids_moy);
+void Modif_vector_diff_cut_ratio(UnorientedGraph *g, const EntiersEntiers &Partition, std::vector<std::vector<int>> &Diff_vector, int recalcul1, int recalcul2, std::string name);
+double Gain_ratio(UnorientedGraph *g,const EntiersEntiers &Partition, int in, int out, int node, double ratio);
+std::vector<int> Vector_diff_cut_ratio_2(UnorientedGraph *g, const EntiersEntiers &Partition, std::string name);
+void Modif_vector_diff_cut_ratio_2(UnorientedGraph *g, const EntiersEntiers &Partition, std::vector<int> &Diff_vector, int node, std::string name);
+void Affinache_gain_diff_2(UnorientedGraph *g, EntiersEntiers &Partition, double &cut, std::string name, double poids_moy);
+double Modif_ratio_cut(UnorientedGraph *g,Entiers *Ss, Entiers *Sd, int node, double ratio);
+double Diff_cut_ratio_bissection(UnorientedGraph *g, Entiers *part, int node, std::string name);
 } } } // namespace paradevs tests boost_graph
 } } } // namespace paradevs tests boost_graph
 
 
 #endif
 #endif

+ 121 - 26
src/tests/boost_graph/tests.cpp

@@ -147,7 +147,8 @@ void test(double duration, std::string partitioning_method_name,
           GraphGenerator& g)
           GraphGenerator& g)
 {
 {
     boost::timer t;
     boost::timer t;
-
+	int nbr_ite = 20;
+	
     log_file << "==== " << partitioning_method_name << " with ";
     log_file << "==== " << partitioning_method_name << " with ";
     if (contraction_coef_flag) {
     if (contraction_coef_flag) {
         log_file << "/";
         log_file << "/";
@@ -168,7 +169,7 @@ void test(double duration, std::string partitioning_method_name,
             if (heap) {
             if (heap) {
                 double t1 = t.elapsed();
                 double t1 = t.elapsed();
 
 
-                for (unsigned int i = 0; i < 10; ++i) {
+                for (unsigned int i = 0; i < nbr_ite; ++i) {
                     partitionning_heap_test(duration, n,
                     partitionning_heap_test(duration, n,
                                             partitioning_method_name,
                                             partitioning_method_name,
                                             contraction_coef,
                                             contraction_coef,
@@ -177,12 +178,12 @@ void test(double duration, std::string partitioning_method_name,
 
 
                 double t2 = t.elapsed();
                 double t2 = t.elapsed();
 
 
-                log_file << (t2 - t1) / 10 << "\t";
+                log_file << (t2 - t1) / nbr_ite << "\t";
             }
             }
             if (vector) {
             if (vector) {
                 double t1 = t.elapsed();
                 double t1 = t.elapsed();
 
 
-                for (unsigned int i = 0; i < 10; ++i) {
+                for (unsigned int i = 0; i < nbr_ite; ++i) {
                     partitionning_vector_test(duration, n,
                     partitionning_vector_test(duration, n,
                                               partitioning_method_name,
                                               partitioning_method_name,
                                               contraction_coef,
                                               contraction_coef,
@@ -191,7 +192,7 @@ void test(double duration, std::string partitioning_method_name,
 
 
                 double t2 = t.elapsed();
                 double t2 = t.elapsed();
 
 
-                log_file << (t2 - t1) / 10 << std::endl;
+                log_file << (t2 - t1) / nbr_ite << std::endl;
             } else {
             } else {
                 log_file << std::endl;
                 log_file << std::endl;
             }
             }
@@ -202,7 +203,7 @@ void test(double duration, std::string partitioning_method_name,
         if (heap) {
         if (heap) {
             double t1 = t.elapsed();
             double t1 = t.elapsed();
 
 
-            for (unsigned int i = 0; i < 10; ++i) {
+            for (unsigned int i = 0; i < nbr_ite; ++i) {
                 partitionning_heap_test(duration, contraction_coef,
                 partitionning_heap_test(duration, contraction_coef,
                                         partitioning_method_name,
                                         partitioning_method_name,
                                         contraction_coef,
                                         contraction_coef,
@@ -211,12 +212,12 @@ void test(double duration, std::string partitioning_method_name,
 
 
             double t2 = t.elapsed();
             double t2 = t.elapsed();
 
 
-            log_file << (t2 - t1) / 10 << "\t";
+            log_file << (t2 - t1) / nbr_ite << "\t";
         }
         }
         if (vector) {
         if (vector) {
             double t1 = t.elapsed();
             double t1 = t.elapsed();
 
 
-            for (unsigned int i = 0; i < 10; ++i) {
+            for (unsigned int i = 0; i < nbr_ite; ++i) {
                 partitionning_vector_test(duration, contraction_coef,
                 partitionning_vector_test(duration, contraction_coef,
                                           partitioning_method_name,
                                           partitioning_method_name,
                                           contraction_coef,
                                           contraction_coef,
@@ -225,7 +226,7 @@ void test(double duration, std::string partitioning_method_name,
 
 
             double t2 = t.elapsed();
             double t2 = t.elapsed();
 
 
-            log_file << (t2 - t1) / 10 << std::endl;
+            log_file << (t2 - t1) / nbr_ite << std::endl;
         } else {
         } else {
             log_file << std::endl;
             log_file << std::endl;
         }
         }
@@ -284,47 +285,57 @@ void test_partitioning_38()
 
 
 /* random graph */
 /* random graph */
 
 
-const double duration_random = 20;
+const double duration_random = 0;
 
 
 void test_flat_random()
 void test_flat_random()
 {
 {
     boost::timer t;
     boost::timer t;
+    int nbr_ite = 20;
 
 
     log_file << "== Random Graph ==" << std::endl;
     log_file << "== Random Graph ==" << std::endl;
     log_file << "flat graph with heap = ";
     log_file << "flat graph with heap = ";
-    for (unsigned int i = 0; i < 10; ++i) {
+    for (unsigned int i = 0; i < nbr_ite; ++i) {
         flat_heap_test< RandomFlatGraphBuilder >(duration_random);
         flat_heap_test< RandomFlatGraphBuilder >(duration_random);
     }
     }
 
 
     double t2 = t.elapsed();
     double t2 = t.elapsed();
 
 
-    log_file << t2 / 10 << std::endl;
+    /*log_file << t2 / 10 << std::endl;
 
 
     log_file << "flat graph with vector = ";
     log_file << "flat graph with vector = ";
     for (unsigned int i = 0; i < 10; ++i) {
     for (unsigned int i = 0; i < 10; ++i) {
         flat_vector_test< FlatGraphBuilder >(duration_random);
         flat_vector_test< FlatGraphBuilder >(duration_random);
     }
     }
 
 
-    double t3 = t.elapsed();
+    double t3 = t.elapsed();*/
 
 
-    log_file << (t3 - t2) / 10 << std::endl;
+    //log_file << (t3 - t2) / 10 << std::endl;
+    log_file << t2 / nbr_ite << std::endl;
 }
 }
 
 
 void test_partitioning_random()
 void test_partitioning_random()
 {
 {
-    std::vector < int > levels = { 4, 3, 2  };
-    RandomGraphGenerator g(3000, levels, 5, 2, 4);
+    std::vector < int > levels = { 5, 4, 3, 2  };
+    int nbr_sommets = 6000;
+    int sources = nbr_sommets/100*1;
+    RandomGraphGenerator g(nbr_sommets, levels, sources, 2, 3);
 
 
-    test < RandomGraphGenerator >(duration_random, "gggp_pond", 2, 32, 2,
-                                  false, true, 5, true, g);
-    test < RandomGraphGenerator >(duration_random, "gggp_pond", 2, 32, 2,
+    /*test < RandomGraphGenerator >(duration_random, "gggp_pond", 2, 32, 2,
+                                  false, true, 5, true, g);*/
+    test < RandomGraphGenerator >(duration_random, "gggp_pond", 2, 50, 2,
                                   false, true, 10, true, g);
                                   false, true, 10, true, g);
-    test < RandomGraphGenerator >(duration_random, "gggp_pond", 2, 32, 2,
+    test < RandomGraphGenerator >(duration_random, "gggp_pond", 2, 50, 2,
                                   false, true, 20, true, g);
                                   false, true, 20, true, g);
-    test < RandomGraphGenerator >(duration_random, "gggp_pond", 2, 32, 2,
+    test < RandomGraphGenerator >(duration_random, "gggp_pond", 2, 50, 2,
                                   false, true, 40, true, g);
                                   false, true, 40, true, g);
-    test < RandomGraphGenerator >(duration_random, "gggp_pond", 2, 22, 2,
+    test < RandomGraphGenerator >(duration_random, "gggp_pond", 2, 50, 2,
+                                  false, true, 60, true, g);
+    /*test < RandomGraphGenerator >(duration_random, "gggp_pond", 2, 32, 2,
+                                  false, true, 80, true, g);   
+    test < RandomGraphGenerator >(duration_random, "gggp_pond", 2, 32, 2,
                                   false, true, 100, true, g);
                                   false, true, 100, true, g);
+    /*test < RandomGraphGenerator >(duration_random, "gggp_pond", 2, 30, 2,
+                                  false, true, 200, true, g);*/
 
 
     /*test < RandomGraphGenerator >(duration_random, "gggp_pond", 2, 32, 2,
     /*test < RandomGraphGenerator >(duration_random, "gggp_pond", 2, 32, 2,
                                   false, true, 15, false, g);
                                   false, true, 15, false, g);
@@ -351,10 +362,14 @@ void test_partitioning_random()
                                   false, true, 20, true, g);
                                   false, true, 20, true, g);
     test < RandomGraphGenerator >(duration_random, "ggp", 2, 32, 2,
     test < RandomGraphGenerator >(duration_random, "ggp", 2, 32, 2,
                                   false, true, 40, true, g);
                                   false, true, 40, true, g);
-    test < RandomGraphGenerator >(duration_random, "ggp", 2, 22, 2,
-                                  false, true, 100, true, g);
-
     test < RandomGraphGenerator >(duration_random, "ggp", 2, 32, 2,
     test < RandomGraphGenerator >(duration_random, "ggp", 2, 32, 2,
+                                  false, true, 60, true, g);
+    test < RandomGraphGenerator >(duration_random, "ggp", 2, 32, 2,
+                                  false, true, 80, true, g);   
+    test < RandomGraphGenerator >(duration_random, "ggp", 2, 30, 2,
+                                  false, true, 100, true, g);*/
+
+    /*test < RandomGraphGenerator >(duration_random, "ggp", 2, 32, 2,
                                   false, true, 15, false, g);
                                   false, true, 15, false, g);
     test < RandomGraphGenerator >(duration_random, "ggp", 2, 32, 2,
     test < RandomGraphGenerator >(duration_random, "ggp", 2, 32, 2,
                                   false, true, 20, false, g);
                                   false, true, 20, false, g);
@@ -384,6 +399,76 @@ void test_partitioning_random()
 
 
 }
 }
 
 
+const double duration_random_linked = 0;
+
+void test_flat_random_linked()
+{
+    boost::timer t;
+    int nbr_ite = 20;
+
+    log_file << "== Random Linked Graph ==" << std::endl;
+    log_file << "flat graph with heap = ";
+    for (unsigned int i = 0; i < nbr_ite; ++i) {
+        flat_heap_test< RandomLinkedFlatGraphBuilder >(duration_random_linked);
+    }
+
+    double t2 = t.elapsed();
+
+    /*log_file << t2 / 10 << std::endl;
+
+    log_file << "flat graph with vector = ";
+    for (unsigned int i = 0; i < 10; ++i) {
+        flat_vector_test< FlatGraphBuilder >(duration_random);
+    }
+
+    double t3 = t.elapsed();*/
+
+    //log_file << (t3 - t2) / 10 << std::endl;
+    log_file << t2 / nbr_ite << std::endl;
+}
+
+void test_partitioning_random_linked()
+{
+    unsigned int levels = 60;
+    int nbr_sommets = 6000;
+    RandomLinkedGraphGenerator g(nbr_sommets, levels, 2, 3);
+
+	// gggp
+    /*test < RandomLinkedGraphGenerator >(duration_random_linked, "gggp_pond", 2, 50, 2,
+                                  false, true, 5, true, g);*/
+    test < RandomLinkedGraphGenerator >(duration_random_linked, "gggp_pond", 2, 50, 2,
+                                  false, true, 10, true, g);
+    test < RandomLinkedGraphGenerator >(duration_random_linked, "gggp_pond", 2, 50, 2,
+                                  false, true, 20, true, g);
+    test < RandomLinkedGraphGenerator >(duration_random_linked, "gggp_pond", 2, 50, 2,
+                                  false, true, 40, true, g);
+    test < RandomLinkedGraphGenerator >(duration_random_linked, "gggp_pond", 2, 50, 2,
+                                  false, true, 60, true, g);
+    /*test < RandomLinkedGraphGenerator >(duration_random_linked, "gggp_pond", 2, 50, 2,
+                                  false, true, 80, true, g);   
+    test < RandomLinkedGraphGenerator >(duration_random_linked, "gggp_pond", 2, 50, 2,
+                                  false, true, 100, true, g);
+    test < RandomLinkedGraphGenerator >(duration_random_linked, "gggp_pond", 2, 50, 2,
+                                  false, true, 200, true, g);*/
+                                  
+    // ggp 
+    /*test < RandomLinkedGraphGenerator >(duration_random_linked, "ggp", 2, 50, 2,
+                                  false, true, 5, true, g);
+    test < RandomLinkedGraphGenerator >(duration_random_linked, "ggp", 2, 50, 2,
+                                  false, true, 10, true, g);
+    test < RandomLinkedGraphGenerator >(duration_random_linked, "ggp", 2, 50, 2,
+                                  false, true, 20, true, g);
+    test < RandomLinkedGraphGenerator >(duration_random_linked, "ggp", 2, 50, 2,
+                                  false, true, 40, true, g);
+    test < RandomLinkedGraphGenerator >(duration_random_linked, "ggp", 2, 50, 2,
+                                  false, true, 60, true, g);
+    test < RandomLinkedGraphGenerator >(duration_random_linked, "ggp", 2, 50, 2,
+                                  false, true, 80, true, g);   
+    test < RandomLinkedGraphGenerator >(duration_random_linked, "ggp", 2, 50, 2,
+                                  false, true, 100, true, g);*/
+
+}
+
 /* corsen graph */
 /* corsen graph */
 
 
 const double corsen_duration = 20;
 const double corsen_duration = 20;
@@ -504,6 +589,12 @@ void test_random()
     test_partitioning_random();
     test_partitioning_random();
 }
 }
 
 
+void test_random_linked()
+{
+    test_flat_random_linked();
+    test_partitioning_random_linked();
+}
+
 int main()
 int main()
 {
 {
     srand(7262);
     srand(7262);
@@ -511,8 +602,12 @@ int main()
 	//std::cout<<"Simulation pour graphe 38"<<std::endl;
 	//std::cout<<"Simulation pour graphe 38"<<std::endl;
     //test_38();
     //test_38();
     //std::cout<<std::endl;
     //std::cout<<std::endl;
-    std::cout<<"Simulation pour graphe RANDOM 4000"<<std::endl;
+    //std::cout<<"Simulation pour graphe RANDOM 4000"<<std::endl;
+    //test_random();
+    std::cout<<"Simulation pour graphe RANDOM_TREE 6000"<<std::endl;
     test_random();
     test_random();
+    std::cout<<"Simulation pour graphe RANDOM_LINKED 6000"<<std::endl;
+    test_random_linked();
     //std::cout<<std::endl;
     //std::cout<<std::endl;
     //std::cout<<"Simulation pour graphe CORSEN"<<std::endl;
     //std::cout<<"Simulation pour graphe CORSEN"<<std::endl;
     //test_corsen();
     //test_corsen();