BGC Tools
Static Public Member Functions | Static Private Member Functions
BGC.Mathematics.Combinatorics Class Reference

Static Public Member Functions

static void TreeOfAllCombinations (int[] indexes, int outputSize, out Node< int > root)
 Build a tree of all combinations. More...
 
static List< List< int > > ListOfAllCombinations (Node< int > root)
 Given a list of indexes, generate a list of all valid combinations. More...
 
static IEnumerator< List< int > > AllCombinationsGenerator (int[] indexes, int outputSize)
 Generate a list of indexes one at a time, generate a list of all valid combinations. More...
 

Static Private Member Functions

static List< List< int > > ListOfAllCombinationsRecursive (Node< int > node)
 

Detailed Description

Definition at line 7 of file Combinatorics.cs.

Member Function Documentation

◆ AllCombinationsGenerator()

static IEnumerator<List<int> > BGC.Mathematics.Combinatorics.AllCombinationsGenerator ( int []  indexes,
int  outputSize 
)
inlinestatic

Generate a list of indexes one at a time, generate a list of all valid combinations.

For example: ([0,1], 2) will return [[0, 0], [0, 1], [1, 0], [1, 1]]

Where the second number in the input defines the size of the inner. Additionally, the ordering of these will be randomized.

Todo:
: needs to generate one at a time rather than use the list method that is provided arrays.

Definition at line 92 of file Combinatorics.cs.

93  {
94  Node<int> root;
95  TreeOfAllCombinations(indexes, outputSize, out root);
96  List<List<int>> combinations = ListOfAllCombinations(root);
97 
98  for (int i = 0; i < combinations.Count; ++i)
99  {
100  yield return combinations[i];
101  }
102  }
Generic Node for generating tree structure
Definition: Node.cs:10
static List< List< int > > ListOfAllCombinations(Node< int > root)
Given a list of indexes, generate a list of all valid combinations.
static void TreeOfAllCombinations(int[] indexes, int outputSize, out Node< int > root)
Build a tree of all combinations.

◆ ListOfAllCombinations()

static List<List<int> > BGC.Mathematics.Combinatorics.ListOfAllCombinations ( Node< int >  root)
inlinestatic

Given a list of indexes, generate a list of all valid combinations.

For example: ([0,1], 2) will return [[0, 0], [0, 1], [1, 0], [1, 1]]

Where the second number in the input defines the size of the inner. Additionally, the ordering of these will be randomized. arrays.

Definition at line 59 of file Combinatorics.cs.

References BGC.DataStructures.Generic.Node< T >.Children.

60  {
61  List<List<int>> output = new List<List<int>>();
62 
63  for (int i = 0; i < root.Children.Count; ++i)
64  {
65  List<List<int>> childOutput = ListOfAllCombinationsRecursive(root.Children[i]);
66 
67  for (int j = 0; j < childOutput.Count; ++j)
68  {
69  output.Add(childOutput[j]);
70  }
71  }
72 
73  return output;
74  }
static List< List< int > > ListOfAllCombinationsRecursive(Node< int > node)
List< Node< T > > Children
Definition: Node.cs:13

◆ ListOfAllCombinationsRecursive()

static List<List<int> > BGC.Mathematics.Combinatorics.ListOfAllCombinationsRecursive ( Node< int >  node)
inlinestaticprivate

Definition at line 104 of file Combinatorics.cs.

References BGC.DataStructures.Generic.Node< T >.Children, and BGC.DataStructures.Generic.Node< T >.Value.

105  {
106  List<List<int>> output = new List<List<int>>();
107  if (node.Children.Count <= 0)
108  {
109  output.Add(new List<int>() { node.Value });
110  return output;
111  }
112 
113  for (int i = 0; i < node.Children.Count; ++i)
114  {
115  List<List<int>> childOutput = ListOfAllCombinationsRecursive(node.Children[i]);
116 
117  for (int j = 0; j < childOutput.Count; ++j)
118  {
119  childOutput[j].Add(node.Value);
120  output.Add(childOutput[j]);
121  }
122  }
123 
124  return output;
125  }
static List< List< int > > ListOfAllCombinationsRecursive(Node< int > node)
List< Node< T > > Children
Definition: Node.cs:13

◆ TreeOfAllCombinations()

static void BGC.Mathematics.Combinatorics.TreeOfAllCombinations ( int []  indexes,
int  outputSize,
out Node< int >  root 
)
inlinestatic

Build a tree of all combinations.

For example: ([0, 1], 2) would generate a tree of structure -1 |-0 | |-0 | |-1 | |-1 |-0 |-1

Except for the fact that the ordering will be randomized.

Definition at line 24 of file Combinatorics.cs.

25  {
26  root = new Node<int>(-1);
27 
28  if (outputSize <= 0)
29  {
30  return;
31  }
32 
33  int[] copyIndexes = new int[indexes.Length];
34  System.Array.Copy(indexes, copyIndexes, indexes.Length);
35  copyIndexes.Shuffle();
36 
37  for (int i = 0; i < indexes.Length; ++i)
38  {
39  Node<int> child;
40  TreeOfAllCombinations(indexes, outputSize - 1, out child);
41  child.Value = copyIndexes[i];
42  root.Children.Add(child);
43  }
44  }
Generic Node for generating tree structure
Definition: Node.cs:10
static void TreeOfAllCombinations(int[] indexes, int outputSize, out Node< int > root)
Build a tree of all combinations.

The documentation for this class was generated from the following file: