tsp_lazy.py 文件源码

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

项目:PySCIPOpt 作者: SCIP-Interfaces 项目源码 文件源码
def findSubtours(self, checkonly, sol):
        EPS = 1.e-6
        edges = []
        x = self.model.data
        for (i, j) in x:
            if self.model.getSolVal(sol, x[i, j]) > EPS:
                edges.append((i,j))

        G = networkx.Graph()
        G.add_edges_from(edges)
        Components = list(networkx.connected_components(G))

        if len(Components) == 1:
            return False
        elif checkonly:
            return True

        for S in Components:
            self.model.addCons(quicksum(x[i, j] for i in S for j in S if j > i) <= len(S) - 1)
            print("cut: len(%s) <= %s" % (S, len(S) - 1))

        return True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号