code: def energy(self):
          
          e = 0
          for i in range(len(self.state)):
              e += self.distance_matrix[self.state[i-1]][self.state[i]]
          return e
docs: Calculates the length of the route.