I need to implement the construction heuristic with a filter, with a similar need as this thread: OptaPlanner construction phase - Is there a way to define filters?
However I need to implement it with the Java API for some reason. So I started with the following code:
/* A. Set Construction Heuristic */
ConstructionHeuristicSolverPhaseConfig constructionHeuristicSolverPhaseConfig = new ConstructionHeuristicSolverPhaseConfig();
constructionHeuristicSolverPhaseConfig
.setConstructionHeuristicType(ConstructionHeuristicType.FIRST_FIT);
/****************/
QueuedEntityPlacerConfig chQueuedEntityPlacerConfig = new QueuedEntityPlacerConfig();
List<MoveSelectorConfig> chMoveSelectorConfigList = new ArrayList<MoveSelectorConfig>();
MoveListFactoryConfig chMoveListFactoryConfig = new MoveListFactoryConfig();
chMoveListFactoryConfig
.setMoveListFactoryClass(...MyChangeMoveFactory.class);
chMoveSelectorConfigList.add(chMoveListFactoryConfig);
chQueuedEntityPlacerConfig.setMoveSelectorConfigList(chMoveSelectorConfigList);
List<EntityPlacerConfig> chEntityPlacerConfigList = new ArrayList<EntityPlacerConfig>();
chEntityPlacerConfigList.add(chQueuedEntityPlacerConfig);
constructionHeuristicSolverPhaseConfig.setEntityPlacerConfigList(chEntityPlacerConfigList);
/****************/
solverPhaseConfigList.add(constructionHeuristicSolverPhaseConfig);
but they are not working. I am getting a null pointer exception:
Exception in thread "main" java.lang.NullPointerException
at org.optaplanner.core.impl.heuristic.selector.move.factory.MoveListFactoryToMoveSelectorBridge.iterator(MoveListFactoryToMoveSelectorBridge.java:89)
at org.optaplanner.core.impl.constructionheuristic.placer.QueuedEntityPlacer$QueuedEntityPlacingIterator.createUpcomingSelection(QueuedEntityPlacer.java:54)
at org.optaplanner.core.impl.constructionheuristic.placer.QueuedEntityPlacer$QueuedEntityPlacingIterator.createUpcomingSelection(QueuedEntityPlacer.java:30)
at org.optaplanner.core.impl.heuristic.selector.common.iterator.UpcomingSelectionIterator.hasNext(UpcomingSelectionIterator.java:40)
at org.optaplanner.core.impl.constructionheuristic.DefaultConstructionHeuristicSolverPhase.solve(DefaultConstructionHeuristicSolverPhase.java:65)
at org.optaplanner.core.impl.solver.DefaultSolver.runSolverPhases(DefaultSolver.java:190)
Any idea of what did I miss?
Thanks.