Directed maximum weighted bipartite matching allowing sharing of start/end vertices

后端 未结 2 2077
耶瑟儿~
耶瑟儿~ 2021-02-02 11:26

Let G (U u V, E) be a weighted directed bipartite graph (i.e. U and V are the two sets of nodes of the bipartite graph and E contains directed weighted edges from U to V or from

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-02 12:25

    Define a new undirected graph G' from G as follows.

    1. G' has a node (A, B) with weight w for each directed edge (A, B) with weight w in G
    2. G' has undirected edge ((A, B),(B, C)) if (A, B) and (B, C) are both directed edges in G

    http://en.wikipedia.org/wiki/Line_graph#Line_digraphs

    Now find a maximal (weighted) independent vertex set in G'.

    http://en.wikipedia.org/wiki/Vertex_independent_set

    Edit: stuff after this point only works if all of the edge weights are the same - when the edge weights have different values its a more difficult problem (google "maximum weight independent vertex set" for possible algorithms)

    Typically this would be an NP-hard problem. However, G' is a bipartite graph -- it contains only even cycles. Finding the maximal (weighted) independent vertex set in a bipartite graph is not NP-hard.

    The algorithm you will run on G' is as follows.

    1. Find the connected components of G', say H_1, H_2, ..., H_k
    2. For each H_i do a 2-coloring (say red and blue) of the nodes. The cookbook approach here is to do a depth-first search on H_i alternating colors. A simple approach would be to color each vertex in H_i based on whether the corresponding edge in G goes from U to V (red) or from V to U (blue).
    3. The two options for which nodes to select from H_i are either all the red nodes or all the blue nodes. Choose the colored node set with higher weight. For example, the red node set has weight equal to H_i.nodes.where(node => node.color == red).sum(node => node.w). Call the higher-weight node set N_i.
    4. Your maximal weighted independent vertex set is now union(N_1, N_2, ..., N_k).

    Since each vertex in G' corresponds to one of the directed edges in G, you have your maximal DirectionalMatching.

提交回复
热议问题