[jboss-svn-commits] JBL Code SVN: r18487 - labs/jbossrules/trunk/documentation/manual/en/Chapter-Solver.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Feb 17 11:53:49 EST 2008


Author: ge0ffrey
Date: 2008-02-17 11:53:49 -0500 (Sun, 17 Feb 2008)
New Revision: 18487

Modified:
   labs/jbossrules/trunk/documentation/manual/en/Chapter-Solver/Section-Local_Search_Solver.xml
   labs/jbossrules/trunk/documentation/manual/en/Chapter-Solver/Section-Score_calculation.xml
   labs/jbossrules/trunk/documentation/manual/en/Chapter-Solver/Section-Solver_configuration.xml
   labs/jbossrules/trunk/documentation/manual/en/Chapter-Solver/Section-Solver_examples.xml
   labs/jbossrules/trunk/documentation/manual/en/Chapter-Solver/Section-Solver_introduction.xml
Log:
StartingSolutionInitializer changes, at least those that I could sift out after they got corrupted... + dtd headers as in irooskov's commit

Modified: labs/jbossrules/trunk/documentation/manual/en/Chapter-Solver/Section-Local_Search_Solver.xml
===================================================================
--- labs/jbossrules/trunk/documentation/manual/en/Chapter-Solver/Section-Local_Search_Solver.xml	2008-02-17 16:23:03 UTC (rev 18486)
+++ labs/jbossrules/trunk/documentation/manual/en/Chapter-Solver/Section-Local_Search_Solver.xml	2008-02-17 16:53:49 UTC (rev 18487)
@@ -1,4 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
+]>
 <section>
   <title>Local search solver</title>
 
@@ -32,9 +34,9 @@
 
     <para>An algorithm that checks every possible solution (even with pruning)
     can easily run for a couple of years on a single real-life planning
-    problem. Most of the time, we 're happy with a feasible solution found in
+    problem. Most of the time, we are happy with a feasible solution found in
     a limited amount of time. Local search tends to find a feasible solution
-    relatively fast. Because it acts very much like a human, it's also pretty
+    relatively fast. Because it acts very much like a human, it is also pretty
     natural to program.</para>
 
     <para>Local search solves a problem making a move on the current solution
@@ -723,10 +725,16 @@
         &lt;maximumHouresSpend&gt;1&lt;/maximumHouresSpend&gt;
     &lt;/finish&gt;</programlisting>
 
-      <para>Notice that if you use this finish, you will most likely sacrifice
-      reproducability. The best solution will depend on real-time process
-      speed, not only because it influences the amount of steps taken, but
-      also because time gradient based algoritms (such as simulated annealing)
+      <para>Note that the time taken by a
+      <literal>StartingSolutionInitializer</literal> also is taken into
+      account by this finish. So if you give the solver 2 minutes to solve
+      something, but the initializer takes 1 minute, the local search solver
+      will only have a minute left.</para>
+
+      <para>Note that if you use this finish, you will most likely sacrifice
+      reproducability. The best solution will depend on available CPU time,
+      not only because it influences the amount of steps taken, but
+      also because time gradient based algorithms (such as simulated annealing)
       will probably act differently on each run.</para>
     </section>
 

Modified: labs/jbossrules/trunk/documentation/manual/en/Chapter-Solver/Section-Score_calculation.xml
===================================================================
--- labs/jbossrules/trunk/documentation/manual/en/Chapter-Solver/Section-Score_calculation.xml	2008-02-17 16:23:03 UTC (rev 18486)
+++ labs/jbossrules/trunk/documentation/manual/en/Chapter-Solver/Section-Score_calculation.xml	2008-02-17 16:53:49 UTC (rev 18487)
@@ -1,4 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
+]>
 <section>
   <title>Score calculation with a rule engine</title>
 

Modified: labs/jbossrules/trunk/documentation/manual/en/Chapter-Solver/Section-Solver_configuration.xml
===================================================================
--- labs/jbossrules/trunk/documentation/manual/en/Chapter-Solver/Section-Solver_configuration.xml	2008-02-17 16:23:03 UTC (rev 18486)
+++ labs/jbossrules/trunk/documentation/manual/en/Chapter-Solver/Section-Solver_configuration.xml	2008-02-17 16:53:49 UTC (rev 18487)
@@ -1,4 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
+]>
 <section>
   <title>Solver configuration</title>
 
@@ -259,29 +261,8 @@
     <para>A Solver can only solve 1 problem at a time.</para>
 
     <para>You need to present the problem as a starting
-    <literal>Solution</literal> instance to the solver. Usually you will make
-    that starting solution with a simple filler algorithm. For example for 4
-    queens we use a starting solution with all queens on a different x and on
-    the same y (with y = 0).</para>
+    <literal>Solution</literal> instance to the solver.</para>
 
-    <figure>
-      <title>Starting solution for the 4 queens puzzle</title>
-
-      <mediaobject>
-        <imageobject>
-          <imagedata fileref="unsolvedNQueens04.svg" format="SVG" />
-        </imageobject>
-
-        <imageobject>
-          <imagedata fileref="unsolvedNQueens04.png" format="PNG" />
-        </imageobject>
-      </mediaobject>
-    </figure>
-
-    <para>The starting solution will probably be far from optimal (or even
-    feasible), but that's OK, as it's the solver's job to find a much better
-    solution.</para>
-
     <para>You need to implement the <literal>Solution</literal>
     interface:</para>
 
@@ -293,7 +274,8 @@
 
 }</programlisting>
 
-    <para>For example:</para>
+    <para>For example, an NQueens instance just holds a list of all it's
+    queens:</para>
 
     <programlisting>public class NQueens implements Solution {
 
@@ -360,6 +342,114 @@
   </section>
 
   <section>
+    <title>The starting solution</title>
+
+    <para>First, you will need to make a starting solution and set that on the
+    solver:</para>
+
+    <programlisting>solver.setStartingSolution(startingSolution);</programlisting>
+  </section>
+
+  <section>
+    <title>A simple filler algorithm</title>
+
+    <para>For 4 queens we use a simple filler algorithm that creates a
+    starting solution with all queens on a different x and on the same y (with
+    y = 0).</para>
+
+    <figure>
+      <title>Starting solution for the 4 queens puzzle</title>
+
+      <mediaobject>
+        <imageobject>
+          <imagedata fileref="unsolvedNQueens04.svg" format="SVG" />
+        </imageobject>
+
+        <imageobject>
+          <imagedata fileref="unsolvedNQueens04.png" format="PNG" />
+        </imageobject>
+      </mediaobject>
+    </figure>
+
+    <para>Here's how we generate it:</para>
+
+    <programlisting>    private NQueens createNQueens(int n) {
+        NQueens nQueens = new NQueens();
+        nQueens.setId(0L);
+        List&lt;Queen&gt; queenList = new ArrayList&lt;Queen&gt;(n);
+        for (int i = 0; i &lt; n; i++) {
+            Queen queen = new Queen();
+            queen.setId((long) i);
+            queen.setX(i); // Different column
+            queen.setY(0); // Same row
+            queenList.add(queen);
+        }
+        nQueens.setQueenList(queenList);
+        return nQueens;
+    }</programlisting>
+
+    <para>The starting solution will probably be far from optimal (or even
+    feasible). Here it's actually the worst possible solution. However, we 'll
+    let the solver find a much better solution for us anyway.</para>
+
+    <section>
+      <title>StartingSolutionInitializer</title>
+
+      <para>For large problems, a simple filler algorithm like
+      <literal>createNQueens(int)</literal> doesn't suffice. A (local search)
+      solver starting from a bad starting solution wastes a lot of time to
+      reach a solution which an initializer algorithm can generate in a
+      fraction of that time.</para>
+
+      <para>An initializer algorithm ussually works something like this:</para>
+
+      <itemizedlist>
+        <listitem>
+          <para>It sorts the unplanned elements in a queue according to some
+          general rules, for example by exam student size.</para>
+        </listitem>
+
+        <listitem>
+          <para>Next, it plans them in the order they come from the queue.
+          Each element is put the best still available spot.</para>
+        </listitem>
+
+        <listitem>
+          <para>It doesn't change an already planned element. It exits when
+          the queue is empty and all elements are planned.</para>
+        </listitem>
+      </itemizedlist>
+
+      <para>Such an algorithm is very deterministic: it's really fast, but you
+      can't give it more time to generate an even better solution. In some
+      cases the solution it generates will be feasible, but in most cases it
+      won't. You 'll need a real solver to get to a feasible or more optimal
+      solution. Nevertheless you 'll want to such an initializer to give the
+      real solver a serious head start. You can do this by implementing the
+      <literal>StartingSolutionInitializer</literal> interface:</para>
+
+      <programlisting>TODO
+TODO
+TODO</programlisting>
+
+      <para>You'll need to set a (uninitialized) solution on the solver. Once
+      the solver starts, it will first call the
+      <literal>StartingSolutionInitializer</literal> to initialize the
+      solution.</para>
+
+      <para>Here's an example on how you add the
+      <literal>StartingSolutionInitializer</literal> to the configuration:
+      </para>
+
+      <programlisting>&lt;localSearchSolver&gt;
+    ...
+    &lt;startingSolutionInitializerClass&gt;org.drools.solver.examples.itc2007.examination.solver.solution.initializer.ExaminationStartingSolutionInitializer&lt;/startingSolutionInitializerClass&gt;
+    ...
+&lt;/localSearchSolver&gt;</programlisting>
+    </section>
+  </section>
+
+  <section>
     <title>Solving a problem</title>
 
     <para>Solving a problem is quite easy once you have a solver and the

Modified: labs/jbossrules/trunk/documentation/manual/en/Chapter-Solver/Section-Solver_examples.xml
===================================================================
--- labs/jbossrules/trunk/documentation/manual/en/Chapter-Solver/Section-Solver_examples.xml	2008-02-17 16:23:03 UTC (rev 18486)
+++ labs/jbossrules/trunk/documentation/manual/en/Chapter-Solver/Section-Solver_examples.xml	2008-02-17 16:53:49 UTC (rev 18487)
@@ -1,4 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
+]>
 <section>
   <title>Solver examples</title>
 
@@ -766,8 +768,80 @@
             </row>
 
             <row>
+              <entry>exam_comp_set5</entry>
+
+              <entry>8719</entry>
+
+              <entry>1018</entry>
+
+              <entry>42</entry>
+
+              <entry>3</entry>
+
+              <entry></entry>
+
               <entry>?</entry>
 
+              <entry>1?</entry>
+            </row>
+
+            <row>
+              <entry>exam_comp_set6</entry>
+
+              <entry>7909</entry>
+
+              <entry>242</entry>
+
+              <entry>16</entry>
+
+              <entry>8</entry>
+
+              <entry></entry>
+
+              <entry>?</entry>
+
+              <entry>1?</entry>
+            </row>
+
+            <row>
+              <entry>exam_comp_set7</entry>
+
+              <entry>13795</entry>
+
+              <entry>1096</entry>
+
+              <entry>80</entry>
+
+              <entry>28</entry>
+
+              <entry></entry>
+
+              <entry>?</entry>
+
+              <entry>1?</entry>
+            </row>
+
+            <row>
+              <entry>exam_comp_set8</entry>
+
+              <entry>7718</entry>
+
+              <entry>598</entry>
+
+              <entry>80</entry>
+
+              <entry>8</entry>
+
+              <entry></entry>
+
+              <entry>?</entry>
+
+              <entry>1?</entry>
+            </row>
+
+            <row>
+              <entry>?</entry>
+
               <entry>s</entry>
 
               <entry>t</entry>

Modified: labs/jbossrules/trunk/documentation/manual/en/Chapter-Solver/Section-Solver_introduction.xml
===================================================================
--- labs/jbossrules/trunk/documentation/manual/en/Chapter-Solver/Section-Solver_introduction.xml	2008-02-17 16:23:03 UTC (rev 18486)
+++ labs/jbossrules/trunk/documentation/manual/en/Chapter-Solver/Section-Solver_introduction.xml	2008-02-17 16:53:49 UTC (rev 18487)
@@ -1,4 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
+]>
 <section>
   <title>Solver introduction</title>
 




More information about the jboss-svn-commits mailing list