Advertisement
AlexMatveev

Untitled

May 15th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.67 KB | None | 0 0
  1. void localFall(std::vector<int> &child, const std::vector<std::vector<int>> &matrix){
  2.    
  3.     std::vector<int> localBest = child;
  4.     std::vector<int> current;
  5.     std::vector<int> best;
  6.     best.resize(CLIENT_COUNT);
  7.     std::vector<int> bestValue;
  8.     bestValue.resize(CLIENT_COUNT);
  9.     std::vector<int> second;
  10.     second.resize(CLIENT_COUNT);
  11.     std::vector<int> secondValue;
  12.     secondValue.resize(CLIENT_COUNT);
  13.  
  14.     //int bestScore = function(child, matrix,best,bestValue,second,secondValue);
  15.     int bestScore = function(child, matrix);
  16.     int localScore = bestScore;
  17.     int a = 0;
  18.     while(1){
  19.         int bestScore = function(child, matrix,best,bestValue,second,secondValue);
  20. //      std::cout<<a++<<std::endl;
  21.         int flag = 0;
  22.         for(int i = 0; i < FACILITY_COUNT; i++){
  23.             current = child;
  24.             if(current[i]==0){
  25.                 localScore += 3000;
  26.                 for(int j = 0; j < CLIENT_COUNT; j++)
  27.                     if (matrix[i][j] < bestValue[j]){
  28.                         secondValue[j] = bestValue[j];
  29.                         second[j] = best[j];
  30.                         bestValue[j] = matrix[i][j];
  31.                         best[j] = i;
  32.                         localScore -= secondValue[j];
  33.                         localScore += bestValue[j];
  34.                     }
  35.                 current[i] = 1;
  36.                 //localScore = function(current,matrix);
  37.                 if(localScore < bestScore){
  38.                     flag = 1;
  39.                     bestScore = localScore;
  40.                     localBest = current;
  41.                 }
  42.                 for(int j = i + 1; j < FACILITY_COUNT; j++){
  43.                     if(current[i]==1){
  44.                         current[i] = 0;
  45.                     //  localScore = function(current,matrix);
  46.                         localScore -= 3000;
  47.                         for(int k = 0; k < CLIENT_COUNT; k++){
  48.                             if(best[k] == i){
  49.                                 localScore -= bestValue[j];
  50.                                 localScore += secondValue[j];
  51.                             }
  52.                         }
  53.                         if(localScore < bestScore){
  54.                             bestScore = localScore;
  55.                             localBest = current;
  56.                             flag = 1;
  57.                         }
  58.                         current[i] = 1;
  59.                     }
  60.                 }
  61.             }
  62.             else{
  63.                 current[i] = 0;
  64.                 //localScore = function(current,matrix);
  65.                 localScore -= 3000;
  66.                 for(int k = 0; k < CLIENT_COUNT; k++){
  67.                     if(best[k] == i){
  68.                         localScore -= bestValue[k];
  69.                         localScore += secondValue[k];
  70.                     }
  71.                 }
  72.                 if(localScore < bestScore){
  73.                     bestScore = localScore;
  74.                     localBest = current;
  75.                     flag = 1;
  76.                 }
  77.                 for(int j = i + 1; j < FACILITY_COUNT; j++){
  78.                     if(current[i]==0){
  79.                         current[i] = 1;
  80.                     //  localScore = function(current,matrix);
  81.                         localScore += 3000;
  82.                         for(int j = 0; j < CLIENT_COUNT; j++)
  83.                             if (matrix[i][j] < bestValue[j]){
  84.                                 localScore += matrix[i][j];
  85.                                 localScore -= bestValue[j];
  86.                             }
  87.                         if(localScore < bestScore){
  88.                             bestScore = localScore;
  89.                             localBest = current;
  90.                             flag = 1;
  91.                         }
  92.                         current[i] = 0;
  93.                     }
  94.                 }
  95.             }
  96.             child = localBest;     
  97.         }
  98.         if(flag == 0)
  99.             break;
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement