Search code examples
optaplanner

MoveIteratorFactory purpose


As i can understand from the documentation the purpose of the "MoveIteratorFactory" is to generate the moves as they are needed to be played out at every step.

Is the "getSize" method how big the subset of moves will be?

What is the difference between "createOriginalMoveIterator" and "createRandomMoveIterator"?

Will the "createOriginalMoveIterator" regenerate a subset of moves again in a later step or not?

I guess that the move is played out after the method next() is called (after its creation) in both the cases?

Is this the best solution if there are a lot moves that need to be generated ,because in my case there are many moves that need to be first of all generated let alone played out?

Is there a smarter way to generate custom combined moves at every step that are based on the current state of the solution?


Solution

  • The MoveIteratorFactory is a more complex alternative to MoveListFactory which avoids creating a List<Move> by creating an Iterator<Move> instead. In Java 8 terms, it has a lot in common with a Stream.

    Suppose you have 50k entities and 10k values. A list of all changemoves would contain 500m elements, causing memory issues and a serious delay loss every time a step starts. To avoid that, it generates a changemove just in time, at Iterator.next() or hasNext().

    For that to work well, it needs to behave differently if the iterator needs to selects moves randomly (= might select the same move twice, this is not shuffled, it's random!) or original order.