Network flow to find intersection between two sets

119 Views Asked by At

I was given the following scenario:

There are $n$ knights in the kingdom $n\in N$

There are $m$ districts in the kingdom $m\in N$

Each knight $i$ can rule a maximum of $Q_i$ districts

Each knight has a list of districts he is willing to rule over

Each district has a list of knights their willing to take as a ruler

Each district can take only one knight as a ruler

Also, i am expected to solve this problem optimally with network flow, first creating the representation of the problem with a network flow and then use Ford Fulkerson algorithm to find the maximum flow in the network, possibly Edmonds-Karp if it will provide a shorter run time.

How can i solve this problem, more specifically how can i represent the intersection between the knights list and the district list as a network flow problem?

1

There are 1 best solutions below

0
On

Create $n$ nodes, one for each knight. Let's denote the $i$-th of them $K_i$. Create $m$ nodes, one for each district. Let's denote the $i$-th of them $D_i$. Create two extra nodes, one being the source $s$ and one the sink $t$. For every knight node $K_i$, add the edge $(s, K_i)$ to your graph with $c(s, K_i) = Q_i$. For every district node $D_i$ add the edge $(D_i, t)$ to your graph with $c(D_i, t) = 1$. Now for every pair of a knight $K_i$ and a district $D_j$ where the knight is willing to rule over the district and the district is willing to accept the knight as a ruler, add the edge $(K_i, D_j)$ to your graph with $c(K_i, D_j) = 1$.

Use any max-flow algorithm to find a maximum $s$-$t$-flow $f$. Once you found the flow you can interpret it in the following way: Knight $i$ should rule over district $j$ if and only if $f(K_i, D_j) = 1$.