Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. public int[] TabuSearch() //ricerca locale simile quello di Annealing (con Elba 12302)
  2. {
  3. int[,] TL = new int[GAP.numserv, GAP.numcli];
  4. int DeltaMax, iter = 0, imax=0, jmax = 0;
  5. int Ttenure = (int)Math.Round(2.375 * GAP.numcli);
  6. int totIter = 10000;
  7. {
  8. //per ogni client cerca una possibile riassegnazione dei server; cerca un minimo locale
  9. int[] sol = buildSolution();
  10. var numClient = GAP.numcli;
  11. var numServer = GAP.numserv;
  12. int[] capleft = new int[GAP.cap.Length];
  13. int i, j, tempServer = 0, z=checkSol(sol), upperBound=int.MaxValue;
  14.  
  15. Array.Copy(GAP.cap, capleft, capleft.Length);
  16. for (j = 0; j < numClient; j++)
  17. {
  18. capleft[sol[j]] -= GAP.req[sol[j]][j]; //tolgo capacità già usate
  19. }
  20. do
  21. {
  22. imax = -1;
  23. jmax = -1;
  24. DeltaMax = int.MinValue;
  25. for (j = 0; j < numClient; j++)
  26. {
  27. tempServer = sol[j]; //assegno soluz precedente
  28. for (i = 0; i < numServer; i++)
  29. {
  30. if ((GAP.cost[tempServer][j] - GAP.cost[i][j]) > DeltaMax && (capleft[i] >= GAP.req[i][j]) &&
  31. (TL[i, j]) <= iter)
  32. {
  33. imax = i;
  34. jmax = j;
  35. DeltaMax = GAP.cost[tempServer][j] - GAP.cost[i][j];
  36. }
  37. }
  38. }
  39. if (jmax>=0)
  40. {
  41. tempServer = sol[jmax];
  42. sol[jmax] = imax;
  43. capleft[imax] -= GAP.req[imax][jmax];
  44. capleft[tempServer] += GAP.req[tempServer][jmax];
  45. z -= DeltaMax;
  46. if (z < upperBound) upperBound = z;
  47. TL[imax, jmax] = iter+ Ttenure;
  48.  
  49. }
  50. iter++;
  51. } while (iter < totIter);
  52. return sol;
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement