## 5.27. assign_and_counts

Origin

N.Β Beldiceanu

Constraint

$\mathrm{\pi \pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi }\left(\mathrm{\pi ²\pi Ύ\pi »\pi Ύ\pi \pi \pi },\mathrm{\pi Έ\pi \pi ΄\pi Ό\pi },\mathrm{\pi \pi ΄\pi »\pi Ύ\pi Ώ},\mathrm{\pi »\pi Έ\pi Ό\pi Έ\pi }\right)$

Arguments
 $\mathrm{\pi ²\pi Ύ\pi »\pi Ύ\pi \pi \pi }$ $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }\left(\mathrm{\pi \pi \pi }-\mathrm{\pi \pi \pi }\right)$ $\mathrm{\pi Έ\pi \pi ΄\pi Ό\pi }$ $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }\left(\mathrm{\pi \pi \pi }-\mathrm{\pi \pi \pi \pi },\mathrm{\pi \pi \pi \pi \pi \pi }-\mathrm{\pi \pi \pi \pi }\right)$ $\mathrm{\pi \pi ΄\pi »\pi Ύ\pi Ώ}$ $\mathrm{\pi \pi \pi \pi }$ $\mathrm{\pi »\pi Έ\pi Ό\pi Έ\pi }$ $\mathrm{\pi \pi \pi \pi }$
Restrictions
 $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }$$\left(\mathrm{\pi ²\pi Ύ\pi »\pi Ύ\pi \pi \pi },\mathrm{\pi \pi \pi }\right)$ $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }$$\left(\mathrm{\pi ²\pi Ύ\pi »\pi Ύ\pi \pi \pi },\mathrm{\pi \pi \pi }\right)$ $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }$$\left(\mathrm{\pi Έ\pi \pi ΄\pi Ό\pi },\left[\mathrm{\pi \pi \pi },\mathrm{\pi \pi \pi \pi \pi \pi }\right]\right)$
Purpose

Given several items (each of them having a specific colour that may not be initially fixed), and different bins, assign each item to a bin, so that the total number $n$ of items of colour $\mathrm{\pi ²\pi Ύ\pi »\pi Ύ\pi \pi \pi }$ in each bin satisfies the condition $n\mathrm{\pi \pi ΄\pi »\pi Ύ\pi Ώ}\mathrm{\pi »\pi Έ\pi Ό\pi Έ\pi }$.

Example
$\left(\begin{array}{c}β©4βͺ,\hfill \\ β©\begin{array}{cc}\mathrm{\pi \pi \pi }-1\hfill & \mathrm{\pi \pi \pi \pi \pi \pi }-4,\hfill \\ \mathrm{\pi \pi \pi }-3\hfill & \mathrm{\pi \pi \pi \pi \pi \pi }-4,\hfill \\ \mathrm{\pi \pi \pi }-1\hfill & \mathrm{\pi \pi \pi \pi \pi \pi }-4,\hfill \\ \mathrm{\pi \pi \pi }-1\hfill & \mathrm{\pi \pi \pi \pi \pi \pi }-5\hfill \end{array}βͺ,\beta €,2\hfill \end{array}\right)$

FigureΒ 5.27.1 shows the solution associated with the example. The items and the bins are respectively represented by little squares and by the different columns. Each little square contains the value of the $\mathrm{\pi \pi \pi ’}$ attribute of the item to which it corresponds. The items for which the colour attribute is equal to 4 are located under the thick line. The $\mathrm{\pi \pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi }$ constraint holds since for each used bin (i.e.,Β namely bins 1 and 3) the number of assigned items for which the colour attribute is equal to 4 is less than or equal to the limit 2.

Typical
 $|\mathrm{\pi ²\pi Ύ\pi »\pi Ύ\pi \pi \pi }|>0$ $|\mathrm{\pi Έ\pi \pi ΄\pi Ό\pi }|>1$ $\mathrm{\pi \pi \pi \pi \pi }$$\left(\mathrm{\pi Έ\pi \pi ΄\pi Ό\pi }.\mathrm{\pi \pi \pi }\right)>1$ $\mathrm{\pi »\pi Έ\pi Ό\pi Έ\pi }>0$ $\mathrm{\pi »\pi Έ\pi Ό\pi Έ\pi }<|\mathrm{\pi Έ\pi \pi ΄\pi Ό\pi }|$
Symmetries
• Items of $\mathrm{\pi ²\pi Ύ\pi »\pi Ύ\pi \pi \pi }$ are permutable.

• Items of $\mathrm{\pi Έ\pi \pi ΄\pi Ό\pi }$ are permutable.

• All occurrences of two distinct values of $\mathrm{\pi Έ\pi \pi ΄\pi Ό\pi }.\mathrm{\pi \pi \pi }$ can be swapped; all occurrences of a value of $\mathrm{\pi Έ\pi \pi ΄\pi Ό\pi }.\mathrm{\pi \pi \pi }$ can be renamed to any unused value.

Usage

Some persons have pointed out that it is impossible to use constraints such as $\mathrm{\pi \pi \pi \pi \pi }$, $\mathrm{\pi \pi \pi \pi \pi \pi \pi }$, $\mathrm{\pi \pi \pi \pi \pi \pi }$, $\mathrm{\pi \pi \pi \pi \pi }$, or $\mathrm{\pi \pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi ’}$ if the set of variables is not initially known. However, this is for instance required in practice for some timetabling problems.

Keywords
Derived Collection
$\mathrm{\pi \pi \pi }\left(\mathrm{\pi  \pi °\pi »\pi \pi ΄\pi }-\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }\left(\mathrm{\pi \pi \pi }-\mathrm{\pi \pi \pi }\right),\left[\mathrm{\pi \pi \pi \pi }\left(\mathrm{\pi \pi \pi }-\mathrm{\pi ²\pi Ύ\pi »\pi Ύ\pi \pi \pi }.\mathrm{\pi \pi \pi }\right)\right]\right)$
Arc input(s)

$\mathrm{\pi Έ\pi \pi ΄\pi Ό\pi }$ $\mathrm{\pi Έ\pi \pi ΄\pi Ό\pi }$

Arc generator
$\mathrm{\pi \pi  \pi \pi ·\pi \pi Ά\pi }$$\beta ¦\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }\left(\mathrm{\pi \pi \pi \pi \pi }\mathtt{1},\mathrm{\pi \pi \pi \pi \pi }\mathtt{2}\right)$

Arc arity
Arc constraint(s)
$\mathrm{\pi \pi \pi \pi \pi }\mathtt{1}.\mathrm{\pi \pi \pi }=\mathrm{\pi \pi \pi \pi \pi }\mathtt{2}.\mathrm{\pi \pi \pi }$
Graph class
 $\beta ’$$\mathrm{\pi °\pi ²\pi \pi ²\pi »\pi Έ\pi ²}$ $\beta ’$$\mathrm{\pi ±\pi Έ\pi Ώ\pi °\pi \pi \pi Έ\pi \pi ΄}$ $\beta ’$$\mathrm{\pi ½\pi Ύ}_\mathrm{\pi »\pi Ύ\pi Ύ\pi Ώ}$

Sets
$\begin{array}{c}\mathrm{\pi ²\pi ΄\pi ’\pi ’}\beta ¦\hfill \\ \left[\begin{array}{c}\mathrm{\pi \pi \pi \pi \pi \pi },\hfill \\ \mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi }-\mathrm{\pi \pi \pi }\left(\begin{array}{c}\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }-\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }\left(\mathrm{\pi \pi \pi }-\mathrm{\pi \pi \pi \pi }\right),\hfill \\ \mathrm{\pi \pi \pi \pi }\left(\mathrm{\pi \pi \pi }-\mathrm{\pi Έ\pi \pi ΄\pi Ό\pi }.\mathrm{\pi \pi \pi \pi \pi \pi }\right)\right]\hfill \end{array}\right)\hfill \end{array}\right]\hfill \end{array}$

Constraint(s) on sets
$\mathrm{\pi \pi \pi \pi \pi \pi }$$\left(\mathrm{\pi  \pi °\pi »\pi \pi ΄\pi },\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi },\mathrm{\pi \pi ΄\pi »\pi Ύ\pi Ώ},\mathrm{\pi »\pi Έ\pi Ό\pi Έ\pi }\right)$
Graph model

We enforce the $\mathrm{\pi \pi \pi \pi \pi \pi }$ constraint on the colour of the items that are assigned to the same bin.

PartsΒ (A) andΒ (B) of FigureΒ 5.27.2 respectively show the initial and final graph associated with the Example slot. The final graph consists of the following two connected components:

• The connected component containing six vertices corresponds to the items that are assigned to bin 1.

• The connected component containing two vertices corresponds to the items that are assigned to bin 3.

The $\mathrm{\pi \pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi }$ constraint holds since for each set of successors of the vertices of the final graph no more than two items take colour 4.

Automaton

FigureΒ 5.27.3 depicts the automaton associated with the $\mathrm{\pi \pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi }$ constraint. To each $\mathrm{\pi \pi \pi \pi \pi \pi }$ attribute ${\mathrm{\pi ²\pi Ύ\pi »\pi Ύ\pi \pi }}_{i}$ of the collection $\mathrm{\pi Έ\pi \pi ΄\pi Ό\pi }$ corresponds a 0-1 signature variable ${\mathrm{\pi }}_{i}$. The following signature constraint links ${\mathrm{\pi ²\pi Ύ\pi »\pi Ύ\pi \pi }}_{i}$ and ${\mathrm{\pi }}_{i}$: ${\mathrm{\pi ²\pi Ύ\pi »\pi Ύ\pi \pi }}_{i}\beta \mathrm{\pi ²\pi Ύ\pi »\pi Ύ\pi \pi \pi }\beta {\mathrm{\pi }}_{i}$. For all items of the collection $\mathrm{\pi Έ\pi \pi ΄\pi Ό\pi }$ for which the $\mathrm{\pi \pi \pi \pi \pi \pi }$ attribute takes its value in $\mathrm{\pi ²\pi Ύ\pi »\pi Ύ\pi \pi \pi }$, counts for each value assigned to the $\mathrm{\pi \pi \pi }$ attribute its number of occurrences $n$, and finally imposes the condition $n\mathrm{\pi \pi ΄\pi »\pi Ύ\pi Ώ}\mathrm{\pi »\pi Έ\pi Ό\pi Έ\pi }$.