OptaPlanner构建阶段 - 使用API​​实现移动过滤器

时间:2015-04-05 05:39:47

标签: optaplanner

我需要使用过滤器实现构造启发式,与此线程有类似的需求:OptaPlanner construction phase - Is there a way to define filters?

但是我需要出于某种原因使用Java API实现它。所以我开始使用以下代码:

/* 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);

但他们没有工作。我得到一个空指针异常:

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)

知道我错过了什么吗?

感谢。

0 个答案:

没有答案