From a342e1d5cfd84986cce00d137e592257607ccdea Mon Sep 17 00:00:00 2001
From: Bruno Seny <bruno.seny@student.uclouvain.be>
Date: Mon, 7 Mar 2011 16:45:43 +0000
Subject: [PATCH] Optimized Partitions with weights on edges

---
 Mesh/meshPartition.cpp      | 12 ++++++------
 Mesh/meshPartitionObjects.h |  7 +++++++
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/Mesh/meshPartition.cpp b/Mesh/meshPartition.cpp
index 905b80664d..f55ee7d567 100644
--- a/Mesh/meshPartition.cpp
+++ b/Mesh/meshPartition.cpp
@@ -488,7 +488,7 @@ int PartitionGraph(Graph &graph, meshPartitionOptions &options)
           break;
         case 4:  // Vertices Multi-Contrained Recursive
           Msg::Info("Vertices Multi-Constrained Recursive Algorithm Used");
-          wgtflag = 2;
+          wgtflag = 3;
           metisOptions[0] = 1;
           metisOptions[1] = options.edge_matching;
           metisOptions[2] = 1;
@@ -497,13 +497,13 @@ int PartitionGraph(Graph &graph, meshPartitionOptions &options)
           graph.fillWithMultipleWeights(options.ncon,options.getWeightMap());
           METIS_mCPartGraphRecursive
             (&n,&options.ncon,&graph.xadj[graph.section[iSec]],
-             &graph.adjncy[graph.section[iSec]], &graph.vwgts[graph.section[iSec]], NULL, &wgtflag, &numflag,
+             &graph.adjncy[graph.section[iSec]], &graph.vwgts[graph.section[iSec]],  &graph.adjwgts[graph.section[iSec]], &wgtflag, &numflag,
              &options.num_partitions, metisOptions, &edgeCut,
              &graph.partition[graph.section[iSec]]);
           break;
         case 5:  // Vertices Multi-Constrained K-way
           Msg::Info("Vertices Multi-Constrained K-way Algorithm Used");
-          wgtflag = 2;
+          wgtflag = 3;
           metisOptions[0] = 1;
           metisOptions[1] = options.edge_matching;
           metisOptions[2] = 1;
@@ -511,9 +511,9 @@ int PartitionGraph(Graph &graph, meshPartitionOptions &options)
           metisOptions[4] = 0;
           printf("Tolerance for Constraints:[");
           for(int u=0;u<options.ncon;u++){
-           ubvec[u]=1.0;
+           ubvec[u]=1.03;
            if(options.tolerance[u]%options.num_partitions>0){
-             ubvec[u] = (float) ceil((float)options.tolerance[u]/options.num_partitions)/((float)options.tolerance[u]/options.num_partitions);
+             //ubvec[u] = (float) ceil((float)options.tolerance[u]/options.num_partitions)/((float)options.tolerance[u]/options.num_partitions);
            }
            printf(" %f", ubvec[u]);
           }
@@ -522,7 +522,7 @@ int PartitionGraph(Graph &graph, meshPartitionOptions &options)
           if (options.num_partitions > 1) {
             METIS_mCPartGraphKway
               (&n,&options.ncon,&graph.xadj[graph.section[iSec]],
-               &graph.adjncy[graph.section[iSec]], &graph.vwgts[graph.section[iSec]], NULL, &wgtflag, &numflag,
+               &graph.adjncy[graph.section[iSec]], &graph.vwgts[graph.section[iSec]], &graph.adjwgts[graph.section[iSec]], &wgtflag, &numflag,
                &options.num_partitions,&ubvec[0], metisOptions, &edgeCut,
                &graph.partition[graph.section[iSec]]);
           }
diff --git a/Mesh/meshPartitionObjects.h b/Mesh/meshPartitionObjects.h
index 97830e1f10..26e2b73109 100644
--- a/Mesh/meshPartitionObjects.h
+++ b/Mesh/meshPartitionObjects.h
@@ -91,6 +91,8 @@ class Graph
                                         // vertices.
   std::vector<int> vwgts;               // Weights assigned for each 
                                         // vertex
+  std::vector<int> adjwgts;             // Weights assigned for each 
+                                        // edge
   std::vector<int> section;             // For separate partitioning of
                                         // different parts of the mesh
   std::vector<int> partition;           // The partitions output from the
@@ -136,6 +138,7 @@ class Graph
     xadj.resize(_totalGrVert + 1);
     adjncy.reserve(2*totalGrEdge);
     vwgts.resize(_totalGrVert);
+    adjwgts.reserve(2*totalGrEdge);
     partition.resize(_totalGrVert);
     element.resize(_totalGrVert);
     c2w = new int[_totalGrVert];
@@ -187,11 +190,15 @@ class Graph
   {
     std::vector<MElement*>::iterator eIt;
     vwgts.resize(element.size()*ncon);
+    adjwgts.resize(adjncy.size());
     int localElNum=0;
     for(eIt=element.begin();eIt !=element.end();eIt++){
       for(int i=0; i<ncon; i++){
         vwgts[localElNum*ncon+i]=weightMap[(*eIt)->getNum()][i];
       }
+      for(int j=xadj[localElNum];j<xadj[localElNum+1];j++){
+        adjwgts[j]+=weightMap[(*eIt)->getNum()][0];
+      }
       localElNum+=1;
     }
   }
-- 
GitLab