Consider I have a set of N activities with a given start and end times and I want to assign them to a set of rooms.<div><br></div><div>One of the main rules is to avoid two activities that have time conflicts, to be assigned to the same room. I devised three modelling options:</div>

<div><br></div><div>[1] Do it entirely in Java code, checking whether there will be a conflict before allowing an &quot;Assignment move&quot;. This way, all solutions that the algorithm works with are feasible.</div><div>
<br></div><div>[2] Do it using drools rules, like the following:</div>
<div><br></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">rule &quot;Avoid conflicting activities&quot;</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">when </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><span style="white-space:pre-wrap">        </span>Assignment($room1: room, $act1: activity, $id : <a href="http://activity.id" target="_blank">activity.id</a>)</font></div>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><span style="white-space:pre-wrap">        </span>Assignment(room == $room1, room!= null, $act2 : activity, <a href="http://activity.id" target="_blank">activity.id</a> &gt; $id)</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><span style="white-space:pre-wrap">        </span>eval(Activity.conflict($act1, $act2))</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">then</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><span style="white-space:pre-wrap">        </span>insertLogical(new IntConstraintOccurrence(&quot;conflictingActivities&quot;, ConstraintType.NEGATIVE_HARD,</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">                10, null));</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">end </font></div><div><br></div><div>Here I&#39;m using Assignment as the only planning entity. There&#39;s an assignment for each activity and it may point to a room or to null in the case the activity is not assigned. In the case above, I have a static function that checks whether two activities conflicts. This way, solutions may be infeasible but with high penalties the best solution found will eventually be feasible.</div>
<div><br></div><div>I also thought of a third option, which is to insert a fact &quot;Conflict&quot; for each pair of conflicting activities in a preprocessing phase. This way we would end up with:</div><div><br></div><div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">rule &quot;Avoid conflicting activities&quot;</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">when </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><span style="white-space: pre-wrap; ">        </span>Assignment($room1 : room, $act1: activity, $id : <a href="http://activity.id/" target="_blank">activity.id</a>)</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><span style="white-space: pre-wrap; ">        </span>Assignment(room== $room1, room != null, $act2 : activity, <a href="http://activity.id/" target="_blank">activity.id</a> &gt; $id)</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><span style="white-space: pre-wrap; ">        </span>Conflict(act1 == $act1, act2 == $act2)</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">then</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><span style="white-space: pre-wrap; ">        </span>insertLogical(new IntConstraintOccurrence(&quot;conflictingActivities&quot;, ConstraintType.NEGATIVE_HARD,</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">                10, null));</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">end </font></div></div><div><br>
</div><div>The problem is that there may be up to O(N^2) such objects. </div><div><br></div><div>I do not know the rules engine algorithm in depth, so I&#39;d like to know: Is any of these approaches more efficient than the others?</div>
<div><br></div><div>Thanks!</div>