aco.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:swarmintelligence 作者: davisyoshida 项目源码 文件源码
def _choose_comp(self, comps):
        weights = list((comp, self.pheromones[comp]**self.alpha * heuristic**self.beta) for comp, heuristic in comps)

        # Pseudo-random proportional update (ACS)
        if random.random() < self.q0:
            comp, weight = max(weights, key=itemgetter(1))
            return comp
        else:
            weights = list(itertools.accumulate(weights, lambda acc, t: (t[0], acc[1] + t[1])))
            _, total_weight = weights[-1]
            threshold = random.random() * total_weight
            return next(comp for comp, w in weights if w >= threshold)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号