Skip to content

Move Director: repeated operations over list variable cause issues #1906

@triceo

Description

@triceo

Consider a custom move which does the following on a problem with list variable:

  • Unassign value A from entity X at position Y in the list.
  • Unassign value B from entity X at position Y+1 in the list.

This should be simple, but it's not. At the time the move executes this operation, Y and Y+1 are fixed. But when the first unassign happens, the old Y+1 becomes Y. (A was removed from the list, shifting B to where A used to be.) This in turn causes all sorts of ArrayIndexOutOfBounds exceptions.

Before MoveDirector, the user could deal with this manually:

A: Call before() methods
A: Do the unassigning
A: Call after() methods
A: Trigger var listeners
B: Call before() methods
B: Do the unassigning
B: Call after() methods
B: Trigger var listeners

Now that MoveDirector tries to abstract this complexity away, the user only does this:

moveDirector.unassign(A);
moveDirector.unassign(B);

And then eventually, the solver triggers var listeners and calculates score. The internal representation is messed up after A changes, which makes the B change fail. This problem needs solving. We don't want to expose the var listener triggers. We also don't want users to keep their own track of these indexes, or think of this problem at all. So what other options are there?

  1. Do a manual trigger within each unassign operation. Is that possible? Will it work with undo? Is it efficient?
  2. Inside the list var state, shift every index when we read that something was unassigned (and assigned, and moved)? This is possibly a massive slowdown on each such operation.
  3. Provide a bulk unassign operation, where we take care of this internally?
  4. Keep an internal representation of these events, aggregate them, and only execute them once before score calculation?
  5. Something else?
    Note: This will affect most (if not all) operations on the list variable. Once a variable is removed from the list, or another added, indexes of other variables are invalidated and keep being invalid until the next var listener trigger.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions