0

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.

Community
  • 1
  • 1
oy321
  • 367
  • 2
  • 8
  • Note that most users that use filter (to have a build-in hard constraints) should probably be using just a normal hard constraint instead. The docs have been recently amended for that (not sure if its published yet). – Geoffrey De Smet Apr 06 '15 at 12:49
  • Thanks Geoffrey. The reason that I was looking at using filter is, in my case there are some extreme scenarios that say only 1 out of 10,000 processes can be allocated to Machine X. If any other process is allocated to this machine it'll break hard constraint. By creating such a hard constraint is very expensive as the planner struggles to find the only alllocatable process. Even implementing a ProcessDifficultyWeightFactory doesn't help too much. That's why I wanted to prevent un-allowed matches from happening. – oy321 Apr 09 '15 at 06:18
  • Use "ValueRangeProvider from entity" instead of "ValueRangeProvider from Solution" - that will solve those extreme scenario's. See docs for info. – Geoffrey De Smet Apr 09 '15 at 06:31
  • Thanks! That's exactly what I needed. I did have a ValueRangeProvider but from solution. I saw another thread: http://stackoverflow.com/questions/26794063/optaplanner-valueselector-can-not-use-valuerangetype-from-planning-entity-prop which says when using the ValueRangeProvider from planning entity, the Sorted selection order cannot be used but have to manually sort values in ValueRangeProvider instead. To keep the randomness of selection, I'd also like to use JIT + Random combination. Will that work? – oy321 Apr 13 '15 at 11:35

0 Answers0