<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#ffffff">
    <br>
    <br>
    Op 28-06-11 11:23, Michael Anstis schreef:
    <blockquote
      cite="mid:BANLkTikivKqSp9LSDUH-6YYO1DnJGd51Ww@mail.gmail.com"
      type="cite">Not completely understanding why solver.solve() would
      only run for 1ms, </blockquote>
    It seems stupid indeed, but there are some cases:<br>
    - Cancellation: the user presses the "terminate early" button<br>
    - Cancellation: the whole system is going down (ctrl-c / kill)<br>
    - In real-time planning cases, the answer is needed NOW (even though
    we just started planning 1 or 10ms ago).<br>
    In that last case you'll probably still want to have an initialized
    solution and configure it appropriate to do random initialization (=
    really fast and really stupid) anyway.<br>
    <br>
    So it looks like cancellation is the only real use case.<br>
    And I 'll support JBRULES-3105 "Planner: construction heuristics
    should be able to optionally ignore terminateEarly until a solution
    is initialized" in the future,<br>
    for the real-time planning case.<br>
    <blockquote
      cite="mid:BANLkTikivKqSp9LSDUH-6YYO1DnJGd51Ww@mail.gmail.com"
      type="cite">isn't a partially initialised starting solution a
      runtime error and (3) have solver.getBestSolution() throw a
      "SolutionsNotInitialisedException" an option?<br>
    </blockquote>
    Intresting idea. It should definitely not be a checked exception.
    Let's call this 3)<br>
    <br>
    <blockquote type="cite">1) It returns null. So you 'll need to do
      null checks:<br>
      Solution bestSolution = solver.getBestSolution();<br>
      if (bestSolution == null) {<br>
      &nbsp; &nbsp; &nbsp;// ... do things with bestSolution<br>
      &nbsp; &nbsp; &nbsp;Score bestScore = bestSolution.getScore();<br>
      }<br>
      <br>
      2) It returns the partially initialized solution. So you'll need
      to do<br>
      isBestSolutionInitialized checks:<br>
      Solution bestSolution = solver.getBestSolution();<br>
      if (solver.isBestSolutionInitialized()) {<br>
      &nbsp; &nbsp; &nbsp;// ... do things with bestSolution<br>
      &nbsp; &nbsp; &nbsp;Score bestScore = bestSolution.getScore();<br>
      }</blockquote>
    3) it throws a SolutionUninitialisedException (runtime exception)<br>
    If you configured JBRULES-3105, then this works:<br>
    &nbsp;&nbsp;&nbsp;&nbsp;
    Solution bestSolution = solver.getBestSolution();<br>
    &nbsp;&nbsp;&nbsp;&nbsp;
    // ... do things with bestSolution<br>
    &nbsp;&nbsp;&nbsp;&nbsp;
    Score bestScore = bestSolution.getScore();<br>
    Otherwise, you probably want to do this instead:<br>
    try {<br>
    &nbsp;&nbsp;&nbsp;&nbsp;
    Solution bestSolution = solver.getBestSolution();<br>
    &nbsp;&nbsp;&nbsp;&nbsp;
    // ... do things with bestSolution<br>
    &nbsp;&nbsp;&nbsp;&nbsp;
    Score bestScore = bestSolution.getScore();<br>
    } catch (SolutionUninitialisedException e) {<br>
    &nbsp;&nbsp;&nbsp; // ...<br>
    }<br>
    <blockquote
      cite="mid:BANLkTikivKqSp9LSDUH-6YYO1DnJGd51Ww@mail.gmail.com"
      type="cite">
      <br>
      <div class="gmail_quote">On 28 June 2011 10:18, Geoffrey De Smet <span
          dir="ltr">&lt;<a moz-do-not-send="true"
            href="mailto:ge0ffrey.spam@gmail.com">ge0ffrey.spam@gmail.com</a>&gt;</span>
        wrote:<br>
        <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
          0.8ex; border-left: 1px solid rgb(204, 204, 204);
          padding-left: 1ex;">
          Normally you use Planner like this:<br>
          <br>
          solver.solve()<br>
          Solution bestSolution = solver.getBestSolution();<br>
          // ... do things with bestSolution<br>
          Score bestScore = bestSolution.getScore();<br>
          <br>
          But let's suppose we give it 1 millisecond to plan and use a
          big,<br>
          uninitialized starting solution<br>
          and our initialization algorithm actually terminates
          immediately as<br>
          requested.<br>
          It won't be able to completely initialize the solution in that
          case.<br>
          What should solver.getBestSolution() return in that case? null
          or the<br>
          partially initialized solution?<br>
          <br>
          1) It returns null. So you 'll need to do null checks:<br>
          Solution bestSolution = solver.getBestSolution();<br>
          if (bestSolution == null) {<br>
          &nbsp; &nbsp; &nbsp;// ... do things with bestSolution<br>
          &nbsp; &nbsp; &nbsp;Score bestScore = bestSolution.getScore();<br>
          }<br>
          <br>
          2) It returns the partially initialized solution. So you'll
          need to do<br>
          isBestSolutionInitialized checks:<br>
          Solution bestSolution = solver.getBestSolution();<br>
          if (solver.isBestSolutionInitialized()) {<br>
          &nbsp; &nbsp; &nbsp;// ... do things with bestSolution<br>
          &nbsp; &nbsp; &nbsp;Score bestScore = bestSolution.getScore();<br>
          }<br>
          <br>
          What makes more sense?<br>
          <br>
          --<br>
          With kind regards,<br>
          Geoffrey De Smet<br>
          <br>
          <br>
          _______________________________________________<br>
          rules-dev mailing list<br>
          <a moz-do-not-send="true"
            href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a><br>
          <a moz-do-not-send="true"
            href="https://lists.jboss.org/mailman/listinfo/rules-dev"
            target="_blank">https://lists.jboss.org/mailman/listinfo/rules-dev</a><br>
        </blockquote>
      </div>
      <br>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
rules-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-dev">https://lists.jboss.org/mailman/listinfo/rules-dev</a>
</pre>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 
With kind regards,
Geoffrey De Smet</pre>
  </body>
</html>