1. Home
  2. SETALLOCATIONS directive

SETALLOCATIONS directive

Runs through all ways of allocating a set of objects to subsets.

Options

NREQUIRED = scalar Number of allocations that are required; default 1
UNIQUE = string token Whether only unique allocations are to be formed, allowing the reordering of the subsets (yes, no); default no
NFOUND = scalar Number of allocations that has been found
NPOSSIBLE = scalar Saves the total of allocations that can be formed
GROUPS = factor or pointer Saves the allocations, in a single factor if NREQUIRED = 1, otherwise in a pointer to NFOUND factors
UNITS = variate Supplies numbers for the objects; if unset, the positive integers 1, 2 … are used
START = factor Previous allocation; if unset the allocations start as a partitioning of the objects in the ordering in the UNITS variate

Parameters

SETSIZE = scalars Number of objects in each subset
ELEMENTS = variates or pointers Saves the objects allocated to each subset, in a single variate if NREQUIRED = 1, otherwise in a pointer to NFOUND variates

Description

The SETALLOCATIONS directive allows you to form all the ways in which a set of objects can be allocated to subsets. For example, suppose we have 4 objects numbered 1 … 4 to allocate to two subsets of size 2. There are 6 possible ways of forming the allocations: {1, 2 : 3, 4}, {1, 3 : 2, 4}, {1, 4 : 2, 3}, {2, 3 : 1, 4}, {2, 4 : 1, 3} and {3, 4 : 1, 2}. If, however, the ordering of the subsets is unimportant, there are only three. For example {1, 2 : 3, 4} is then the same as {3, 4 : 1, 2}.

The sizes of the subsets are specified by the SETSIZE parameter, and the UNIQUE option can be set to yes to indicate that their ordering is unimportant (so only unique allocations are then formed). The NREQUIRED option indicates how many allocations you want to form (default 1). If you set NREQUIRED to a scalar containing a missing value, SETALLOCATIONS will save as many allocations as it can find.

You can use the NPOSSIBLE option to find out how many allocations are possible. The NFOUND option is useful if you request more allocations than are possible – it indicates how many allocations SETALLOCATIONS has actually been able to find.

The GROUPS option saves the allocations in factors (each with a level for each subset). If NREQUIRED = 1, it saves a single factor. Alternatively, if NREQUIRED is greater than one, it saves a pointer containing NFOUND factors.

As an alternative, the ELEMENTS parameter allows you to save the allocations in variates. For example

SETALLOCATIONS 2,2; ELEMENTS=Sub1, Sub2

saves the first subset in variate Sub1 and the second in variate Sub2. Just one allocation has been formed here as the NREQUIRED option has default 1. If several allocations are formed, ELEMENTS saves them in pointers to variates. For example

SETALLOCATIONS [NREQUIRED=3] 2,2; ELEMENTS=Sub1, Sub2

saves three allocations: (Sub1[1] : Sub2[1]), (Sub1[2] : Sub2[2]), and (Sub1[3] : Sub2[3]). By default, the variates will contain the positive integers 1, 2 upwards, but you can supply a variate containing others using the UNITS option.

By default, the first allocation is a partitioning of the objects in the same ordering as in the UNITS variate (or numerical order if UNITS is not set). However, if you want to run through the allocations in order, you can save the current allocation using the GROUPS option, and then use this as the setting of the START option to get the next one. For example, the following program runs through all the allocations of seven objects into subsets of size 2, 3 and 2.

SETALLOCATIONS [NPOSSIBLE=Nposs; GROUPS=Alloc] 2,3,2

CALCULATE Ntimes = Nposs - 1

FOR [INDEX=i; NTIMES=Ntimes]

  DUPLICATE Alloc; NEWSTRUCTURE=Start

  SETALLOCATIONS [NREQUIRED=1; GROUPS=Alloc; START=Start]\

                 2,3,2

  " use allocation Alloc "

ENDFOR

Options: NREQUIRED, UNIQUE, NFOUND, NPOSSIBLE, GROUPS, UNITS, START.

Parameters: SETSIZE, ELEMENTS.

Action with RESTRICT

Not relevant.

See also

Directives: SETCALCULATE, SETRELATE.

Procedure: SUBSET.

Commands for: Calculations and manipulation.

Example

" Example 1:4.3.4 "
SCALAR         nreqd
SETALLOCATIONS [NFOUND=Nfound; NREQUIRED=nreqd; GROUPS=Alloc] 2,2;\
               ELEMENTS=Sub1,Sub2
PRINT          Nfound
&              Alloc[]
&              Sub1[1...6]; DECIMALS=0 & Sub2[1...6]; DECIMALS=0
Updated on June 18, 2019

Was this article helpful?