enum:
Filter:
miSCellaneous_lib/Tutorials (extension) | Libraries > miSCellaneous > General Tutorials

enum
ExtensionExtension

general enumeration tool, can be used for a variety of combinatorial problems

Description

Method enum implements a basic backtracking search suited for a number of counting and optimization problems. For specification of search criteria a boolean-valued Function has to be passed.

NOTE: The method applies to Integers indicating the recursion depth. Due to the nature of combinatorial problems with an often rapid growth of solutions and/or enumeration steps with increase of size, it is recommended to start examples with low numbers to avoid hangs.

Instance Methods

.enum

Returns solutions of the problem, which is defined by function, as an Array of SequenceableCollections (size = receiver).

Arguments:

pool

SequenceableCollection of items to be considered for possible solutions. If type equals 0 the same pool is taken for all indices of possible solutions, if type equals 1 a SequenceableCollection of pools might be passed. The existence of an additional type arg is necessary as it might also be desirable to consider SequenceableCollections as single items of possible solutions.

function

Boolean-valued Function to be evaluated at currentIndex. For many applications it is not necessary to evaluate at index 0 (so per default evalAtZero set to false), the Function is not evaluated and the item is supposed to be considered as first element of a possible solution.

From current state the Function is passed the following args to specify search:

  • item - Current item to be checked.
  • currentIndex - Current enumeration level, between 1 (resp. 0 in case evalAtZero set to true) and receiver - 1.
  • currentCol - Contains current collection of items already chosen at indices up to currentIndex - 1, for efficiency reasons length of this collection equals receiver and items indexed at current or higher enumeration level might stem from earlier enumeration steps.
  • indexCol - Current collection of indices (of items from pool) already chosen, for efficiency reasons length of this collection equals receiver and indices at current or higher enumeration level might stem from earlier enumeration steps.
evalAtZero

Boolean. Determines if function will be evaluated at index 0. Defaults to false.

type

Must be 0 or 1. Determines if pool should be taken for all items (0, default) or specified per index (1).

order

Boolean. Determines if search should follow order of items given in pool or a search order is randomly chosen. Defaults to true. For search of a single random solution one would set order to false and maxNum to 1.

maxNum

Integer. Maximum number of solutions to be searched for. Defaults to inf.

Example 1: Basic enumerations, Subsets

Example 2: Melodic Shapes

Example 3: Partitions of Integers, Scales

Example 4: Graphs