I have a list of the following struture:
(my real list also has the same structure, just much longer not just 12)
mylist= {group1, group2, group3, group4, group5, group6, group7, group8, group9, group10, group11, group12}
Each group is also a list which include 4 sublists, let's assume:
group1 = {list1A, list1B, list1C, list1D}
group2 = {list2A, list2B, list2C, list2D}
group3 = {list3A, list3B, list3C, list3D}
...
group11 = {list11A, list11B, list11C, list11D}
group12 = {list12A, list12B, list12C, list12D}
Now I want to form families of 6 lists from 6 groups (out of 12 groups and one list from group) which satisfies the structure in any order:
form = {{x1, x2, x3, x4, x5, x6, x7, x8}, {x3, x2, x1, x6, x5, x4, x8,
x7}, {x3, x2, -x1 - x3, x6, x5, -x4 - x6,
x8, -x7 - x8}, {-x1 - x3, x2, x3, -x4 - x6, x5, x6, -x7 - x8,
x8}, {-x1 - x3, x2, x1, -x4 - x6, x5, x4, -x7 - x8, x7}, {x1,
x2, -x1 - x3, x4, x5, -x4 - x6, x7, -x7 - x8}}
for example:
families1= {list1A, list3A, list2A, list10A, list12A, list4A}
families2= {list6A, list5A, list8A, list11A, list9A, list7A}
(* all of them happens to be the first list of each group but it's not necessary to be the first list in each group, just any list in a group is okay and lists in families1 and families2 should not intersect*)
so the expectedOut would be:
expectedOut = {families1, families2}
(*families are not allowed to be interesect*)
This is the result I got by manually do it myself so probably I missed some other possible different combinations of families.
for example:
expectedOut1 = {families1, families2}
expectedOut2 = {families1, families3}
expectedOut3 = {families5, families7}
or just only one families is found:
expectedOut1 = {families8}
Finally here is my data:
(the expectedOUt) does satisfy the form just not in the given order and the order is not important.)
mylist = {{{-3, -3, 0, -3, 0, 0, -3, 3}, {-3, 0, 0, -3, -3, 0, -3,
3}, {3, 0, 0, 3, 3, 0, -3, 3}, {3, 3, 0, 3, 0, 0, -3,
3}}, {{0, -3, -3, 0, 0, -3, 3, -3}, {0, 0, -3, 0, -3, -3,
3, -3}, {0, 0, 3, 0, 3, 3, 3, -3}, {0, 3, 3, 0, 0, 3,
3, -3}}, {{-3, -3, 3, -3, 0, 3, -3, 0}, {-3, 0, 3, -3, -3, 3, -3,
0}, {3, 0, -3, 3, 3, -3, -3, 0}, {3, 3, -3, 3, 0, -3, -3,
0}}, {{3, -3, 0, 3, 0, 0, 0, 3}, {3, 0, 0, 3, -3, 0, 0, 3}, {-3,
0, 0, -3, 3, 0, 0, 3}, {-3, 3, 0, -3, 0, 0, 0, 3}}, {{-3, -3,
3, -3, 0, 3, 0, 3}, {-3, 0, 3, -3, -3, 3, 0, 3}, {3, 0, -3, 3,
3, -3, 0, 3}, {3, 3, -3, 3, 0, -3, 0, 3}}, {{-3, -3, 0, -3, 0, 0,
0, -3}, {-3, 0, 0, -3, -3, 0, 0, -3}, {3, 0, 0, 3, 3, 0,
0, -3}, {3, 3, 0, 3, 0, 0, 0, -3}}, {{3, -3, 0, 3, 0, 0,
3, -3}, {3, 0, 0, 3, -3, 0, 3, -3}, {-3, 0, 0, -3, 3, 0,
3, -3}, {-3, 3, 0, -3, 0, 0, 3, -3}}, {{0, -3, -3, 0, 0, -3, -3,
0}, {0, 0, -3, 0, -3, -3, -3, 0}, {0, 0, 3, 0, 3, 3, -3, 0}, {0,
3, 3, 0, 0, 3, -3, 0}}, {{3, -3, -3, 3, 0, -3, 3, 0}, {3, 0, -3,
3, -3, -3, 3, 0}, {-3, 0, 3, -3, 3, 3, 3, 0}, {-3, 3, 3, -3, 0,
3, 3, 0}}, {{0, -3, 3, 0, 0, 3, 3, 0}, {0, 0, 3, 0, -3, 3, 3,
0}, {0, 0, -3, 0, 3, -3, 3, 0}, {0, 3, -3, 0, 0, -3, 3,
0}}, {{0, -3, 3, 0, 0, 3, -3, 3}, {0, 0, 3, 0, -3, 3, -3, 3}, {0,
0, -3, 0, 3, -3, -3, 3}, {0, 3, -3, 0, 0, -3, -3,
3}}, {{3, -3, -3, 3, 0, -3, 0, -3}, {3, 0, -3, 3, -3, -3,
0, -3}, {-3, 0, 3, -3, 3, 3, 0, -3}, {-3, 3, 3, -3, 0, 3,
0, -3}}};
form = {{x1, x2, x3, x4, x5, x6, x7, x8}, {x3, x2, x1, x6, x5, x4, x8,
x7}, {x3, x2, -x1 - x3, x6, x5, -x4 - x6, x8, -x7 - x8}, {-x1 - x3,
x2, x3, -x4 - x6, x5, x6, -x7 - x8, x8}, {-x1 - x3, x2,
x1, -x4 - x6, x5, x4, -x7 - x8, x7}, {x1, x2, -x1 - x3, x4,
x5, -x4 - x6, x7, -x7 - x8}}
expectedOut = {{{-3, -3, 0, -3, 0, 0, -3, 3}, {-3, -3, 3, -3, 0,
3, -3, 0}, {0, -3, -3, 0, 0, -3, 3, -3}, {0, -3, 3, 0, 0, 3, 3,
0}, {3, -3, -3, 3, 0, -3, 0, -3}, {3, -3, 0, 3, 0, 0, 0,
3}}, {{-3, -3, 0, -3, 0, 0, 0, -3}, {-3, -3, 3, -3, 0, 3, 0,
3}, {0, -3, -3, 0, 0, -3, -3, 0}, {0, -3, 3, 0, 0, 3, -3,
3}, {3, -3, -3, 3, 0, -3, 3, 0}, {3, -3, 0, 3, 0, 0, 3, -3}}};
How can I do that? Note that the expectOut above is just what I got by doing manually myself so it may not include all possible cases.
Edit by lericr attempting to clarify
Given 6 data of the same type (specifically a flat list of 8 numbers), we can check a condition which I'll call isFamily
. The isFamily
condition is satisfied if some permutation of the 6 data matches the pattern supplied in the original post and labelled form
(with the implied replacements of the xN symbols).
A group is a list of 4 data (of the type described above, a length 8 list of numbers). As input, we are given a larger data structure, theData
, that consists of 6k groups for some positive integer k.
We want to find families such that each member of the family comes from a different group. Ideally, we'd like to find k disjoint inter-group families. With regard to the disjoint condition, I'm assuming that if the groups are not disjoint then the families need not be disjoint as long as they can be formed without pulling two data from the same group (but it may be the case that theData
is constrained so that this cannot occur--maybe the OP can clarify). If the ideal cannot be satisfied, I'm assuming that we want the largest set of inter-group families that we can find.
A solution could provide either one family set (the set that most closely matches the ideal) or all possible family sets.