I've stampled upon a curious problem.
I've got an unbounded chessboard, N knights starting locations and N target locations.
The task is to find minimal number of moves for all knights to reach all target locations.
I know that shortest path problem for a single knight can be solved using breadth-first search, but how can it be solved for multiple knights?
Sorry for my english, I use it seldom.
I assume you know how to do it for one Knigt .
You can reformulate your problem as a linear program:
I will use the following notations :
We have N knights and N en locations.
xij = 1
if you chose knight i to go to location j and 0 otherwisecij
is the min length of moving knight i to location jThen you have the following linear program :
if X is the matrix of (xij) you have n! possible matrix. This problem can be NP-Hard (there is no easy solution to this system, solving the system is pretty similar than testing all possible solutions).
EDIT:
This problem is called the assignment problem and there exist multiple algorithms to solve it in polynomial time . (check out @purav answer for an example)
As mentionned by @Purav even though this kind of problems can be NP-hard, in this case it can be solve in O(n^3)
About the problem @j_random_hacker raised :
Remarks :
1. multiple optimal paths :
As there is no constraint on the side of the chessboard (ilimited chessboard), the order in which you do your move for achiveing the shortest path is not relevant, so there is always a lot a different shortest path (I won't do the combinatorics here).
Example with 2 knights
Let say you have 2 K and 2 endpoints ('x'), the optimal path are drawned.
you move the right K to the first point (1 move) the second cannot use the optimal path.
But I can easily create a new optimal path, instead of moving 2 right 1 up then 2 up 1 right. 1 can move 2 up 1 right the 1 up 2 right (just inverse)
and any combination of path works :
2. order in which knights are moved :
The second thing is that I can chose the order of my move.
example:
with the previous example if I chose to start with the left knight and go to the upper endpoint, dont have anymore endpoint constraint.
With these 2 remarks it might be possible to prove that there is no situation in which the lower bound calculated is not optimal .