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

Add @PreviousElement and @NextElement shadow variables

XMLWordPrintable

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

      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?

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

                Created:
                Updated:
                Resolved: