dimod.binary.BinaryQuadraticModel.to_polystring#

BinaryQuadraticModel.to_polystring(encoder: Callable[[Hashable], str] | None = 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'