Академический Документы
Профессиональный Документы
Культура Документы
ВЫСШЕГО ОБРАЗОВАНИЯ
направление подготовки
09.03.02 «Информационные системы и технологии»
ЛАБОРАТОРНАЯ РАБОТА № 3
Дата, подпись
(Дата) (Подпись)
Проверил:
(Фамилия И.О., степень, звание) (Оценка)
Дата, подпись
(Дата) (Подпись)
Замечания:
2023
Цель работы.
Теоретическое обоснование.
for i in range(nAnts):
tempVisibility = np.array(visibility)
for j in range(nCitys-1):
completedPaths = np.zeros(SizeOfResult)
nextPathProbability = np.zeros(SizeOfResult)
currentTown = int(rute[i, j]-1)
tempVisibility[:, currentTown] = 0
pFeature = np.power(pheromone[currentTown, :], dist)
vFeature = np.power(tempVisibility[currentTown, :], ferImp)
pFeature = pFeature[:, np.newaxis]
vFeature = vFeature[:, np.newaxis]
completedPaths = np.multiply(pFeature, vFeature)
total = np.sum(completedPaths)
probs = completedPaths/total
nextPathProbability = np.cumsum(probs)
r = np.random.random_sample()
city = np.nonzero(nextPathProbability > r)[0][0]+1
rute[i, j+1] = city
left = list(set([i for i in range(1, nCitys+1)])-set(rute[i, :-2]))[0]
rute[i, -2] = left
ruteOpt = np.array(rute) costRt
= np.zeros((nAnts, 1)) for i in
range(nAnts):
s = 0
for j in range(nCitys-1):
s = s + graph[int(ruteOpt[i, j])-1, int(ruteOpt[i, j+1])-1]
costRt[i] = s
distOptPerAnt = np.argmin(costRt)
distOpt = costRt[distOptPerAnt]
optRt = rute[distOptPerAnt, :]
pheromone = (1-ferIsp)*pheromone
for i in range(nAnts):
for j in range(nCitys-1):
dt = 1/costRt[i]
pheromone[int(ruteOpt[i, j])-1, int(ruteOpt[i, j+1]) - 1] =
pheromone[int(ruteOpt[i, j])-1, int(ruteOpt[i, j+1])-1] + dt
print('Лучший путь:', optRt, 'с длиной', int( distOpt[0]) +
graph[int(optRt[-2]) - 1, 0])