private Individ LeftUnitGreedy(int n = 0) //Обратный удельный жадный алгоритм, начинающий поиск с n-ой компании { Individ data = new Individ(); int counter = numberOfAttachmentSizes - 1; n %= numberOfCompany; int currentPos = (n - 1 + numberOfCompany) % numberOfCompany; while ((counter > 0) && (currentPos != n)) { double maxGain = 0; int pos = 0; for (int j = 1; j < counter + 1; j++) { double gain = (double)tableOfOffers[currentPos, j] / sizeOfAttachment[j]; if (gain >= maxGain) { maxGain = gain; pos = j; } } data.Set(currentPos, pos); counter -= pos; currentPos = (currentPos - 1 + numberOfCompany) % numberOfCompany; } data.Set(currentPos, counter); return(data); }
private Individ RightUnitGreegy(int n = 0) //Прямой удельный жадный алгоритм, начинающий поиск с n-ой компании { Individ data = new Individ(); int limit = n + numberOfCompany - 1; int counter = numberOfAttachmentSizes - 1; int currentPos; while ((counter > 0) && (n < limit)) { double maxGain = 0; int pos = 0; currentPos = n % numberOfCompany; for (int j = 1; j < counter + 1; j++) { double gain = (double)tableOfOffers[currentPos, j] / sizeOfAttachment[j]; if (gain >= maxGain) { maxGain = gain; pos = j; } } data.Set(currentPos, pos); counter -= pos; n++; } data.Set(limit % numberOfCompany, counter); return(data); }