I have a set of 30 nodes, each node can connect to one and only one at a time. Moreover, one node cannot connect to another specific one (say, the one with and id= id+15
, e.g. 1-16, 2-17... the rule is not relevant, I can change the association node-number). What I am looking for is a matrix where each row is a possible set of connections where all nodes are connected to another and that each nodes connected to all other nodes (except the forbidden ones). It would look like this (read it in pairs)
[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30;
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 1 30;
1 4 2 5 3 6 7 10 8 11 9 12 13 16 14 17 15 18 19 22 20 23 21 24 25 28 26 29 27 30;
4 7 5 8 6 9 10 13 11 14 12 15 16 19 17 20 18 21 22 25 23 26 24 27 28 1 2 29 3 30;
...
]
I was trying to develop this by collecting all the possible non-repeated combination (binomial 30 over 2 => 435) with nchoosek
but now I am dealing with the problem of placing all the pairs that I have in a 29-by-15 pairs matrix without repetition. This would allow me to respect the constraint easily by removing the forbidden pairs from the output of nchoosek
.
I am sure this is a known graph problem but I was not able to find anything about that. Does anyone know to implement it?
Aim is to describe the timeline of point-to-point connections between 30 nodes. Since each one cannot connect to a particular other, the total number of possible connections is 420 (435 - 15 forbidden connections), for a total of 28 time slots (rows) containing 15 pairs (30 column).
Edit2: A further way could be to generate a 30x30 matrix having as row all possible combinations of numbers from 1 to 30 but with the constraint that pairs shall not be repeated (not in order). E.g. the following are possible valid vectors (limited to 12 elements instead of 30), however the second is discarded since couple [2 1]
is equivalent to couple [1 2]
. Don't know how to deal with the constraint, though.
[1 2 3 4 5 6 7 8 9 10 11 12]
[2 1 3 4 5 6 7 8 9 10 11 12]