]> AND Private Git Repository - loba.git/blobdiff - loba_lln.cpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
Add option -X <double>, for testing and/or debugging purpose.
[loba.git] / loba_lln.cpp
index 35acb265cd1fb325d9dd453b167eea237e0d0875..0422b38ff5a082e7cd38b1c247a8870b720712a6 100644 (file)
@@ -7,32 +7,34 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba);
 
 void loba_lln::load_balance()
 {
-       std::vector<int>  listLessLoadedNeighbors;
-       unsigned i;
-       double myLoad = get_load();
-       unsigned size = pneigh.size();
-       double *S = new double[size];
-       double lessLoad = get_load();
+    std::vector<int> listLessLoadedNeighbors;
+    unsigned i;
+    double myLoad = get_load();
+    unsigned size = pneigh.size();
+    double *S = new double[size];
+    double lessLoad = get_load();
 
-       listLessLoadedNeighbors.clear();
-               for(i=0;i<size;++i) {
-                       S[i]=0.0;
-                       if( pneigh[i]->get_load()< lessLoad )
-                                       listLessLoadedNeighbors.push_back(i);
-               }
-               int nbLessLoadedNeighbors=listLessLoadedNeighbors.size();
-               for( i=0; i<listLessLoadedNeighbors.size(); ++i) {
-                       double delta = (myLoad-pneigh[listLessLoadedNeighbors[i]]->get_load())/(nbLessLoadedNeighbors+1);
-                       if(myLoad-delta > pneigh[listLessLoadedNeighbors[i]]->get_load()) {
-                               S[i]=delta;
-                               myLoad-=delta;
-                       }
-               }
-               for(i=0; i<size; ++i) {
-                       send(pneigh[i], S[i]);
-                       XBT_DEBUG("sent to %s", pneigh[i]->get_name());
-               }
-       delete[] S;
+    listLessLoadedNeighbors.clear();
+    for (i = 0; i < size; ++i) {
+        S[i] = 0.0;
+        if (pneigh[i]->get_load() < lessLoad)
+            listLessLoadedNeighbors.push_back(i);
+    }
+    int nbLessLoadedNeighbors = listLessLoadedNeighbors.size();
+    for (i = 0; i < listLessLoadedNeighbors.size(); ++i) {
+        double delta =
+            (myLoad - pneigh[listLessLoadedNeighbors[i]]->get_load()) /
+            (nbLessLoadedNeighbors + 1);
+        if (myLoad - delta > pneigh[listLessLoadedNeighbors[i]]->get_load()) {
+            S[i] = delta;
+            myLoad -= delta;
+        }
+    }
+    for (i = 0; i < size; ++i) {
+        send(pneigh[i], S[i]);
+        XBT_DEBUG("sent to %s", pneigh[i]->get_name());
+    }
+    delete[] S;
 }
 
 // Local variables: