我有一大组代表一组图的顶点/节点。请注意,在这个完整的集合中可能有许多独立的图。目标是找到所有这些图中的最小顶点数,这些顶点对应于那些选定顶点捕获的所有边上的最大权重总和。我在熊猫中有邻接矩阵,我正在使用networkx。
下面是一个包含三列的示例数据框,其中 Number_Of_Trips 是权重。我可以提供 node = 10*trips 的权重,以便将两个指标合并在一起。即最大化旅行次数 - 10*NumberOfNodes
Number_Of_Trips dropoff_gh7 pickup_gh7
0 304 9tbqhsx 9tbqj4g
1 271 9tbqj4f 9tbqhsx
2 263 9tbqt4s 9tbqhsx
3 258 9tbqdye 9tbqdsr
4 256 9tbqhgh 9tbqjfv
5 236 9tbqhsw 9tbqj4g
6 233 9tbqt4g 9tbqv03
7 229 9tbqhsx 9tbqj4c
8 218 9tbqy3f 9tbqt4s
9 213 9tbq5v4 9tbqh41
10 210 9tbqhgh 9tbqhsw
11 192 9tbqhgh 9tbqje4
12 186 9tbqy3f 9tbqt4g
13 184 9tbqhgh 9tbqj4z
14 183 9tbqe3d 9tbqe9e
15 170 9tbq3xn 9tbq39w
16 167 9tbq5bw 9tbqht6
17 163 9tbqhsx 9tbqh0x
18 162 9tbqdk1 9tbq7p2
19 160 9tbqsch 9tbqt4s
x = nx.from_pandas_dataframe(df,"dropoff_gh7","pickup_gh7","Number_Of_Trips")
graphs = list(nx.connected_component_subgraphs(x))