Categories &

Functions List

Function Reference: multiway

statistics: groupindex = multiway (numbers, num_parts)
statistics: groupindex = multiway (numbers, num_parts, method)
statistics: [groupindex, partition] = multiway (…)
statistics: [groupindex, partition, groupsizes] = multiway (…)

Solve the multiway number partitioning problem.

groupindex = multiway (numbers, num_parts) splits a set of numbers in numbers into a number of subsets specified in num_parts such that the sums of the subsets are nearly as equal as possible and returns a vector of group indices in groupindex with each index corresponding to the set of numbers provided as input.

  • numbers is a vector of positive real numbers to be partitioned.
  • num_parts is a positive integer scalar specifying the number of partitions (subsets) to split the numbers into.

groupindex = multiway (numbers, num_parts, method) also specifies the algorithm used for partitioning the set of numbers. By default, multiway uses the complete Karmarkar-Karp algorithm, when the set of numbers contains up to 10 elements and the requested number of subsets does not exceed 5, otherwise it defaults to the greedy algorithm, which is optimized for speed, but may not return the optimal partitioning. The following methods are supported:

  • 'greedy' (Greedy algorithm)
  • 'completeKK' (Complete Karmarkar-Karp algorithm)

The multiway function may return up to three output arguments described below:

  • groupindex: A vector of the same length as numbers containing the group index (from 1 to num_parts) for each number.
  • partition: A cell array of length num_parts with each cell containing the numbers assigned to that partition.
  • groupsizes: A vector of the sums of the numbers in each partition.

Example:

 
 
 numbers = [4, 5, 6, 7, 8];
 num_parts = 2;
 [groupindex, partition, groupsizes] = multiway (numbers, num_parts);
 
 

See also: cvpartition

Source Code: multiway