I want to code a program to solve a variation of the salesman problem but I am encountering some difficulties.
The idea is that I have $S$ points (customers) I'd wish to visit and I always depart and return to the same origin point (warehouse). If I visit all points with 1 single driver I might be exceeding the allowed working hours so the idea is to try all possible combinations to visit those S points with $1$ driver, $2$ drivers,..., $S$ drivers and check which solution is better.
I want to know how many combinations there are to visit those $S$ points with K drivers but I am unable to find the solution. I believe it might be related to the Stirling numbers but I cannot conclude the problem.
I would solve the problem with 2 steps:
- Find all the possible partitions of $S$ into $K$ different subsets of exactly size $k_1, k_2,\cdots, k_K $ $(k_1+k_2+\cdots+k_K = S)$. That would tell me all the different assignations of points to each driver (without taking into account that once you have more than 1 point assigned to a particular driver, you have several ways to visit it)
- Once I have the above-mentioned number, I know that I can visit N different points into $N!$ ways, so I would multiply that particular number by $k_1!k_2!\cdots k_K!$ to get the final amount of combinations.
Example 01:
$$S = 4, K = 2, k_{1} = 1, k_{2} = 3$$
points $\{A,B,C,D\}$
- $\{A\},\{BCD\} // \{B\},\{ACD\} // \{C\}, \{ABD\} // \{D\},\{ABC\} \Rightarrow 4$ partitions
- $k_1!k_2! = 1!3! = 6 \Rightarrow 6\cdot 4 = 24$ ways to visit $4$ points with $2$ drivers (1 driver visiting 1 point and another driver visiting $3$ points)
Example 02:
$S = 4$ $K = 2$ $k_1 = 2$ $k_2 = 2$
points $\{A,B,C,D\}$
- $\{AB\},\{CD\} // \{AC\}\{BD\} // \{AD\},\{BC\}$ ==> 3 partitions
- $k_1!k_2! = 2!2! = 4 \Rightarrow 3\cdot 4 = 12$ ways to visit $4$ points with $2$ drivers ($1$ driver visiting $2$ points and another driver visiting $2$ points)
I would like the formula to obtain the number in step $1$. Something like a Stirling number with known items assigned to a known amount of partitions.
You will need to consider the multiplicity of each value in the partition of $S$. Let \begin{eqnarray*} S=\sum_{i=1}^{S} i \, m_i \end{eqnarray*} where $m_i$ is the number of times i occurs in the sum to $S$. (many of these multiplicities will be zero) And \begin{eqnarray*} K=\sum_{i=1}^{S} m_i \end{eqnarray*} is the number of number of parts in the partition.
The number of ways partition $S$ labelled objects is given by \begin{eqnarray*} \frac{S!}{\prod_{i=1}^{n} ((i!)^{m_i}m_i !)}. \end{eqnarray*} These numbers occur in the Faa di Bruno Formula. https://en.wikipedia.org/wiki/Fa%C3%A0_di_Bruno%27s_formula