Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Most optimal way to solve multiple-source multiple-sink flow network

For the sake of simplicity, let's say we have the following problem:

We are writing the GPS for self-driving cars in a city. We assume the cars running our software are the only cars on the road.

They layout of the city is represented as a flow network, but the flow network has multiple starting/ending points, so there's multiple sources/sinks that are not necessarily close to one another.

Is there an efficient solution to this problem?

like image 364
CaptainForge Avatar asked Dec 24 '22 19:12

CaptainForge


2 Answers

Standard approach to solving multiple source / multiple sink problems is adding a synthetic single source and a synthetic single sink. Once you connect synthetic source to all real sources with pipes of capacity equal to the capacity of the source, and also connect the synthetic sink to all real sink with a pipe equal to sink's capacity, you can use your preferred algorithm for solving single source / single sink flow network.

like image 179
Sergey Kalinichenko Avatar answered Apr 05 '23 22:04

Sergey Kalinichenko


Yes, you can create a single dummy source that all of your other sources connect to, and similarly, a single dummy sink for all of the real sinks to connect to.

But what flow do you assign to the edges from the dummy source to a real source? The edge from your dummy source to a real source (lets call it A) should have a flow equal to the sum of all edges leading out of A. Likewise, the flow of an edge from a real sink (B) to the dummy sink should be the same as the sum of all edges coming in to B.

You can read more about it in these lecture slides about network flow.

like image 28
Matthew Pope Avatar answered Apr 05 '23 23:04

Matthew Pope