Categories &

Functions List

Function Reference: multiway

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

Solve the multiway number partitioning problem.

multiway partitions a set of numbers into a specified number of subsets such that the sums of the subsets are as equal as possible.

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 create.

The optional parameter "method" specifies the algorithm used for partitioning. Supported methods are:

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

The output arguments are:

  • 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:

Source Code: multiway