我的问题是关于最大权重的B-匹配问题。在
二部匹配问题对二部图中的两组顶点。最大加权二部匹配(MWM)被定义为匹配中的边值之和具有最大值的匹配。一个著名的多项式时间算法MWM是匈牙利算法。在
我感兴趣的是一个特定的最大加权二部匹配问题,称为加权二部B-匹配问题。权重二部B-匹配问题(WBM)寻求匹配顶点,使得每个顶点匹配的顶点不超过其容量b
所允许的数量。在
这个图(来自Chen et al.)显示了WBM问题。输入图的分数为2.2,即所有边权重的总和。在满足红度约束的所有子图中,解H的蓝边得到的分数最高,为1.6。在
虽然最近有一些关于WBM问题(this和this)的工作,但我找不到该算法的任何实现。有人知道WBM问题在networkX这样的库中是否已经存在吗?在
让我们试着一步一步来做,编写我们自己的函数来解决问题中指定的WBM问题。在
当给定两组节点(u和v、边权值和顶点容量)时,用
pulp
构造和求解加权二部匹配(WBM)并不困难在下面的第2步中,您将找到一个函数(希望很容易理解)将WBM表示为ILP并使用
pulp.
进行求解,看看它是否有帮助。(您需要pip install pulp
)步骤1:设置二部图容量和边权重
第2步:求解WBM(作为整数规划制定)
下面是一些说明,以使下面的代码更易于理解:
一。在
^{pr2}$步骤3:指定图形并调用WBM解算器
这样可以得到:
步骤4:可选地,使用Networkx
蓝边是为WBM选择的边。希望这能帮助你前进。在
相关问题 更多 >
编程相关推荐