1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| import networkx as nx
G = nx.Graph() G.add_nodes_from(["F1", "F2", "F3", "F4", "F5"], bipartite=0) G.add_nodes_from(["M1", "M2", "M3", "M4", "M5"], bipartite=1) G.add_weighted_edges_from([ ("F1", "M1", 70), ("F1", "M2", 90), ("F1", "M3", 80), ("F1", "M4", 80), ("F1", "M5", 70), ("F2", "M1", 60), ("F2", "M2", 10), ("F2", "M3", 80), ("F2", "M4", 70), ("F2", "M5", 60), ("F3", "M1", 70), ("F3", "M2", 70), ("F3", "M3", 100), ("F3", "M4", 70), ("F3", "M5", 60), ("F4", "M1", 80), ("F4", "M2", 80), ("F4", "M3", 80), ("F4", "M4", 50), ("F4", "M5", 60), ("F5", "M1", 90), ("F5", "M2", 90), ("F5", "M3", 90), ("F5", "M4", 90), ("F5", "M5", 30) ])
max_matching = nx.max_weight_matching(G) print(max_matching)
|