浏览代码

modification mineur de la fonction multiniveau dans le cadre d'un appel sans contraction + méthode de partitionnement aléatoire sans perte de mémoir

totofeh 9 年之前
父节点
当前提交
f65b3d0fe1
共有 2 个文件被更改,包括 58 次插入39 次删除
  1. 47 28
      src/tests/boost_graph/partitioning/gggp.cpp
  2. 11 11
      src/tests/boost_graph/partitioning/main.cpp

+ 47 - 28
src/tests/boost_graph/partitioning/gggp.cpp

@@ -593,20 +593,6 @@ EntiersEntiers Random_partitioning(UnorientedGraph *g,
 	return Partition;
 }
 
-/* std::vector<std::string> parameters :
- * 0 -> contraction    : nom de la méthode de contraction
- * 1 -> type_methode   : nom de la méthode de partitionnement
- * 2 -> choix_affinage : nom de la méthode d'affinage
- * 3 -> type_cut       : nom de la fonction objectif étudiée
- * 
- * std::vector<uint> numeric_parameters :
- * 0 -> niveau_contraction : niveau de contraction à atteindre
- * 1 -> nbr_parties        : nombre de parties de la partition
- * 2 -> nbr_tirage         : nombre de tirage de sommet de depart
- * 3 -> distance           : distance minimum de selection de sommet 
- * 							 de depart par default -1
- */
-
 void Coarsening_Phase(Base_Graph &baseg, ListEntiersEntiers &liste_corr, 
 					  uint niveau, int nbr_vertex, 
 					  std::string parameter){
@@ -629,16 +615,13 @@ EntiersEntiers Partitioning_Phase(const Base_Graph &baseg,
 					const std::vector<uint> &numeric_parameters, 
 					const std::vector<std::string> &parameters, 
 					int distance){
-	
-	EntiersEntiers Partition;
-    Entiers *part = new Entiers();
-    
-	for(uint i = 0; i<num_vertices(*baseg.at(baseg.size() - 1)); i++)
-		part->push_back(i);
-			
-	Partition.push_back(part);
-    
+						
+    EntiersEntiers Partition;
     if(parameters.at(1) == "gggp" || parameters.at(1) == "ggp"){
+		Entiers *part = new Entiers();
+		for(uint i = 0; i<num_vertices(*baseg.at(baseg.size() - 1)); i++)
+			part->push_back(i);
+		Partition.push_back(part);
 		bissectionRec(baseg.at(baseg.size()-1), Partition,
 					  numeric_parameters.at(1), parameters.at(3), 
 					  numeric_parameters.at(2), parameters.at(1), 
@@ -769,6 +752,20 @@ void Uncoarsening_Phase(const Base_Graph &baseg,
 
     }
 }
+
+/* std::vector<std::string> parameters :
+ * 0 -> contraction    : nom de la méthode de contraction
+ * 1 -> type_methode   : nom de la méthode de partitionnement
+ * 2 -> choix_affinage : nom de la méthode d'affinage
+ * 3 -> type_cut       : nom de la fonction objectif étudiée
+ * 
+ * std::vector<uint> numeric_parameters :
+ * 0 -> niveau_contraction : niveau de contraction à atteindre
+ * 1 -> nbr_parties        : nombre de parties de la partition
+ * 2 -> nbr_tirage         : nombre de tirage de sommet de depart
+ * 3 -> distance           : distance minimum de selection de sommet 
+ * 							 de depart par default -1
+ */
 	 
 OrientedGraphs Multiniveau(OrientedGraph *go,
                            const std::vector<uint> &numeric_parameters,
@@ -787,8 +784,10 @@ OrientedGraphs Multiniveau(OrientedGraph *go,
     ListEntiersEntiers liste_corr;
     OrientedGraphs Graphes;
     int val_cpt = num_vertices(*g);
+    bool time = true;
+    double t1, t2, t3, t4;
     
-    if(numeric_parameters.at(0) != val_cpt){
+    if(numeric_parameters.at(0) != val_cpt && parameters.at(1) != "rand"){
 			
 		Coarsening_Phase(baseg, liste_corr, numeric_parameters.at(0), val_cpt, parameters.at(0));
 	    
@@ -803,8 +802,10 @@ OrientedGraphs Multiniveau(OrientedGraph *go,
 			GRAPHp.close();
 		}
 	
-	    //double t2 = t.elapsed();
-	    //std::cout << "C : " << t2 << " ; ";
+		if(time){
+			t2 = t.elapsed();
+			std::cout << "C : " << t2 << " ; ";
+		}
 	    
 	    if(rec)
 			Plot_UnorientedGraph(baseg.at(baseg.size()-1),"../../sortie_graphe/Tests/Graphes/Multiniveau/txt/contraction_final.txt");
@@ -815,8 +816,10 @@ OrientedGraphs Multiniveau(OrientedGraph *go,
 		EntiersEntiers Partition = Partitioning_Phase(baseg, 
 							numeric_parameters, parameters, distance);
 	    
-	    //double t3 = t.elapsed();
-	    //std::cout << "P : " << (t3 - t2) << " ; ";
+	    if(time){
+			t3 = t.elapsed();
+			std::cout << "P : " << (t3 - t2) << " ; ";
+	    }
 	    
 	    if(rec)
 			Plot_UnorientedGraph_All(&copy_graph,Partition,"../../sortie_graphe/Tests/Graphes/Multiniveau/txt/contraction_final_partition.txt", true);
@@ -829,6 +832,14 @@ OrientedGraphs Multiniveau(OrientedGraph *go,
 		
 		Uncoarsening_Phase(baseg, Partition, parameters, 
 								  liste_corr, poids_moy, rec);
+								  
+		if(time){
+			t4 = t.elapsed();
+			std::cout << "A : " << (t4 - t3) << " ; "<<std::endl;
+	    }
+	    
+	    double ratio_cut = Cut_cluster(Partition, *g, parameters.at(3));
+	    std::cout<<"Coût de la fonction objectif : "<<ratio_cut<<std::endl;
 		
 		Graphes = Graph_Partition(Partition, go, g, outputedgelist,
 	                              inputedgelist, connections);
@@ -846,6 +857,14 @@ OrientedGraphs Multiniveau(OrientedGraph *go,
 		EntiersEntiers Partition = Partitioning_Phase(baseg, 
 								   numeric_parameters, parameters, 
 								   distance);
+								   
+		if(time){
+		    t1 = t.elapsed();
+			std::cout << "P : " << t1 << " ; "<<std::endl;
+	    }
+	    
+	    double ratio_cut = Cut_cluster(Partition, *g, parameters.at(3));
+	    std::cout<<"Coût de la fonction objectif : "<<ratio_cut<<std::endl;
 			
 		Graphes = Graph_Partition(Partition, go, copie_g, 
 								  outputedgelist, inputedgelist,

+ 11 - 11
src/tests/boost_graph/partitioning/main.cpp

@@ -48,11 +48,11 @@ int main()
 	/*** Génération du graphe ***/
 	
     OrientedGraph *go = new OrientedGraph();
-    std::string type_graph = "grid";
+    std::string type_graph = "tree";
     std::pair<bool,bool> Spectrale = {false,false};
     
     if(type_graph == "grid"){
-		int side = floor(sqrt(200));
+		int side = floor(sqrt(5000));
 		std::vector<std::pair<int,int>> vertex_selection;
 	    std::pair<int,int> tmp;
 	    tmp.first = 0;
@@ -64,9 +64,9 @@ int main()
 	    build_graph_grid(go, side, vertex_selection, weight_vertex,texte,true);
 	    Plot_OrientedGraph(go,"../../sortie_graphe/Tests/Graphes/Multiniveau/txt/grid_500.txt");
 	}else if (type_graph == "tree"){
-		int nbr_sommets = 1000;
+		int nbr_sommets = 5000;
 		int nbr_sources = nbr_sommets/100*1; 
-		Entiers niveau = {4,3,2};
+		Entiers niveau = {5,4,3,2};
 		build_generator_graph(go, nbr_sommets, nbr_sources , 2 , 4 ,niveau);
 	}else if (type_graph == "linked"){
 		int nbr_sommets = 1000;
@@ -93,8 +93,8 @@ int main()
 	}
 
 	/*** Paramétrage du Multiniveau ***/
-	std::vector<uint> numeric_parameters = {num_vertices(*go), 8, 5};
-	std::vector<std::string> parameters = {"HEM", "gggp", "diff", "ratio"};
+	std::vector<uint> numeric_parameters = {num_vertices(*go)/20, 8, 10};
+	std::vector<std::string> parameters = {"HEM", "rand", "diff", "cut"};
 	
 	uint nbr_tirage = 1;
 	
@@ -104,23 +104,23 @@ int main()
 		InputEdgeList inputedgelist;
 		Connections connections;
 		if(!Spectrale.first){
-			UnorientedGraph *g = new UnorientedGraph();
-			make_unoriented_graph(*go, *g);
 			if(Spectrale.second){
+				UnorientedGraph *g = new UnorientedGraph();
+				make_unoriented_graph(*go, *g);
 				Adjacent_Matrix_Txt(g,"../../Classif_R/Graphe/txt/Madj.txt");
 				Weight_Matrix_Txt(g,"../../Classif_R/Graphe/txt/Mwei.txt");
+				delete g;
 			}
-			delete g;
 			OrientedGraphs graphs = Multiniveau(go, numeric_parameters,
 												parameters, edge_partie ,
 												outputedgeslist, inputedgelist,
-												connections,true, 2);  	
+												connections,true, i);  	
 												std::cout<<std::endl;
 		}else{
 			OrientedGraphs graphs = Multiniveau(go, numeric_parameters,
 												parameters, edge_partie ,
 												outputedgeslist, inputedgelist,
-												connections,true, 2); 
+												connections,true, i); 
 												std::cout<<std::endl;
 		}
 	}