Finding the most coordinates as possible

39 Views Asked by At

I'm trying to solve a mathematic riddle, I'm having B , Bands, and C Clubs. each of the B bands has a coordinate(x,y) in km, and each club has also (x,y) coordinates. I need to pair as much bands as I can to a each club, each band can perform in 1 club, and each club can have only 1 band.

band cant go to a location which is farther then 50km.

here is my idea: I thought I should use Closest pair of points problem algorithm and then match each coordinate of a band(which is not taken) with another club which is closet and not taken also.

what do you think about it? or should I use other methods?

1

There are 1 best solutions below

0
On BEST ANSWER

The greedy algorithm won't necessarily give you the best result. It's possible, for instance, that if you start by pairing the first few bands with the closest clubs, then a later band will be all out of adjacent clubs, but you could have given an early band a different club to leave room for the later band.

This problem is essentially a maximum matching problem in the bipartite graph $G$ with bipartition $B \mathbin{\dot{\cup}} C$, where

  • $B$ is the set of bands,
  • $C$ is the set of clubs,
  • $b \in B$ is adjacent to $c \in C$ if the distance between $b$ and $c$ is at most $50$ km.

The standard way to solve this is the Ford–Fulkerson method (Wikipedia link).

The idea is that we can increase a partial matching by finding augmenting paths: paths $(b_0, c_0, b_1, c_1, \dots, b_k, c_k)$ in $G$ such that $b_0$ and $c_k$ are unpaired, but $b_1$ is paired to $c_0$, $b_2$ to $c_1$, and in general $b_{i+1}$ to $c_i$. Then we can switch all these pairings to pairing $b_0$ with $c_0$, $b_1$ with $c_1$, and so on, up to $b_k$ with $c_k$. This gives us one more pair.

Augmenting paths can always be found unless you've reached the maximum matching, and one way to find them is by a breadth-first search.