<!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">
    Cedric is referring to this issue:<br>
    &nbsp; <a class="moz-txt-link-freetext" href="https://issues.jboss.org/browse/JBRULES-3461">https://issues.jboss.org/browse/JBRULES-3461</a><br>
    Currently, the following implementation should be respected for
    entities:<br>
    - solutionHashCode() must include the variables, and hashCode() must
    not include the variables<br>
    (same for solutionEquals() and equals() of course)<br>
    1) Check if your code follows that?<br>
    2) Does your code follow the equals() and hashCode() contract of
    Java?<br>
    <br>
    I agree with you guys that a changing hashcode might have caused
    this.<br>
    - The entity X is inserted into a Set or Map with a hashcode A.<br>
    - While it's in that Set or Map, the entity X changes which also
    changes it's hashcode value to B.<br>
    - This effectively corrupts the Set or Map, because X is still in
    bucket A%n, while it should be in bucket B%n,<br>
    so the Set or Map will report that it doesn't contain X.<br>
    <br>
    That fact that uncommented equals() and hashcode() together doesn't
    fix it, means that:<br>
    a) either the superclass has an equals/hashcode problem<br>
    b) either it's not a hashcode related problem<br>
    c) the 2 Meeting entities are different instances, that represent
    the same entity. This is only possible if you create or remove
    entities in moves. =&gt; In this case you cannot rely on object
    identity and you must implement an equals/hashcode implementation
    based on at least some sort of id (for example a database primary
    key or uuid).<br>
    <br>
    <blockquote type="cite"><span>It seems to happen randomly, with
        different entities each time</span></blockquote>
    If environmentMode == REPRODICBLE or DEBUG or TRACE (so not
    PRODUCTION)<br>
    and you're not using simulated annealing (~ timegradient based),
    then 2 runs should be exactly the same always (more info in manual
    on environmentMode).<br>
    <br>
    So, if they are still not in that case, the only thing I can think
    of that differs between runs is the memory addresses of the entity
    instances which are used in object identity.<br>
    Object.hashCode() is implemented to return the memory address.
    Object.equals() returns true if it's the same memory address. The
    memory address doesn't change during 1 run, but it differs from run
    to run.<br>
    So how can that explain that "randomly" behavior? Because in a Map
    of capacity 10, the hashCode() gets % 10, so about 1 out of 10
    instances with different hashCode()s do end up in the same bucket
    (and this differs from run to run).<br>
    <br>
    3) Can you turn on environmentMode TRACE, just to verify that it
    doesn't fail on anything else sooner?<br>
    <br>
    <blockquote type="cite"><span>I couldn't find an easy way to add a
        knowledge session logger in planner, but that might also be
        useful.</span></blockquote>
    I don't think there is an easy way at this time. Feel free to create
    a jira issue that DroolsScoreDirector or DroolsScoreDirectorFactory
    should support that.<br>
    <br>
    Op 05-05-12 04:35, Cedric Hurst schreef:
    <blockquote cite="mid:3105E4889C574EA297F74FD6F2455601@spantree.net"
      type="cite">
      <div> yeah, i have a solutionEquals() and solutionHashCode() as
        well. I tried dumping my hashCode() and equals() methods on the
        PlanningEntity but that didn't seem to have much effect. &nbsp;My
        hashCode() and solutionHashCode() values now both change when I
        assign a different supplier, but planner still can't seem to
        find the entity in working memory.</div>
      <div>
        <div><br>
        </div>
        --
        <div><span style="font-family: arial,sans-serif;
            background-color: rgb(255, 255, 255);">Build Smarter
            Software.</span><span style="font-family: arial,sans-serif;
            background-color: rgb(255, 255, 255);"><br>
          </span><span style="font-family: arial,sans-serif;
            background-color: rgb(255, 255, 255);"><br>
          </span><span style="font-family: arial,sans-serif;
            background-color: rgb(255, 255, 255);">Spantree Technology
            Group, LLC</span></div>
        <div><span style="font-family: arial,sans-serif;
            background-color: rgb(255, 255, 255);">813 W Randolph St,
            Suite 301<br>
          </span><span style="font-family: arial,sans-serif;
            background-color: rgb(255, 255, 255);">email:</span><span
            style="font-family: arial,sans-serif; background-color:
            rgb(255, 255, 255);">&nbsp;</span><span style="font-family:
            arial,sans-serif; background-color: rgb(255, 255, 255);"><a
              moz-do-not-send="true"
              href="/user/SendEmail.jtp?type=node&amp;node=3963892&amp;i=0"
              target="_top" rel="nofollow" link="external">[hidden
              email]</a></span><span style="font-family:
            arial,sans-serif; background-color: rgb(255, 255, 255);">&nbsp;</span><span
            style="font-family: arial,sans-serif; background-color:
            rgb(255, 255, 255);">| phone:</span><span
            style="font-family: arial,sans-serif; background-color:
            rgb(255, 255, 255);">&nbsp;</span><span style="font-family:
            arial,sans-serif; background-color: rgb(255, 255, 255);">&lt;a
            href="tel:773.359.3865" value="+17733593865"
            target="_blank"&gt;773.359.3865</span><span
            style="font-family: arial,sans-serif; background-color:
            rgb(255, 255, 255);"><br>
          </span><span style="font-family: arial,sans-serif;
            background-color: rgb(255, 255, 255);"><a
              moz-do-not-send="true" href="http://www.spantree.net/"
              target="_blank" rel="nofollow" link="external">http://www.spantree.net</a></span></div>
        <div><br>
        </div>
      </div>
      <p style="color: rgb(160, 160, 168);">On Friday, May 4, 2012 at
        8:51 PM, Christopher Dolan [via Drools] wrote:</p>
      <blockquote type="cite" style="border-left-style: solid;
        border-width: 1px; margin-left: 0px; padding-left: 10px;"> <span>
          <div>
            <div>
              <meta http-equiv="Content-Type" content="text/html;
                charset=ISO-8859-1">
              <div style="direction: ltr; font-family: Tahoma; color:
                rgb(0, 0, 0); font-size: 10pt;">Try just commenting out
                your .equals() and .hashCode() methods. My experience
                was that Planner is unexpectedly sensitive to hashcode
                algorithms, and identity equality just worked best. I
                ended up implementing a solutionEquals like some of the
                example code.<br>
                Chris<br>
                <br>
                <div style="font-family: Times New Roman; color: rgb(0,
                  0, 0); font-size: 16px;">
                  <hr tabindex="-1">
                  <div style="direction: ltr;"><font color="#000000"
                      face="Tahoma" size="2"><b>From:</b> <a
                        moz-do-not-send="true"
                        href="/user/SendEmail.jtp?type=node&amp;node=3963850&amp;i=0"
                        target="_top" rel="nofollow" link="external">[hidden
                        email]</a> [<a moz-do-not-send="true"
                        href="/user/SendEmail.jtp?type=node&amp;node=3963850&amp;i=1"
                        target="_top" rel="nofollow" link="external">[hidden
                        email]</a>] on behalf of Cedric Hurst [<a
                        moz-do-not-send="true"
                        href="/user/SendEmail.jtp?type=node&amp;node=3963850&amp;i=2"
                        target="_top" rel="nofollow" link="external">[hidden
                        email]</a>]<br>
                      <b>Sent:</b> Friday, May 04, 2012 5:09 PM<br>
                      <b>To:</b> <a moz-do-not-send="true"
                        href="/user/SendEmail.jtp?type=node&amp;node=3963850&amp;i=3"
                        target="_top" rel="nofollow" link="external">[hidden
                        email]</a><br>
                      <b>Subject:</b> [rules-users] Drools Planner:
                      entity was never added to this ScoreDirector?<br>
                    </font><br>
                  </div>
                  <div>
                    <p>Hi all,</p>
                    <p>I'm working on a Drools Planner 5.4.0.CR1
                      implementation for a scheduling app.</p>
                    <p>First, some background:</p>
                    <p>The solution class is 'Schedule' and the
                      PlanningEntity is 'Meeting'. Meetings consist of
                      timeslots (or 'slots'), and two participants in
                      complimentary roles 'planners' and 'suppliers'.
                      Since there are more planners than suppliers, I've
                      structured the Schedule model so that its meeting
                      collection is basically the cross-product of slots
                      and planners. Suppliers are configured as the
                      @PlanningVariable in a meeting. The meeting list
                      in the schedule is also annotated as a
                      @PlanningEntityCollectionProperty. I've structured
                      three MoveFactories that add, subtract or swap
                      suppliers from meeting to meeting.</p>
                    <p>That part works fairly well, however, when I try
                      to try to run my solution through a Solver, I am
                      inevitably plagued with a dreaded message like
                      this:</p>
                    <pre>        java.lang.IllegalArgumentException: The entity (Meeting[slot: 26, planner: 29C2E0FF-00EE-409F-B05B-B175B30A6B45, supplier: BB25B297-54FA-45BD-923A-C209848E74B4,
        hashCode: 1219749520, solutionHashCode: -1086095971, slotHashCode: 436282962, plannerHashCode: -2037841459]) was never added to this ScoreDirector.
                at org.drools.planner.core.score.director.drools.DroolsScoreDirector.afterAllVariablesChanged(DroolsScoreDirector.java:110)
                at org.drools.planner.core.score.director.drools.DroolsScoreDirector.afterVariableChanged(DroolsScoreDirector.java:120)
                at com.somecompany.scheduler.moves.AddSupplierToMeetingMove.doMove(AddSupplierToMeetingMove.groovy:36)
                at org.drools.planner.core.localsearch.decider.DefaultDecider.doMove(DefaultDecider.java:128)
                at org.drools.planner.core.localsearch.decider.DefaultDecider.decideNextStep(DefaultDecider.java:103)
                at org.drools.planner.core.localsearch.DefaultLocalSearchSolverPhase.solve(DefaultLocalSearchSolverPhase.java:57)
                at org.drools.planner.core.solver.DefaultSolver.runSolverPhases(DefaultSolver.java:183)
                at org.drools.planner.core.solver.DefaultSolver.solve(DefaultSolver.java:151)
                at org.spockframework.util.GroovyRuntimeUtil.invokeMethod(GroovyRuntimeUtil.java:100)
                at com.somecompany.scheduler.solver.SolverSpec.should solve schedule(SolverSpec.groovy:59)
</pre>
                    <p>It seems to happen randomly, with different
                      entities each time, but I've not yet had a
                      successful run of a full solve cycle without
                      hitting it a least once. Unfortunately, it kills
                      my whole process.</p>
                    <p>I've step debugged through the planner internals
                      and verified that all the meetings are getting
                      added to the working memory, including the
                      offending one:</p>
                    <pre>        2012-05-04 16:30:17,379 INFO  com.somecompany.scheduler.solver.SolverSpec  - Meeting[slot: 26, planner: 29C2E0FF-00EE-409F-B05B-B175B30A6B45, supplier:
        FEA76C13-C9E2-42EC-977C-BCBB0BD1FFA0, hashCode: 1219749520, solutionHashCode: -574491332, slotHashCode: 436282962, plannerHashCode: -2037841459]
</pre>
                    <p>I was pretty certain my issue has to do with the
                      meeting's hashCode value, but as you'll see
                      they're exactly the same in working memory as they
                      are when . I'm using commons HashCodeBuilder and
                      EqualsBuilder to check only the fixed slot and
                      planner values. The solutionHashCode changes based
                      on the slot, planner and supplier-- supplier being
                      the @PlanningVariable. I've pasted the full log,
                      with trace enabled, here for review:</p>
                    <a moz-do-not-send="true"
href="https://gist.github.com/raw/93752853a0996ae1c016/d0ca35f5c531a2fa25e6a106c90257b015500931/solver-error.log"
                      target="_top" rel="nofollow" link="external">https://gist.github.com/raw/93752853a0996ae1c016/d0ca35f5c531a2fa25e6a106c90257b015500931/solver-error.log</a>
                    <p>The error is listed at 2012-05-04 16:30:37,168.</p>
                    <p>The original meeting in working memory is listed
                      at 2012-05-04 16:30:17,379 (toward the middle of
                      entries with that timestamp).</p>
                    <p>I couldn't find an easy way to add a knowledge
                      session logger in planner, but that might also be
                      useful.</p>
                    <br>
                    <hr width="300" align="left">
                    View this message in context: <a
                      moz-do-not-send="true"
href="http://drools.46999.n3.nabble.com/Drools-Planner-entity-was-never-added-to-this-ScoreDirector-tp3963528.html"
                      target="_blank" rel="nofollow" link="external">
                      Drools Planner: entity was never added to this
                      ScoreDirector?</a><br>
                    Sent from the <a moz-do-not-send="true"
                      href="http://drools.46999.n3.nabble.com/Drools-User-forum-f47000.html"
                      target="_blank" rel="nofollow" link="external">
                      Drools: User forum mailing list archive</a> at <a
                      moz-do-not-send="true" href="http://Nabble.com"
                      target="_top" rel="nofollow" link="external">Nabble.com</a>.<br>
                  </div>
                </div>
              </div>
              <br>
              _______________________________________________
              <br>
              rules-users mailing list
              <br>
              <a moz-do-not-send="true"
                href="/user/SendEmail.jtp?type=node&amp;node=3963850&amp;i=4"
                target="_top" rel="nofollow" link="external">[hidden
                email]</a>
              <br>
              <a moz-do-not-send="true"
                href="https://lists.jboss.org/mailman/listinfo/rules-users"
                target="_top" rel="nofollow" link="external">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
              <br>
              <br>
              <hr color="#cccccc" noshade="noshade" size="1">
              <div style="color: rgb(68, 68, 68); font: 12px
                tahoma,geneva,helvetica,arial,sans-serif;">
                <div style="font-weight: bold;">If you reply to this
                  email, your message will be added to the discussion
                  below:</div>
                <a moz-do-not-send="true"
href="http://drools.46999.n3.nabble.com/Drools-Planner-entity-was-never-added-to-this-ScoreDirector-tp3963528p3963850.html"
                  target="_top" rel="nofollow" link="external">http://drools.46999.n3.nabble.com/Drools-Planner-entity-was-never-added-to-this-ScoreDirector-tp3963528p3963850.html</a>
              </div>
              <div style="color: rgb(102, 102, 102); font: 11px/1.5em
                tahoma,geneva,helvetica,arial,sans-serif; margin-top:
                0.4em;"> To unsubscribe from Drools Planner: entity was
                never added to this ScoreDirector?, <a
                  moz-do-not-send="true" href="" target="_top"
                  rel="nofollow" link="external">click here</a>.<br>
                <a moz-do-not-send="true"
href="http://drools.46999.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&amp;id=instant_html%21nabble%3Aemail.naml&amp;base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&amp;breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml"
                  rel="nofollow" style="font: 9px serif;" target="_top"
                  link="external">NAML</a> </div>
            </div>
          </div>
        </span> </blockquote>
      <div> <br>
      </div>
      <br>
      <hr width="300" align="left">
      View this message in context: <a moz-do-not-send="true"
href="http://drools.46999.n3.nabble.com/Re-rules-users-Drools-Planner-entity-was-never-added-to-this-ScoreDirector-tp3963892.html">Re:
        [rules-users] Drools Planner: entity was never added to this
        ScoreDirector?</a><br>
      Sent from the <a moz-do-not-send="true"
        href="http://drools.46999.n3.nabble.com/Drools-User-forum-f47000.html">Drools:
        User forum mailing list archive</a> at Nabble.com.<br>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 
With kind regards,
Geoffrey De Smet</pre>
  </body>
</html>