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

Add @PreviousElement and @NextElement shadow variables

    XMLWordPrintable

Details

    • Story
    • Resolution: Done
    • Major
    • 8.29.0.Final
    • None
    • optaplanner-core
    • None

    Description

      With inverse and index shadow variables, users can write:

          @InverseRelationShadowVariable(sourceVariableName = "tasks")
          private Employee employee;
          @IndexShadowVariable(sourceVariableName = "tasks")
          private Integer index;
      
          public Task getNextTask() {
              if (index == employee.getTasks().size() - 1) {
                  return null;
              }
              return employee.getTasks().get(index + 1);
          }
      
          public Task getPreviousTask() {
              if (index == 0) {
                  return null;
              }
              return employee.getTasks().get(index - 1);
          }
      

      We can save user from writing boiler plate code with this:

          @PreviousElementShadowVariable(sourceVariableName = "tasks")
          private Task previousTask;
          @NextElementShadowVariable(sourceVariableName = "tasks")
          private Task nextTask;
      
          public Task getPreviousTask() {
              return previousTask;
          }
      
          public Task getNextTask() {
              return nextTask;
          }
      

      Questions:

      • Do users really need it? Task assigning doesn't. VRP uses previousCustomer to calculate route distance.
      • What if VRP performs better with a custom distance updating listener and it turns out it doesn't need previous/next either?

      Attachments

        Activity

          People

            jlocker Jiří Locker
            jlocker Jiří Locker
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: