LinearIntegerEquation

class trainsum.linearintegerequation.LinearIntegerEquation(dims, coeffs, rhs, solver=<pulp.apis.coin_api.COIN_CMD object>)

Linear integer equation: \(\sum^N_i c_i x_i = \Delta\). \(c_i\) are integer coefficients, \(x_i\) are the dimensions and \(\Delta\) is the right hand side.

Parameters:
  • dims (tuple[Dimension, ...])

  • coeffs (tuple[int, ...])

  • rhs (int)

  • solver (GLPK_CMD | COIN_CMD | COPT_CMD | SCIP_CMD | CHOCO_CMD | CPLEX_CMD | FSCIP_CMD | HiGHS_CMD | MIPCL_CMD | GUROBI_CMD | XPRESS | PULP_CBC_CMD)

inner(other)

Calculates the inner product between this equation and another equation. The inner product is defined as 1.0 if the two equations are identical, and 0.0 otherwise.

Parameters:

other (IntegerEquation)

Return type:

float

has_solution()

Determines whether the integer equation has a solution given the current evaluated values.

Return type:

bool

to_tensor(xp)

Returns a tensor representation of the integer equation, where the shape of the tensor corresponds to the dimensions of the equation, and the values are 1.0 for indices that satisfy the equation and 0.0 for indices that do not.

Parameters:

xp (ArrayNamespace)

Return type:

T

tensor_shape()

Returns the shape that to_tensor will product.

Return type:

tuple[int, …]

factorize(*idxs)

Factorizes the integer equation into sub-equations based on the provided indices. Each index tuple corresponds to a dimension and specifies which digits of that dimension to factorize over. The method returns a tuple containing two lists: the first list contains the indices for each dimension that were used for factorization, and the second list contains the resulting sub-equations after factorization.

Parameters:

idxs (Sequence[int])

Return type:

tuple[Sequence[Sequence[int]], Sequence[IntegerEquation]]