Uploaded image for project: 'OptaPlanner'
  1. OptaPlanner
  2. PLANNER-713

Support for zero-based variance / standard deviation (for fairness/load balancing constraints) in Drools DRL in Tennis example

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Done
    • Icon: Blocker Blocker
    • 7.0.0.Beta7
    • None
    • optaplanner-core
    • None
    • NEW
    • NEW

      Problem: It's hard to mix a fairness constraint with another constraint on the same score level and remain dataset size independent.

      Solution: Standard deviation instead of variance for fairness rules is needed to allow other constraints at the same score level.
      Well, its not exactly standard deviation and variance (as it's relative to zero instead of the average), so we'll call it loadBalance() instead.

      BEFORE: This is slow and verbose:

      rule "fairAssignmentCountPerTeam"
          when
              accumulate(
                  $t : Team()
                  and accumulate(
                      $a : TeamAssignment(team == $t);
                      $teamTotal : count($a)
                  );
                  $total : sum($teamTotal.intValue() * $teamTotal.intValue())
              )
          then
              scoreHolder.addMediumConstraintMatch(kcontext, - (int) (Math.sqrt($total) * 1_000_000.0));
      end
      

      AFTER: We'll introduce an accumulate function called loadBalance():

      rule "fairAssignmentCountPerTeam"
          when
              accumulate(
                  TeamAssignment($t : team);
                  $total : loadBalance($t)
              )
          then
              scoreHolder.addMediumConstraintMatch(kcontext, - (int) ($total * 1_000_000.0));
      end
      

              gdesmet@redhat.com Geoffrey De Smet (Inactive)
              gdesmet@redhat.com Geoffrey De Smet (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: