dimod.binary.BinaryQuadraticModel.to_polystring

BinaryQuadraticModel.to_polystring(encoder: Optional[Callable[[Hashable], str]] = None) str[source]

Return a string representing the model as a polynomial.

Parameters

encoder – A function mapping variables to a string. By default string variables are mapped directly whereas all other types are mapped to a string f"v{variable!r}".

Returns

A string representing the binary quadratic model.

Examples

>>> x, y, z = dimod.Binaries(['x', 'y', 'z'])
>>> (2*x + 3*y*z + 6).to_polystring()
'6 + 2*x + 3*y*z'