Retrieve drools working memory from Optaplanner solution

北城以北 提交于 2019-12-08 06:24:04

问题


When drl file used while solving constraints one could use insertLogical() which insert facts in drools working memory only and may not be retracted till completion of solution(LHS stay true forever for that insertLogical()). When we get solution from Optaplanner's solver.solve(), we receive our own solution classes option like NurseRoster, CloudBalance. But how could I retrieve facts which stayed in Drools working memory till my solution stayed so I can see what caused solution?

I'm looking for something like:

solver.solve(nurseRoster);
scoreDirector.getDroolsWorkingMemory().getNotRetractedFacts()

Any help is appreciated. Thanks


回答1:


The working memory is not avialable after solution has been processed, however use scoreDirector in this way to retrieve it from an active session:

    solver.getScoreDirectorFactory().buildScoreDirector()    
    director=(DroolsScoreDirector<Solution>)((DefaultSolver)solver).getSolverScope().getScoreDirector();
    LegacyDroolsScoreDirectorFactory<TaskPlanningSolution> scoreDirectorFactory = (LegacyDroolsScoreDirectorFactory)director.getScoreDirectorFactory();
    KnowledgeBaseImpl kbase=(KnowledgeBaseImpl)scoreDirectorFactory.getKieBase();//.newKieSession();
    InternalWorkingMemory internalWorkingMemory =((StatefulKnowledgeSessionImpl)kbase.getWorkingMemories()[0]).getInternalWorkingMemory();


来源:https://stackoverflow.com/questions/46703743/retrieve-drools-working-memory-from-optaplanner-solution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!