【问题标题】:ILP graph cycle detectionILP图循环检测
【发布时间】:2021-03-25 11:47:02
【问题描述】:

我完全被这个(整数)线性规划公式任务困住了:
输入:包含循环的有向边加权图。
目标:找到一组边,它们的权重之和最小,这样如果从图中删除这些边,图就会变成非循环的。

编辑:对于任何感兴趣的人,我发现(在朋友的帮助下),您可以使用拓扑排序来解决这个问题。您只需要为每条边引入一个约束,这样:
topologicalOrder[ edge.parent ] << topologicalOrder[ edge.child ] + ( M * edgeInactive[edge])
其中topologicalOrder[node] 是节点拓扑位置的整数数组,edgeInactive 是布尔数组,表示边在结果(非循环)图中是否处于活动状态。 M 是用于在 edgeActive[edge] == true 时“关闭”约束的 Big M 方法。
那么你只需要最小化非活动边的权重总和。

旧(较慢)解决方案:
我的想法是创建节点的拓扑排序(对于非循环图,当拓扑排序时,所有边都将从左到右定向),但是当我得到带有循环的图时,我将寻找这样的拓扑排序,即总和从右到左的边数最少。

这种方法有效,但速度很慢......

(我正在尝试用 Gurobi 解决这个问题,但我认为这是非常普遍的线性规划公式问题。) 我的代码:

# Variables
x = model.addVars(nodeCount, nodeCount, vtype=g.GRB.BINARY) # matrix of size nodeCount * nodeCount, where x[i,j] denotes if node i is topologically before node j

#Constraints
for e in edges:
    model.addConstr(x[e.child, e.parent] == 1 - x[e.parent, e.child])  # x[i,j] needs to be equal to negative value of x[j,i]

    for k in range(nodeCount):
        model.addConstr(  x[e.parent, e.child] + x[e.child, k] - x[e.parent, k] <= 1) # Without this constraint solver produced invalid ordering results so I came up with this equation. But I'm not sure if this is the best way to solve this issue..


# Objective
sumNegativeEdges = 0;
for e in edges:
    sumNegativeEdges+= (x[e.child, e.parent]) * e.weight; # Adding just weight of edges where child is topologically before the parent

model.setObjective(sumNegativeEdges, g.GRB.MINIMIZE) 

不胜感激...

【问题讨论】:

    标签: graph-theory mathematical-optimization linear-programming gurobi


    【解决方案1】:

    这看起来像一个(通常)NP 难题:minimum feedback arc set。至少this answer 表明了这一点。

    您可能会使用此关键字找到更多资源。

    当我在Kemeny–Young method

    上做一些 ILP 工作时,我记得阅读过关于 above 问题的 ILP 公式

    在 Google Scholar 上快速查找将我们带到:

    Ali、Alnur 和 Marina Meil​​ă。 “凯梅尼排名实验:什么时候有效?”数学社会科学 64.1 (2012): 28-40。

    上面写着:

    "上面的ILP公式在[10, 28]之前已经给出。这个公式也可以理解为求解最小加权反馈弧 设置问题来自计算机科学 [10, 19]"

    我猜你可能会从这篇论文开始 (Link to pdf as referenced by Google Scholar)

    【讨论】:

    • 谢谢@sascha!知道这个问题有一个名字(最小反馈弧集)在寻找关于这个主题的论文时真的很有帮助。
    【解决方案2】:

    我发现(在朋友的帮助下),您可以使用拓扑排序来解决这个问题。您只需要为每条边引入一个约束,这样:
    topologicalOrder[ edge.parent ] &lt;&lt; topologicalOrder[ edge.child ] + ( M * edgeInactive[edge])
    其中topologicalOrder[node] 是节点拓扑位置的整数数组,edgeInactive 是布尔数组,表示边在结果(非循环)图中是否处于活动状态。 M 是用于在 edgeActive[edge] == true 时“关闭”约束的 Big M 方法。
    那么你只需要最小化非活动边的权重总和。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-19
      • 1970-01-01
      • 2017-06-15
      相关资源
      最近更新 更多