From bb6cacd898d15bb015af1d90b3eb160b53a7ce30 Mon Sep 17 00:00:00 2001 From: Sven Czarnian Date: Thu, 16 Dec 2021 10:23:40 +0100 Subject: [PATCH] fix an issue in the global update --- aman/sys/aco/Colony.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/aman/sys/aco/Colony.py b/aman/sys/aco/Colony.py index b3526f6..f1fae9f 100644 --- a/aman/sys/aco/Colony.py +++ b/aman/sys/aco/Colony.py @@ -110,10 +110,11 @@ class Colony: if None == bestCandidate or candidate[0] < bestCandidate[0]: bestCandidate = candidate - dTheta = 1.0 / ((candidate[0].total_seconds() / 60.0) or 1.0) - for i in range(1, len(candidate[1])): - update = (1.0 - self.Configuration.Epsilon) * self.PheromoneMatrix[candidate[1][i - 1], candidate[1][i]] + dTheta - self.PheromoneMatrix[candidate[1][i - 1], candidate[1][i]] = max(update, self.Configuration.ThetaZero) + if None != bestSequence: + dTheta = 1.0 / ((bestSequence[0].total_seconds() / 60.0) or 1.0) + for i in range(1, len(bestSequence[1])): + update = (1.0 - self.Configuration.Epsilon) * self.PheromoneMatrix[bestSequence[1][i - 1], bestSequence[1][i]] + self.Configuration.Epsilon * dTheta + self.PheromoneMatrix[bestSequence[1][i - 1], bestSequence[1][i]] = max(update, self.Configuration.ThetaZero) # check if we find a new best candidate if None != bestCandidate: