sweetpea.combinatorics module

This module provides combinatoric functionality.

sweetpea.combinatorics.extract_components(sizes, n)

Given a list of dimension sizes, and an integer less than the product of the sizes, this function will extract the component value for each dimension from the total.

For example, if sizes is [3, 4, 2], there are 24 possible combinations of the three. If 0 <= n < 24, this function will return the selections for each dimension for that n.

Parameters
  • sizes (List[int]) –

  • n (int) –

Return type

List[int]

sweetpea.combinatorics.compute_jth_inversion_sequence(n, j)

The are n! permutations of n elements. Each permutation can be uniquely identified by and constructed from its “inversion sequence”. This function will compute the j``th inversion sequence for a set of ``n elements.

Information on inversion sequences can be found:

  • MathOnline

  • “Introductory Combinatorics” by Richard A. Brualdi, ISBN 978-0136020400.

sweetpea.combinatorics.construct_permutation(inversion_sequence)

Given an inversion sequence, construct the permutation.

Parameters

inversion_sequence (List[int]) –

Return type

List[int]

sweetpea.combinatorics.compute_jth_combination(l, n, j)

In a sequence of l items, where there are n choices for each item, this will compute the jth combination, out of all nl possibilities.