Maximum weights bipartite matching with weighted vertices - algorithm

I have a bipartite graph with two sets of vertices A and B. Edges have no weights. However, vertices in one of the sets(say set B) have positive weights assigned to them (wb1,wb2...)
I want to find a matching in this bipartite graph so as to maximize the sum of weights of vertices matched from set B.
After an extensive online search, this is what I have come up with : Assign weight wbi to all edges incident on vertex bi and run the Hungarian algorithm.
Is there a more efficient way to look at this problem, since it's different from weighted maximum matching (here vertices have weights as opposed to edges)
If my language is not clear, feel free to edit. Thank you.

If an improvement from O(V^3) to O(V E) and a simpler algorithm is worth it (it isn't asymptotically for the densest graphs), you could exploit the matroid structure of matchings as follows. Instantiate Ford--Fulkerson by repeatedly choosing a path to an unmatched vertex in B whose weight is as large as possible.

Related

Linear algorithm to make edge weights unique

I have a weighted graph, and I want to compute a new weighting function for the graph, such that the edge weights are distinct, and every MST in the new graph corresponds to an MST in the old graph.
I can't find a feasible algorithm. I doubled all the weights, but that won't make them distinct. I also tried doubling the weights and adding different constants to edges with the same weights, but that doesn't feel right, either.
The new graph will have only 1 MST, since all edges are distinct.
Very simple: we multiply all weights by a factor K large enough to ensure that our small changes cannot affect the validity of an MST. I'll go overboard on this one:
K = max(<sum of all graph weights>,
<quantity of edges>)
+ 1
Number the N edges in any order, 0 through N-1. To each edge weight, add the edge number. It's trivial to show that
the edge weights are now unique (new difference between different weights is larger than the changes);
any MST in the new graph maps directly to a corresponding MST in the
old one (each new path sum is K times the old one, plus a quantity smaller than K -- the comparison (less or greater than) on any two paths cannot be affected).
Yes, this is overkill: you can restrict the value of K quite a bit. However, making it that large reduces the correctness proofs to lemmas a junior-high algebra student can follow.
We definitely cannot guarantee that all of the MSTs in the old graph are MSTs in the new graph; a counterexample is the complete graph on three vertices where all edges have equal weights. So I assume that you do not require the construction to give all MSTs, as that is not possible in the general case.
Can we always make it so that the new graph's MSTs are a subset of the old graph's? This would be easy if we could construct a graph without a MST. Of course, that doesn't make any sense and is impossible, since all graphs have at least one MST. Is it possible to change edge weights so that only one of the old graph's MSTs is an MST for the new graph? I propose that this is possible in general.
Determine some MST of the old graph.
Construct a new graph with the same edges and vertices, but with weights assigned as follows:
if the edge in the new graph belongs to the MST determined in step 1, give it a unique weight between 1 and n, the number of edges in the graph.
otherwise, give the edge in the new graph a unique weight greater than or equal to n^2, the square of the number of edges in the graph.
Without proof, it seems like this should guarantee that only the nominated MST from the old graph is an MST of the new graph, and therefore every MST in the new graph (there is just the one) is an MST in the old graph.
Now, one could ask whether we can do the deed with additional restrictions:
Can you do it if you only want to change the values of edges that are not unique in the old graph?
Can you do it if you want to keep relative weights the same for edges which were unique in the old graph?
One could even pose optimization problems:
What is the minimum number of edge weights that must be changed to guarantee it?
What is the weighting with minimum distance (according to some metric) from the old weighting that guarantees it?
What is the weighting that minimizes the average change while also guaranteeing it?
I am hesitant to attempt these, what I believe to be much more difficult, problems.

Which algorithm+representation should I use for finding minimum path distance in a huge sparse undirected graph?

I need to find the minimum distance between two nodes in a undirected graph, here are some details
The graph is undirected and huge(no of nodes is in order of 100,000)
The graph is sparse, no of edges is less than no of nodes
I am not interested in the actual path, just the distance.
What representation and algorithm should I use for a) Space efficiency b)time efficiency?
EDIT: If it matters,
The wieghts are all non zero positive integers.
No node connects to itself.
Only single edge between two adjacent nodes
It depends on the weights of the edges. If they are non-negative - Dijkstra suits you. If your graph is planar, you can use A*.
If you have negative weights, you have to use Bellman-Ford.

How do I explore a directed graph (DAG) by visting minimum number of starting vertices?

Given a DAG (possibly not strongly connected e.i consisting of several connected components), the goal is to find the minimum number of starting vertices required to visit to fully explore the graph.
One method I thought of was to generate all permutations of the given vertices and run a topological sort in that order. The one with the minimum backtracks would be the answer.
Is there an efficient algorithm to perform the above task?
This a famous problem called minimum path cover, it's a pity that wiki says nothing about it, you can search it in google.
As methioned, the minimum path cover problem is NP-hard in normal graph. But in DAG, it can be solved with Matching.
Method:
Dividing each vertex u into two different vertex u1 and u2. For every edge (u->v) in orginal graph, adding edge (u1->v2) in new graph. Then do any matching algorithm you like. The result is n - maximum matching, n is total number of vertex in orginal graph.

Maximum weighted bipartite matching _with_ directed edges

I know various algorithms to compute the maximum weighted matching of weighted, undirected bipartite graphs (i.e. the assignment problem):
For instance ... The Hungarian Algorithm, Bellman-Ford or even the Blossom algorithm (which works for general, i.e. not bipartite, graphs).
However, how can I compute the maximum weighted matching if the edges of the bipartite graph are weighted and directed?
I would appreciate pointers to algorithms with polinomial complexity or prior transformations to make the graph undirected so that I could apply any of the aforementioned algorithms.
Edit: note that the matching should maximize the weight of the edges, that's why having directed edges makes a difference (A->B can have a totally different weight than B->A).
Admittedly, if I was maximizing cardinality, the directed edges wouldn't make a difference and I could apply any of the well-known algorithms to maximize cardinality: Hopcroft–Karp, Maximum Network Flow ....
Edit 2: Since matching is a term normally applied to undirected graphs, let me clarify what I exactly mean by matching in this question: a set of directed edges that do not share start or end vertices. More formally, if U->V and U'->V' are part of the matching, then V /= U' and V' /= U.
dfb's comment is correct, for any two vertices A, B you can discard the cheaper of the two edges AB and BA.
The proof is a one-liner:
Theorem: A maximum matching M never contains the cheaper edge of AB and BA for any two vertices A,B.
Proof: Let M be a maximum matching. Suppose AB is in M and is cheaper than BA. Define M' = M - {AB} + {BA}. M' is clearly still a matching, but it's more expensive. That contraditcs the assumption that M was a maximum matching.

Weighted Directed Acyclic Graphs: algorithm to find edge weights such that they define a distance function?

I have this technical problem that can be formuated with a Directed Acyclic Graph (DAG).
Nodes represent events (with unknown timing), with directed edges encoding the relation ship: "I'm younger than you/I happened before you".
I need to estimate edge weights (i.e. "dynamic weights") such that the Weighted DAG (WDAG) implies a distance function on the DAG. In other words the sum of weights for paths between nodes A and B should be equal for all paths.
This is an undetermined problem, even if the weights are integers (same underlying reason that topological sorting is not unique, I suppose). In all generality, the edge weights, which represent timeintervals between nodes/events, are real numbers. Therefore I'm introducing some preset objective function C=J(WDAG) on the weighted DAG, here unspecified.
My question is: is there an algorithm that distributes positive definite weights on the WDAG, subject to the constraint 1) that the weights form a distance function of the DAG and 2) minimizing the objective function cost C.
This seems unrelated to the shortest-path or minimum-spanning-tree problems classically associated to WDAG's. Any ideas to a formal or heuristic solution to the above problem?
Regards,
Stephane
I think all you need is topological sorting.
Sort the nodes according to a topological sort.
Distribute them in the [0,1] interval in the order you got.
Now the distance of node-pairs on the [0,1] line will give you the weight of the edge connecting them.
This is one possible solution. If you have more constraints on the weights than what you describe in the question, the problem might be more difficult.

Resources