Parcourir la source

ajout de la fonction de fusion des arcs dans utils.cpp pour faire fonctionner lifegame

totofeh il y a 9 ans
Parent
commit
e902e7e115

+ 11 - 3
src/tests/boost_graph/partitioning/gggp.cpp

@@ -825,18 +825,25 @@ OrientedGraphs Multiniveau(OrientedGraph *go,
     double t1, t2, t3, t4;
     UnorientedGraph *g = new UnorientedGraph();
 	make_unoriented_graph(*go, *g);
+	UnorientedGraph *copie = new UnorientedGraph();
+	boost::copy_graph(*g,*copie);
+	//Plot_UnorientedGraph(copie,"lifegame.txt");
     Base_Graph baseg;
-    baseg.push_back(g);
+    //baseg.push_back(g);
     ListEntiersEntiers liste_corr;
     OrientedGraphs Graphes;
     int val_cpt = num_vertices(*g);
     bool time = true;
+    
 
     /*Eigen::MatrixXd Madj = adjacence_matrix(g);
 	std::cout << Madj << std::endl << std::endl;*/
 
     if(numeric_parameters.at(0) != val_cpt && parameters.at(1) != "rand" && parameters.at(1) != "rande"){
-
+		
+		simple_graph(copie);
+		baseg.push_back(copie);
+		//Plot_UnorientedGraph(copie,"lifegame2.txt");
 		Coarsening_Phase(baseg, liste_corr, numeric_parameters.at(0), val_cpt, parameters.at(0));
 
 	    if(rec){
@@ -898,7 +905,8 @@ OrientedGraphs Multiniveau(OrientedGraph *go,
 	                              inputedgelist, connections);
 	    if(rec)
 			Plot_OrientedGraph_All(go,Partition,"../../sortie_graphe/Tests/Graphes/Multiniveau/txt/résultat_partitionnement.txt", true);
-
+		
+		delete g;
 		for(uint it = 0 ; it < Partition.size(); it++ )
 		{
 			delete Partition.at(it);

+ 56 - 0
src/tests/boost_graph/partitioning/utils.cpp

@@ -3387,4 +3387,60 @@ double distance_t(std::pair<double,double> x, std::pair<double,double> y)
 	return sqrt(total);
 }
 
+void simple_graph(UnorientedGraph *g)
+{
+	edge_t e1;
+    bool found;
+
+	tie(vertexIt, vertexEnd) = vertices(*g);
+	for (; vertexIt != vertexEnd; ++vertexIt) {
+		tie(neighbourIt, neighbourEnd) = adjacent_vertices(*vertexIt,*g);
+		
+		std::vector<uint> neight;
+		for (; neighbourIt != neighbourEnd; ++neighbourIt)
+			neight.push_back(*neighbourIt);
+		neight.push_back(-2);
+		sort(neight.begin(), neight.end());
+		
+		int tmp = -1;
+		uint cpt = 1;
+		double wi = 0.;
+		
+		for (uint i = 0; i < neight.size(); i++)
+		{
+			if(neight.at(i) > *vertexIt && *vertexIt != num_vertices(*g) - 1)
+			{
+				if(i != neight.size()-1)
+				{
+					tie(e1, found) = edge(vertex(*vertexIt, *g), vertex(neight.at(i), *g), *g);
+					if(tmp == neight.at(i))
+					{
+						wi += (*g)[e1]._weight;
+						cpt++;
+					}
+					else if(tmp != neight.at(i) & cpt != 1.)
+					{
+						remove_edge(*vertexIt,neight.at(i-1),*g);
+						add_edge(*vertexIt, neight.at(i-1), wi, *g);
+						wi = (*g)[e1]._weight;
+						cpt = 1;
+						tmp = neight.at(i);
+					}
+					else
+					{
+						wi = (*g)[e1]._weight;
+						cpt = 1.;
+						tmp = neight.at(i);
+					}
+				}
+				else
+				{
+					remove_edge(*vertexIt,neight.at(i-1),*g);
+					add_edge(*vertexIt, neight.at(i-1), wi, *g);
+				}
+			}
+		}
+	}
+}
+
 } } } // namespace paradevs tests boost_graph

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

@@ -234,6 +234,8 @@ Entiers Random_Sort_Vector2(uint min, uint size);
 
 double distance_t(std::pair<double,double> x, std::pair<double,double> y);
 
+void simple_graph(UnorientedGraph *g);
+
 } } } // namespace paradevs tests boost_graph
 
 #endif

+ 8 - 8
src/tests/multithreading/lifegame/graph_builder.hpp

@@ -35,8 +35,8 @@ using namespace paradevs::tests::boost_graph;
 namespace paradevs { namespace tests {
         namespace multithreading { namespace lifegame {
 
-const int NCOLUMNS = 10;
-const int NLINES = 10;
+const int NCOLUMNS = 5;
+const int NLINES = 5;
 
 class GraphBuilder
 {
@@ -50,21 +50,22 @@ public:
                OutputEdgeList& output_edges,
                Connections& parent_connections)
     {
+        //std::vector < std::string > parameters = {
+        //    "HEM", "rande", "diff", "ratio"
+        //};
         std::vector < std::string > parameters = {
-            "HEM", "rande", "diff", "ratio"
+             "HEM", "gggp", "diff", "ratio"
         };
-        // std::vector < std::string > parameters = {
-        //     "HEM", "gggp", "diff", "ratio"
-        // };
 
         bool contraction_coef_flag = false;
-        uint contraction_coef = 20;
         uint cluster_number = _cluster_number;
         OrientedGraph go;
         Edges edge_partie;
         Connections connections;
 
         generate(go);
+        std::cout << "Nbrs models : " << num_vertices(go) << std::endl;
+        uint contraction_coef = 20;//num_vertices(go);
         output_edges = OutputEdgeList(cluster_number);
         if (contraction_coef_flag) {
             uint coars = num_vertices(go) / contraction_coef;
@@ -93,7 +94,6 @@ private:
     void generate(OrientedGraph& g)
     {
         std::vector < OrientedGraph::vertex_descriptor > vertices;
-
         for (int i = 0; i < NLINES; ++i) {
             for (int j = 0; j < NCOLUMNS; ++j) {
                 vertices.push_back(boost::add_vertex(g));