def gbest_idx(swarm):
    """ gbest Neighbourhood topology function.

    Args:
        swarm: list: The list of particles.

    Returns:
        int: The index of the gbest particle.
    """
    best = 0
    cmp = comparator(swarm[best].best_fitness)
    for (idx, particle) in enumerate(swarm):
        if cmp(particle.best_fitness, swarm[best].best_fitness):
            best = idx
    return best