我有一个加权和非二分图,并希望获得最大权重匹配。我已经使用 python networkx 库完成了这项任务,并正在寻找 java 的替代库。我查看了 JGraphT 库,但找不到解决方案。
import networkx as nx
import networkx.algorithms.matching as matching
G=nx.Graph()
G.add_edge(1,2,weight = 30)
G.add_edge(1,3,weight = 100)
G.add_edge(1,4,weight = 30)
G.add_edge(2,3,weight = 0)
G.add_edge(2,4,weight = 30)
G.add_edge(3,4,weight = 30)
M = matching.max_weight_matching(G,maxcardinality=True)
print(list(M))
//OUTPUT: [(1, 3), (2, 4)]