Given a set of labels {a_1,...,a_n} (with some labels possibly appearing multiple times) I would like to efficiently compute all trees with n leaves labelled {a_1,...,a_n} and 2n-2 nodes. This is equivalent to trees with n leaves labelled {a_1,...,a_n} where all interior (non-leaf) vertices are trivalent. I only wish to produce all trees up to graph isomorphisms that preserve the labels.
For example, the output for {a,a,a,a,1,2} would be the following 8 trees (edit: there should be 9, see solution below):
This is similar to a question I have asked in the past, but now I am adding in some labels where I do care about ordering and some where I do not care about ordering. One (probably non-optimal strategy) would be to produce all of the trees using the code listed there, then produce all of the labellings of those trees (yikes) and then somehow test whether there is a graph isomorphism preserving the labels to eliminate duplicates (I am also not sure yet about how to do this last step).
This seems very inefficient, so I am wondering if there is a better way.
I have thought about trying to use Groupings for this, but I have not yet figured out a way to make it work.