Skip to main content

Goals and Constraints

Rebalancer lets you express what you want from an assignment as goals and constraints, built from a library of 25+ reusable specs. Some specs work only as a goal, some only as a constraint, and many as either.

  • A constraint defines what makes an assignment valid; it must hold.
  • A goal is a quantity to minimize; with several goals, their relative priority decides how they trade off.

To add them to the solver, use addConstraint and addGoal. Only the spec is required; the remaining parameters are optional:

solver.addConstraint(spec, policy, invalidCost, invalidState, tuplePosIfBroken);
solver.addGoal(spec, weight, tuplePos);
  • For a constraint, policy and the invalidCost / invalidState / tuplePosIfBroken tuning control its constraint policy: how a constraint that is already broken in the initial assignment is treated (fixed best-effort by default, or made strictly hard or soft).
  • For a goal, weight and tuplePos control its goal priorities: how it trades off against other goals.

Available specs

Where a spec has its own page, its name links to it. The Type column shows whether a spec can be used as a goal, a constraint, or either. Examples links to the spec's unit tests.

Capacity and limits

SpecTypeDescriptionExamples
CapacityBothLimit each scope item's utilization for a dimension to a max (or min)unit tests
ToFreeBothDrain the listed containers, driving their utilization for a dimension to zerounit tests
Group CountBothLimit how many objects of a group a scope item holds, or their total for a dimensionunit tests
GroupDiversityBothRequire each scope item to hold at least, or at most, N distinct groupsunit tests
CapacityWithGroupPresenceBothLimit each scope item's utilization, with every present group counting for at least a minimum weightunit tests
GroupCapacityBothLimit each group's total utilization across all scope items in a scopeunit tests
GroupIsolationLimitBothLimit how many groups may exceed their utilization limit in the same scope item (default 1)unit tests
DisasterRecoveryCapacityBothReserve enough spare capacity so scope items can survive correlated failure scenariosunit tests

Balancing and packing

SpecTypeDescriptionExamples
BalanceGoalBalance a dimension's utilization evenly across scope itemsunit tests
UtilIncreaseCostGoalPenalize raising a scope item's utilization above a lower boundunit tests
MinimizeContainersGoalMinimize the number of scope items usedunit tests
MaximizeAllocationGoalMaximize utilization on a set of scope itemsunit tests
MinimizeNthLargestUtilizationGoalMinimize the n-th largest scope-item utilization (n is 0-based)unit tests
MinimizeSquaresGoalMinimize the sum of squared scope-item utilizationsunit tests
WorkingSetGoalMinimize the average or maximum working-set size across scope itemsunit tests

Placement

SpecTypeDescriptionExamples
NonAcceptingConstraintPrevent objects from moving into the listed scope itemsunit tests
AvoidAssignmentsConstraintForbid specific object-to-scope-item assignmentsunit tests
ColocateGroupsBothLimit how many scope items each group spreads across (default: one)unit tests
ExclusiveScopeItemsBothForbid pairs of scope items from being used at the same timeunit tests

Movement

SpecTypeDescriptionExamples
AvoidMovingConstraintPrevent the listed objects from movingunit tests
GroupMoveLimitConstraintLimit how many objects of a group may moveunit tests
MovesInProgressConstraintAccount for objects already moving between containersunit tests
MinimizeMovementBothMinimize the number (or dimension-weighted amount) of objects movedunit tests

Affinities

SpecTypeDescriptionExamples
AssignmentAffinitiesGoalMake specific objects prefer specific scope itemsunit tests
PairAffinitiesBothMake pairs of objects prefer the same scope itemunit tests
GroupAssignmentAffinitiesGoalMake specific groups prefer specific scope itemsunit tests
ScopeAffinitiesGoalReward or penalize each scope item's utilization of a dimension via a per-scope-item weightunit tests