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

Constraint Streams: tuple-based constraint weight

XMLWordPrintable

    • Icon: Feature Request Feature Request
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • None
    • Constraint Streams
    • None
    • NEW
    • NEW

      At the moment, constraint streams require us to duplicate constraints in some cases:

          constraint.filter(task -> task.getPriority() == Priority.MAJOR)
                      .penalize("Major priority task end time",
                              BendableScore.ofSoft(0, 2, 0, 1),
                              Task::getEndTime);
          }
      
          constraint.filter(task -> task.getPriority() == Priority.MINOR)
                      .penalize("Minor priority task end time",
                              BendableScore.ofSoft(0, 2, 1, 1),
                              Task::getEndTime);
          }
      

      Notice that the constraints are identical, except for the constraint weight (BendableScore), which depends on a property of the entity. This could be simplified and also made more performant, if we indeed replaced this by one constraint like this:

          constraint.penalize("Task end time",
                              task -> {
                                  if (task.getPriority() == Priority.MAJOR) {
                                      return BendableScore.ofSoft(0, 2, 0, 1);
                                  } else {
                                      return BendableScore.ofSoft(0, 2, 1, 1);
                                  }
                              },
                              Task::getEndTime);
          }
      

      This example is adapted from OptaPlanner's TaskAssigning example, which would need updating when this feature is implemented.

              Unassigned Unassigned
              lpetrovi@redhat.com Lukáš Petrovický (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: