Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void localFall(std::vector<int> &child, const std::vector<std::vector<int>> &matrix){
- std::vector<int> localBest = child;
- std::vector<int> current;
- std::vector<int> best;
- best.resize(CLIENT_COUNT);
- std::vector<int> bestValue;
- bestValue.resize(CLIENT_COUNT);
- std::vector<int> second;
- second.resize(CLIENT_COUNT);
- std::vector<int> secondValue;
- secondValue.resize(CLIENT_COUNT);
- //int bestScore = function(child, matrix,best,bestValue,second,secondValue);
- int bestScore = function(child, matrix);
- int localScore = bestScore;
- int a = 0;
- while(1){
- int bestScore = function(child, matrix,best,bestValue,second,secondValue);
- // std::cout<<a++<<std::endl;
- int flag = 0;
- for(int i = 0; i < FACILITY_COUNT; i++){
- current = child;
- if(current[i]==0){
- localScore += 3000;
- for(int j = 0; j < CLIENT_COUNT; j++)
- if (matrix[i][j] < bestValue[j]){
- secondValue[j] = bestValue[j];
- second[j] = best[j];
- bestValue[j] = matrix[i][j];
- best[j] = i;
- localScore -= secondValue[j];
- localScore += bestValue[j];
- }
- current[i] = 1;
- //localScore = function(current,matrix);
- if(localScore < bestScore){
- flag = 1;
- bestScore = localScore;
- localBest = current;
- }
- for(int j = i + 1; j < FACILITY_COUNT; j++){
- if(current[i]==1){
- current[i] = 0;
- // localScore = function(current,matrix);
- localScore -= 3000;
- for(int k = 0; k < CLIENT_COUNT; k++){
- if(best[k] == i){
- localScore -= bestValue[j];
- localScore += secondValue[j];
- }
- }
- if(localScore < bestScore){
- bestScore = localScore;
- localBest = current;
- flag = 1;
- }
- current[i] = 1;
- }
- }
- }
- else{
- current[i] = 0;
- //localScore = function(current,matrix);
- localScore -= 3000;
- for(int k = 0; k < CLIENT_COUNT; k++){
- if(best[k] == i){
- localScore -= bestValue[k];
- localScore += secondValue[k];
- }
- }
- if(localScore < bestScore){
- bestScore = localScore;
- localBest = current;
- flag = 1;
- }
- for(int j = i + 1; j < FACILITY_COUNT; j++){
- if(current[i]==0){
- current[i] = 1;
- // localScore = function(current,matrix);
- localScore += 3000;
- for(int j = 0; j < CLIENT_COUNT; j++)
- if (matrix[i][j] < bestValue[j]){
- localScore += matrix[i][j];
- localScore -= bestValue[j];
- }
- if(localScore < bestScore){
- bestScore = localScore;
- localBest = current;
- flag = 1;
- }
- current[i] = 0;
- }
- }
- }
- child = localBest;
- }
- if(flag == 0)
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement