dimod.variables.Variables._relabel_as_integers#

Variables._relabel_as_integers()[source]#

Relabel the variables as integers in-place.

Returns:

A mapping that will restore the original labels.

Return type:

dict[int, Variable]

Examples

>>> variables = dimod.variables.Variables(['a', 'b', 'c', 'd'])
>>> print(variables)
Variables(['a', 'b', 'c', 'd'])
>>> mapping = variables._relabel_as_integers()
>>> print(variables)
Variables([0, 1, 2, 3])
>>> variables._relabel(mapping)  # restore the original labels
>>> print(variables)
Variables(['a', 'b', 'c', 'd'])

Caution

This method is semi-public. It is intended to be used by classes that have Variables as an attribute, not by the the user.