This is a general algorithm question. I want to run some shortest path algorithm on an undirected graph where both edges and vertices have costs associated with them. Most of the shortest path finding algorithms do not take the vertex costs into account. Is there any method to compensate this problem?
Share
Augment the graph by adding half the cost of the two vertices an edge connects to the cost of the edge (call that the augmented cost of the edge).
Then ignore the vertex costs and run an ordinary shortest path algorithm on the augmented graph.
For each path
the cost in the augmented graph is
so the cost of a path between two vertices
aandbin the augmented graph is the cost of the same path in the original graph minus half the combined cost of the start and end vertices.Thus a path is a shortest path in the original graph if and only it is a shortest path in the augmented graph.