droolsdrools-planner

Understanding the Drools planner examples: where is the p‌r‌o‌b‌l‌e‌m state initialized?


I am trying to understand the N Queens and Cloud Balancer examples of Drools. I delved into chapter 3 and 4 of the manual and the sources for the two examples.

I (mis)understand that

  1. The problem has to begin from an unassigned or unoptimal state
  2. So then, the problem facts and planning entities, which are POJOs, have to be instantiated
  3. The solution class, such as CloudBalance or NQueens have to be aware of the problem facts and planning entities

Question 1: In the examples, where are the objects of the planning entity and problem fact classes initialized?

For example, when I load the cloud balancing, I see this:

2012 .. INFO  Loaded: data/cloudbalancing/unsolved/cb-0002comp-0006proc.xml

This means that a serialized format is converted to real objects and fed into a solution right?


Question 2: Where are the planning entities handled?

What is the meaning of that comment? How was that handled in the first place?

public Collection<? extends Object> getProblemFacts() {
    List<Object> facts = new ArrayList<Object>();
    facts.addAll(columnList);
    facts.addAll(rowList);
    // Do not add the planning entity's (queenList) because that will be done automatically 

Solution

  • Q1: The planning instances where created in NQueensGenerator, CurriculumCourseSolutionImporter, ... and then serialized to an XML file with XStream. The load button just deserializes them from XML. Use the import button (not available in all examples) if you want to debug a *SolutionImporter.

    Q2: It means that getProblemFacts() should not do facts.addAll(queenList). Planner does that automatically due to this annotation:

    @PlanningEntityCollectionProperty
    public List<Queen> getQueenList() {
        return queenList;
    }