For my planning problem with one real planning entity class I need to declare various PriorityQueue
s in one of the problem classes.
However, I’m getting following error message:
Exception in thread "main" java.lang.IllegalStateException: The cloneCollectionClass (class java.util.ArrayList) created for originalCollectionClass (class java.util.PriorityQueue) is not assignable to the field's type (class java.util.PriorityQueue).
Maybe consider replacing the default SolutionCloner.
So it seems that PriorityQueue
is not cloned as a PriorityQueue by default, but replaced by an ArrayList
by the default cloner.
The manual says
When the FieldAccessingSolutionCloner clones one of your collections
or maps, it may not recognize the implementation and replace it with
ArrayList, LinkedHashSet, TreeSet, LinkedHashMap or TreeMap (whichever
is more applicable) . It recognizes most of the common JDK collection
and map implementations.
So PriorityQueue
is not in the ‘most common JDK collection … implementations.’ Fine, it’s not even a Collection
.
There are three possible solutions to my problem:
- Place the
PriorityQueue
s in a customVariableListener
(onePriorityQueue
per planning fact, e.g. in a Map), then make sure theVariableListener
is triggered properly - Don’t bother with PriorityQueues, convert all to
ArrayList
and just sort the Array (e.g.,Arrays.sort(pq.toArray())
) as required in my customVariableListener
- Create a custom
SolutionCloner
as suggested by the error message. I don’t really want to write one from scratch, I’d prefer just to extend the custom cloner.
And here are my two questions:
- Any hints on a preference of the three solutions points above?
- Where is the custom cloner located and how would I start extending it?
Thank you in advance!