1

I have a Planning Solution class containing a method getProblemFacts() to load facts in working memory. but i am not able to get the facts in DRL file.

Some code snippet is as follows :

@Override
    public Collection<? extends Object> getProblemFacts() {
        List<Object> facts = new ArrayList<Object>();
        facts.add(users);
        facts.add(resources);
        facts.add(availabilityList);
        facts.add(fromDate);
        facts.add(toDate);
        return facts
    }

DRL File :

rule Rule4
when
    $users : org.volcare.brms.event.User(userName == "User10") 
    //$value : org.volcare.brms.event.User() from $users
then
    System.out.println("Test");
end

Config file is :

<?xml version="1.0" encoding="UTF-8"?>
<solver>
  <solutionClass>org.volcare.brms.event.EventSolution</solutionClass>
  <planningEntityClass>com.volcare.brms.EventPlanning</planningEntityClass>

  <scoreDirectorFactory>
    <scoreDefinitionType>HARD_SOFT</scoreDefinitionType>
     <scoreDrl>/eventrule.drl</scoreDrl>
  </scoreDirectorFactory>
  <termination>
    <maximumSecondsSpend>90</maximumSecondsSpend>
  </termination>

  <constructionHeuristic>
    <constructionHeuristicType>FIRST_FIT</constructionHeuristicType>
  </constructionHeuristic>

  <localSearch>
    <unionMoveSelector>
      <changeMoveSelector>
        <valueSelector>
          <variableName>eventDate</variableName>
        </valueSelector>
      </changeMoveSelector>
    </unionMoveSelector>
    <acceptor>
      <entityTabuRatio>0.2</entityTabuRatio>
      <lateAcceptanceSize>500</lateAcceptanceSize>
    </acceptor>
    <forager>
      <acceptedCountLimit>4</acceptedCountLimit>
    </forager>
  </localSearch>
</solver>

Planning entity is accessible in DRL file. Please let me know if i am missing something.

Harish Garg
  • 139
  • 8
  • 1
    Your question is not quite clear. Can you please clarify? The title says that you are unable to load facts in DRL, but the last line in your question states "Planning entity is accessible in DRL file." – kaskelotti Aug 12 '14 at 12:32
  • I have not added planning entity in facts as it is by default accessible in working memory but other facts are not accessible in DRL file. For eg i am trying to access User fact but it is not running. – Harish Garg Aug 12 '14 at 12:37
  • Added a simple rule to just check if the users facts is available or not. – Harish Garg Aug 12 '14 at 12:44
  • One thing to note is that the DRL match `$users : org.volcare.brms.event.User(userName == "User10")` would not give you a list of users. It would give you a single user. To match a list, you would need to write a match for a `List`, or use `collect` to gather individual users into a list. – Steve Aug 12 '14 at 12:50
  • 1
    It's also worth noting that if you are inserting the result of `getProblemFacts()`, then you have no `User` facts in working memory. Instead you have an `ArrayList` fact, which contains objects of various types. – Steve Aug 12 '14 at 12:51
  • If i am trying with this rule its still not working rule Rule4 when $users : org.volcare.brms.event.User() $value : org.volcare.brms.event.User() from $users then System.out.println("Test" + $value); end – Harish Garg Aug 12 '14 at 12:52
  • @Steve : If i can insert an arraylist of facts then i can also get the Domain that i have inserted in DRL file. For reference you can see the Job scheduling example solved in optaplanner distribution. – Harish Garg Aug 12 '14 at 12:56
  • 1
    That's because, as I mentioned, `$users` is not a list. It's a single `User` if one happens to have been inserted into working memory. I'm not sure what you mean by your second comment. If you insert an `ArrayList` of facts then you need to write DRL to match an `ArrayList` fact and then match on `User() from $yourlist`. – Steve Aug 12 '14 at 13:02
  • @Steve Can you rewrite the rule as i am not able to get you what you trying to say? – Harish Garg Aug 12 '14 at 13:06
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/59185/discussion-between-harish-garg-and-steve). – Harish Garg Aug 12 '14 at 13:11

0 Answers0