atomica.optimization.constrain_sum_bounded

atomica.optimization.constrain_sum_bounded(x, s, lb, ub)[source]

Bounded nearest constraint sum

Parameters:
  • x (array) – Array of proposed values to constrain

  • s (float) – Target value for sum(x)

  • lb (array) – Array of lower bounds, same size as x

  • ub (array) – Array of upper bounds, same size as x

  • tolerance – Absolute tolerance for the constrained sum s

Return type:

array

Returns:

Array same size as x, such that sum(x)==s and x[i]>=lb and x[i]<=ub for i<len(x)

Raises:

FailedConstraint if it was not possible to constrain