<meta http-equiv="Content-Type" content="text/html charset=windows-1252">Thanks for clarifying this, I totally agree that the Vehicle is a planning entity and it should be treated as such thought.<div><br></div><div>I will be happy to open a JIRA for this.</div><div>Can you point me to instructions or do/don’t do list so I will do it properly?</div><div><br></div><div>Can you please clarify another thing regarding changes to entities in a ProblemFactChange code:</div><div>When a fact is changed, you call ScoreDirector.beforeProblemFactChanged and ScoreDirector.afterProblemFactChange on the fact object, regardless of the change specifics.</div><div>However, there is no such equivalent for entities.</div><div>My understanding is that you have to call ScoreDirector.beforeVariableChanged and ScoreDirector.afterVariableChange for every change, even for changes to none-panning variables</div><div>For example, when changing the Customer.demand or the Vehicle.capacity.</div><div><br></div><div>It becomes tricky when you need to change none planning variables that take part in calculating the actual solution.&nbsp;</div><div>For example, changing the TimeWindowedCustomer.readyTime might result in constraint violation that is not reflected in the score (arrive before ready time) until the code in&nbsp;ArrivalTimeUpdatingVariableListener is invoked.</div><div><br></div><div>Can you please confirm or correct my understanding?</div><div><br></div><div>Thanks,<br><div apple-content-edited="true">
Hagai<br><br></div>
<br><div><div>On 6 May 2014, at 19:16, ge0ffrey [via Drools] &lt;<a href="/user/SendEmail.jtp?type=node&node=4029444&i=0" target="_top" rel="nofollow" link="external">[hidden email]</a>&gt; wrote:</div><br class="Apple-interchange-newline"><blockquote style='border-left:2px solid #CCCCCC;padding:0 1em' type="cite"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Thanks for reporting.<span class="Apple-converted-space">&nbsp;</span><br><br>That's a terminology bug.<span class="Apple-converted-space">&nbsp;</span><br>The Vehicle isn't both an entity and not an entity...<span class="Apple-converted-space">&nbsp;</span><br>A) It's an entity because it has @PlanningVariable and a shadow variable.<span class="Apple-converted-space">&nbsp;</span><br>B) But it's also not an entity because it doesn't have any genuine<span class="Apple-converted-space">&nbsp;</span><br>variables,<span class="Apple-converted-space">&nbsp;</span><br>and therefore ScoreDirector throws that NPE... (which should be a better<span class="Apple-converted-space">&nbsp;</span><br>error message too).<span class="Apple-converted-space">&nbsp;</span><br>I 'll fix this for 6.1, probably by discarding B).<span class="Apple-converted-space">&nbsp;</span><br><br>Could you file a jira for this?<span class="Apple-converted-space">&nbsp;</span><br>&nbsp; &nbsp;<a href="https://issues.jboss.org/browse/PLANNER" target="_top" rel="nofollow" link="external">https://issues.jboss.org/browse/PLANNER</a><br><br>Workaround for 6.0.1:<span class="Apple-converted-space">&nbsp;</span><br>&nbsp; &nbsp; Presuming you're doing this in a ProblemFactChange,<span class="Apple-converted-space">&nbsp;</span><br>&nbsp; &nbsp; call scoreDirector.beforeProblemFactRemoved() instead of<span class="Apple-converted-space">&nbsp;</span><br>beforeEntityRemoved()<span class="Apple-converted-space">&nbsp;</span><br>&nbsp; &nbsp; =&gt; Treat it as a problem fact for that... but treat is as an entity<span class="Apple-converted-space">&nbsp;</span><br>for everything else.<span class="Apple-converted-space">&nbsp;</span><br><br>hth<span class="Apple-converted-space">&nbsp;</span><br><br>On 06-05-14 16:17, Hagai wrote:<div class="shrinkable-quote"><div class='shrinkable-quote'><br>&gt; Using OptaPlanner 6.0.1.Final with problem like vehiclerouting.<span class="Apple-converted-space">&nbsp;</span><br>&gt;<span class="Apple-converted-space">&nbsp;</span><br>&gt; In vehiclerouting the Vehicle and Customer are both planning entities. They<span class="Apple-converted-space">&nbsp;</span><br>&gt; both implements the Standstill interface that is annotated with<span class="Apple-converted-space">&nbsp;</span><br>&gt; @PlanningEntity and their collections are annotated with<span class="Apple-converted-space">&nbsp;</span><br>&gt; @PlanningEntityCollectionProperty on the solution class.<span class="Apple-converted-space">&nbsp;</span><br>&gt;<span class="Apple-converted-space">&nbsp;</span><br>&gt; Flowing the code of VehicleRoutingPanel.insertLocationAndCustomer to insert<span class="Apple-converted-space">&nbsp;</span><br>&gt; a new Vehicle to the solution, my code is failing when the new Vehicle is<span class="Apple-converted-space">&nbsp;</span><br>&gt; reported to the score director:<span class="Apple-converted-space">&nbsp;</span><br>&gt; scoreDirector.beforeEntityAdded(newVehicle);<span class="Apple-converted-space">&nbsp;</span><br>&gt;<span class="Apple-converted-space">&nbsp;</span><br>&gt; The exception is NullPointerException at<span class="Apple-converted-space">&nbsp;</span><br>&gt; org.optaplanner.core.impl.domain.variable.listener.PlanningVariableListenerSupport.beforeEntityAdded(PlanningVariableListenerSupport.java:54)<span class="Apple-converted-space">&nbsp;</span><br>&gt;<span class="Apple-converted-space">&nbsp;</span><br>&gt; It looks like the PlanningVariableListenerSupport.entityVariableListenerMap<span class="Apple-converted-space">&nbsp;</span><br>&gt; does not have item for the Vehicle entity, there is only one item for the<span class="Apple-converted-space">&nbsp;</span><br>&gt; Customer entity in this map.<span class="Apple-converted-space">&nbsp;</span><br>&gt;<span class="Apple-converted-space">&nbsp;</span><br>&gt; I get the same problem when calling ScoreDirector.beforeEntityRemoved to<span class="Apple-converted-space">&nbsp;</span><br>&gt; remove a Vehicle.<span class="Apple-converted-space">&nbsp;</span><br>&gt;<span class="Apple-converted-space">&nbsp;</span><br>&gt; Is this a bug or do I need to handle Vehicle entities differently?<span class="Apple-converted-space">&nbsp;</span><br>&gt;<span class="Apple-converted-space">&nbsp;</span><br>&gt;<span class="Apple-converted-space">&nbsp;</span><br>&gt;<span class="Apple-converted-space">&nbsp;</span><br>&gt; --<span class="Apple-converted-space">&nbsp;</span><br>&gt; View this message in context:<span class="Apple-converted-space">&nbsp;</span><a href="http://drools.46999.n3.nabble.com/NullPointerException-when-calling-ScoreDirector-beforeEntityAdded-with-new-Vehicle-tp4029434.html" target="_top" rel="nofollow" link="external">http://drools.46999.n3.nabble.com/NullPointerException-when-calling-ScoreDirector-beforeEntityAdded-with-new-Vehicle-tp4029434.html</a><br>&gt; Sent from the Drools: User forum mailing list archive at <a href="http://Nabble.com" target="_top" rel="nofollow" link="external">Nabble.com</a>.<span class="Apple-converted-space">&nbsp;</span><br>&gt; _______________________________________________<span class="Apple-converted-space">&nbsp;</span><br>&gt; rules-users mailing list<span class="Apple-converted-space">&nbsp;</span><br>&gt;<span class="Apple-converted-space">&nbsp;</span>&lt;a href=&quot;x-msg://7/user/SendEmail.jtp?type=node&amp;amp;node=4029440&amp;amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot; link=&quot;external&quot;&gt;[hidden email]</a><span class="Apple-converted-space">&nbsp;</span><br>&gt;<span class="Apple-converted-space">&nbsp;</span><a 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>&gt;</div></div>_______________________________________________<span class="Apple-converted-space">&nbsp;</span><br>rules-users mailing list<span class="Apple-converted-space">&nbsp;</span><br>&lt;a href=&quot;x-msg://7/user/SendEmail.jtp?type=node&amp;amp;node=4029440&amp;amp;i=1&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot; link=&quot;external&quot;&gt;[hidden email]</a><span class="Apple-converted-space">&nbsp;</span><br><a 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 noshade="noshade" size="1"><div style="color: rgb(68, 68, 68); font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-family: 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 href="http://drools.46999.n3.nabble.com/NullPointerException-when-calling-ScoreDirector-beforeEntityAdded-with-new-Vehicle-tp4029434p4029440.html" target="_top" rel="nofollow" link="external">http://drools.46999.n3.nabble.com/NullPointerException-when-calling-ScoreDirector-beforeEntityAdded-with-new-Vehicle-tp4029434p4029440.html</a></div><div style="color: rgb(102, 102, 102); font-style: normal; font-variant: normal; font-weight: normal; font-size: 11px; font-family: tahoma, geneva, helvetica, arial, sans-serif; margin-top: 0.4em; line-height: 1.5em;">To unsubscribe from NullPointerException when calling ScoreDirector.beforeEntityAdded with new Vehicle,<span class="Apple-converted-space">&nbsp;</span><a href="" target="_top" rel="nofollow" link="external">click here</a>.<br><a 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-style: normal; font-variant: normal; font-weight: normal; font-size: 9px; line-height: normal; font-family: serif;" target="_top" link="external">NAML</a></div></div></blockquote></div><br></div>

        
        
        
<br/><hr align="left" width="300" />
View this message in context: <a href="http://drools.46999.n3.nabble.com/NullPointerException-when-calling-ScoreDirector-beforeEntityAdded-with-new-Vehicle-tp4029434p4029444.html">Re: [rules-users] NullPointerException when calling ScoreDirector.beforeEntityAdded with new Vehicle</a><br/>
Sent from the <a href="http://drools.46999.n3.nabble.com/Drools-User-forum-f47000.html">Drools: User forum mailing list archive</a> at Nabble.com.<br/>