I'm interested in Python specifically, but a generic solution would be also be much appreciated. I have an even number of nodes (let's say 12 for a particular example):
['a1', 'a2', 'a3', 'b1', 'b2', 'b3', 'c1', 'c2', 'c3', 'd1', 'd2', 'd3']
Each node must be connected to another node, forming 6 connections (pairs).
I need to figure out a way to find all possible combinations of connections.
Also, 'a1'-'a2'
should be considered the the same as 'a2'-'a1'
Some thoughts:
I can get the list of possible
itertools.combinations(lst, 2)
, but nodes are not reusable. Say, a connection'a1'<->'a2'
should eliminate'a1'<->'a3'
from the available choices as'a1'
already used.I have no idea if the search is even applicable as there seems to be a few problems:
- there seems to be no (easy, cheap) way to track visited states
- the solution will always be on the bottom (need to traverse the tree all the way down to complete all the connections)