Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int[] TabuSearch() //ricerca locale simile quello di Annealing (con Elba 12302)
- {
- int[,] TL = new int[GAP.numserv, GAP.numcli];
- int DeltaMax, iter = 0, imax=0, jmax = 0;
- int Ttenure = (int)Math.Round(2.375 * GAP.numcli);
- int totIter = 10000;
- {
- //per ogni client cerca una possibile riassegnazione dei server; cerca un minimo locale
- int[] sol = buildSolution();
- var numClient = GAP.numcli;
- var numServer = GAP.numserv;
- int[] capleft = new int[GAP.cap.Length];
- int i, j, tempServer = 0, z=checkSol(sol), upperBound=int.MaxValue;
- Array.Copy(GAP.cap, capleft, capleft.Length);
- for (j = 0; j < numClient; j++)
- {
- capleft[sol[j]] -= GAP.req[sol[j]][j]; //tolgo capacità già usate
- }
- do
- {
- imax = -1;
- jmax = -1;
- DeltaMax = int.MinValue;
- for (j = 0; j < numClient; j++)
- {
- tempServer = sol[j]; //assegno soluz precedente
- for (i = 0; i < numServer; i++)
- {
- if ((GAP.cost[tempServer][j] - GAP.cost[i][j]) > DeltaMax && (capleft[i] >= GAP.req[i][j]) &&
- (TL[i, j]) <= iter)
- {
- imax = i;
- jmax = j;
- DeltaMax = GAP.cost[tempServer][j] - GAP.cost[i][j];
- }
- }
- }
- if (jmax>=0)
- {
- tempServer = sol[jmax];
- sol[jmax] = imax;
- capleft[imax] -= GAP.req[imax][jmax];
- capleft[tempServer] += GAP.req[tempServer][jmax];
- z -= DeltaMax;
- if (z < upperBound) upperBound = z;
- TL[imax, jmax] = iter+ Ttenure;
- }
- iter++;
- } while (iter < totIter);
- return sol;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement