The rule below assumes that markets is List<Market> in Town and ids is List<Integer> in a Market.<br><br>It does not rely on Market or even Location objects being facts, and there's no problem if a location id is re-used in another town.<br>
<br>rule findThree<br>when<br> $t: Town( $name: name, $markets: markets )<br> $s: HashSet( $size: size ==3 )<br> from accumulate( $m: Market() from $markets,<br> init( HashSet set = new HashSet(); )<br>
action( set.addAll( $m.getIds() ); )<br> result( set ) )<br>then<br> System.out.println( $name + " is a three-location town " + $s );<br>end<br><br><br>
<div class="gmail_quote">2011/11/14 Michael Anstis <span dir="ltr"><<a href="mailto:michael.anstis@gmail.com">michael.anstis@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Something like this?<br><br><span style="font-family: courier new,monospace;">when</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> $t : Town( )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> $s : SuperMarket( town == $t, $lid : locationId )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> $ls : HashSet( size == 3) from ( Location( locationId = $lid ) )</span><br style="font-family: courier new,monospace;">
<br>I suspect Location would have to override equals and hashCode correctly.<br><br>Once you have some DRL that works I'd suggest moving to Guvnor.<div><div></div><div class="h5"><br><br><div class="gmail_quote">On 12 November 2011 23:15, LCode <span dir="ltr"><<a href="mailto:j_whittlesea@hotmail.com" target="_blank">j_whittlesea@hotmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I am trying to write a rule via the guided rule editor and I am really<br>
struggling.<br>
<br>
The following is a simplified explanation of my scenario:<br>
<br>
I have a model where there are lots of 'Town' objects, each town has any<br>
number of 'Supermarket' objects and each supermarket has a list of integers<br>
'locationID'.<br>
<br>
Something like this....<br>
<br>
<Town><br>
<Supermarket name = 'asda'><br>
<LocationID>15</LocationID><br>
<LocationID>18</LocationID><br>
</Supermarket><br>
<Supermarket name = 'tesco'><br>
<LocationID>13</LocationID><br>
</Supermarket><br>
<Supermarket name = 'lidl'><br>
<LocationID>13</LocationID><br>
<LocationID>15</LocationID><br>
<LocationID>18</LocationID><br>
</Supermarket><br>
</Town><br>
<br>
(apologies to the Sainsburys shoppers!!)<br>
<br>
I need to write a rule that fires when there are precisely 3 unique location<br>
ID's in the whole town.<br>
<br>
So in the example above the complete list of locationIDs would be 13, 13,<br>
15, 15, 18, 18<br>
With the following unique numbers 13, 15, 18<br>
therefore the rule would fire as there are 3 unique numbers.<br>
<br>
I hope that makes some sense.<br>
<br>
I understand that I should collect the locationIDs into a java.util.Set in<br>
order to count unique entries and I can collect together all supermarkets<br>
into an arraylist. However I cannot for the life of me seem to collect<br>
LocationID across all supermarkets.<br>
<br>
Thank you so much in anticipation, I realise this was rather long-winded!<br>
<span><font color="#888888"><br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/Collecting-properties-in-a-rule-tp3503523p3503523.html" target="_blank">http://drools.46999.n3.nabble.com/Collecting-properties-in-a-rule-tp3503523p3503523.html</a><br>
Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></span></blockquote></div><br>
</div></div><br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>