问题
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