Drools - rule hierarchy and conditional execution - nested

I was wondering if there is a way to define hierarchy (not just order of execution) between rules and control the rule execution - i.e. if the parent rule fired then the ones below should not be evaluated etc...
Information in this thread is an option but it is essentially IF/THEN/ELSE
Is there a different option?
thanks

I am not sure if I understand your question, but using a combination of Activation Groups and the traditional conflict resolution strategies might achieve what you need. For instance, lets say you have 3 rules, A, B and C. You want to use, lets say, salience to give priority of execution to them in that order, and once one is executed, no other rule in that group should execute. You can define them like this:
rule A
salience 30
activation-group "x"
...
rule B
salience 20
activation-group "x"
...
rule C
salience 10
activation-group "x"
...
The salience guarantees that if A activates, it will fire first, followed by B, followed by C if they were activated. The Activation Group guarantees that once one of the rules fire, all other activated rules in that group will be cancelled. So, lets say that in your session, rules B and C activate, but not A, then B will fire and C will be cancelled.
Please note that activation groups do not prevent rules from later being re-activated. It just cancels any activations currently in the agenda at the time one of the rules in the group fire.

Related

What is the uncontrollable automatic propagation behavior in ECLIPSe-CLP?

I am trying to research, evaluate, and compare some searching methods in ECLIPSe-CLP. The key method of evaluating complexity and the efficacy of a method in said system is counting backtracks, implemented with the predicate search/6 from lib(ic_search). However, in my testing, I noticed that the Eclipse software applies some process similar to domain propagation automatically before entering the search, which I have no way of controlling, which apparently solves certain problems without any backtracks. This hinders my evaluation of search methods as I have no control over the domains and/or problem statement when it passes into search. I would like to know what the process employed is, and whether it can be disabled or if I can work around it. Attached below is a very primitive sample code and its tracing. Problems such as SEND + MORE = MONEY and the Australian Map coloring problems can be similarly solved with 0 backtracks.
Thanks in advance!
Eclipse code
:- lib(ic), lib(ic_global), lib(ic_search).
go :-
simpleproblem(Vars).
simpleproblem(Vars) :-
Vars = [A,B],
Vars :: [0..1],
A + B #= 2,
search(Vars,0,input_order,indomain,complete,[backtrack(Backtracks)]),
writeln(backtracks:Backtracks),
writeln(Vars).
Tracing log
(1) 1 CALL go
(2) 2 CALL simpleproblem(_598)
(3) 3 CALL ... = ...
(3) 3 EXIT ... = ...
(4) 3 CALL '::_body'([_1028, _1030], [0 .. 1], eclipse)
(4) 3 EXIT '::_body'([_1476{[0, ...]}, _1490{[...]}], [0 .. 1], eclipse)
(5) 3 CALL _1490{[0, ...]} + _1476{[0, ...]} #= 2
(9) 4 CALL wake
(6) 5 RESUME<2> 0 #= 0
(6) 5 EXIT<2> 0 #= 0
(9) 4 EXIT wake
(5) 3 EXIT 1 + 1 #= 2
(10) 3 CALL search_body([1, 1], 0, input_order, indomain, complete, [backtrack(_3046)], eclipse)
The very reason for the effectiveness of Constraint Programming is the principle of interleaving propagation with search. Because this is really the essence of CP, I am not sure it makes much sense for you to look at search methods in isolation.
Propagation is performed in a data-driven way by the implementation of each individual constraint: whenever a variable domain changes, e.g. during the initial constraint setup or by a search decision, the constraint will try to propagate the consequences. This may lead to more domain changes, which cause further propagation, and so on, until a fixpoint is reached.
Once no further propagation is possible, the search control takes over again, looks at the the constraint network and current variable domains, and decides on the next guess. When a guess is made (in the form of a variable instantiation, domain splitting, etc), propagation is triggered again.
Implementation-wise, there is a clear separation: propagation is done by the individual constraints (in your example #=/2 only), while the search control algorithm is in the search/6 predicate. However, there is a strong interdependency between them, because they communicate back-and-forth via the constraint network.
Note that most search techniques, such as the popular first-fail heuristics, heavily rely on the result of propagation, otherwise they could not make their informed guesses. While in principle it would be possible for you to use non-propagating implementations for all constraints (e.g. wait for all their variables to be instantiated, and only then test for satisfaction), this would make many search options pointless, and you would not learn much by counting backtracks.

How to call complete internal flows multiple times in Sequence Diagrams

Main Idea: To convert an activity diagram into a sequence diagram.
Problem: I want that if "Action 2" fails then, in that case all the flows get triggered again from "Action 1".
(i.e Action 1 --> Action 2 --> then the verification again. and this should happen until Action 2 is Successful)
Basically, the flow works like a GOTO function and then from there triggers all the steps again.
I have tried to use a ref block but again it seems that it might be ambiguous and someone might read it only as the "execution of Action 1" and not the steps after it.
Therefore I wanted some hints to make this sort of scenario clear. Any suggestions would be appreciated.
Attaching the image for better clarity of the problem.
The activity and sequence diagrams are not supposed to be equivalent. Both set a different focus (flow vs interactions) and as a consequence you might have to do the mapping by identifying higher-level constructs.
Here you have clearly a loop:
You could reformulate in pseudocode as: REPEAT action 1 and action 2 UNTIL action 2 passes, which is a loop that has the test in the end. You could further rewrite this loop into: Last did not passed; WHILE last did not pass, DO action 1 and action 2, or WHILE true DO action 1 and action 2 and BREAk if it succeeds.
Now you can use a loop fragment to achieve this behavior in a sequence diagram. This fragment would enclose action1, action 2, and the test for success, and after the loop, would come the interaction for the success case. The nesting makes it very explicit what gets repeated and what not. For example, some variant of:

How can I test this (interaction) pattern

Hi, I have some troubles understanding which analysis is suitable to test this expected pattern.
The idea here is that in Condition 1, the difference between A and B is higher, but small between C and IC. In Condition 2, the difference between C and IC should be higher, but lower between A and B. Ideally, I would like to test this via a three-way ANOVA (2x2x2), but as the graphs are parallel in both plots, it seems that there would not be a significant interaction. Does anyone have an idea? Thanks a lot in advance
The proposed model seems to be something like:
RT ~ Condition * GroupAB * GroupCIC
Based on the plots provided, this should produce output with:
no meaningful 3-way interaction, nor a meaningful 2-way interaction between GroupAB and GroupCIC since the lines are parallel in both conditions.
A meaningful Condition:GroupCIC interaction, since the lines are further apart in condition 2 that condition 1
A meaningful Condition:GroupAB interaction, since the slopes of the lines are different between the two conditions.

DDD - No Lazy loading - how to do certain tasks without draining the database?

I'm working on a module for a larger solution.
In this solution they tried in the past to work with DDD.
However that didn't turn out how it should of been because there was no DDD expert. (and there still isn't one present imo.)
Everything was under a single root aggregate, lazy loading was enabled, and so on.
Now for the new module we want to make it better.
However i'm failing to see how i can use DDD without lazy loading and not drain the entire database.
For example i have an object let's call it "B".
B has a flag let's say "AwesomeFlag"
B has children
If one of B's children is Awesome, then B is awesome as well.
If none of B's children is Awesome, then B isn't awesome.
Now if I would not work with DDD; I'd just get B and execute a linq query that check's if one of B's children is awesome without actually retrieving all of the children.
However if i got a domainobject where i am not allowed to perform queries, how can i do this?
Is DDD forcing me to get all of B's children just to get the calculated flag "IsAwesome" to work?
Or how am i supposed to do this correctly in a DDD environment?
A small hint in which direction i need to focus my research on would be appreciated.
UPDATE
As I was a bit broad in what my question is I'd like to rephrase whilst still using the same terms to be consistent.
B is awesome when one of it's children is awesome.
B itself, does not have a flag "awesome" as this is a calculated field based on the children.
B could have quite a few children, with the children each having allot of properties and data, which you do not want to retrieve just to check if one of the children is Awesome.
B has a method ShouldIBecomeADeveloper
If one of B's children is awesome, making B awesome, it should return a boolean "true"
If none of B's children are awesome, making B not awesome, it should return a boolean "false"
Disclaimer: although this is somehow a valid question, it is very broad, thus it may have many different valid answers.
You need to analyze the business requirements regarding the valid states in which the system is allowed to be. For this you need to answer the question: after a child of B becomes awesome, how fast needs B to become awesome as well?
There are two answers:
Immediately, in a strongly consistent matter. This means that the "awesome mutation" of a child of B and the "awesome mutation" of B are performed in an atomic fashion, they are in the same transaction. In this case you must load B and all its children before mutating one of its children awesomeness. The children of B are nested entities inside the B Aggregate.
It can be delayed, eventually changing its awesomeness to match the business rule, that is, the system can be for some time in a temporary invalid state. In this case, the children of B are also Aggregates. You need a way of mutating B when one of its "past childrens" mutate and for this you can use a Saga/Process manager.
In neither of the two cases you don't use lazy-loading, there is not such thing in case of DDD Aggregates. You can't anyway, if you have pure Aggregates, with no dependencies to Repositories (as you should).
B itself, does not have a flag "awesome" as this is a calculated field based on the children.
Even though "awesome" is a calculated field any operation you perform on the child entity has to go through "B" only, as it is the aggregate root. So you could have a state in "B" called numberOfAwesomeChildren and a child can become awesome/not awesome only when some operation happens on it and since all the operations are directed via "B" only, you can update the numberOfAwesomeChildren whenever a child becomes awesome/not awesome.
So "B" is awesome when numberOfAwesomeChildren is greater than zero.
Even this solution won't solve your lazy loading problem, since to perform an operation on a child entity you will end up loading all the child entity. You may have to have a re-look at your design.

One transition with multiple events in UML State diagram

We are learning in school that behavioral State diagram's transition has syntax:
list of events [guard condition] / list of actions
But I couldn't find any example on Internet where is used transition with multiple events. Is it really possible? If yes, how does it behave? Does it mean that transaction is realized when one of this events occurs (and of course condition is fulfilled)?
Yes, a transition can be triggered by one of many events in a list. You would use such a construct to avoid multiple lines between states, making a tidier diagram.
Here is what the 2.5 spec says:
14.2.3.9.2 Enabled Transitions
A Transition is enabled if and only if:
[ . . . ]
At least one of the triggers of the Transition has an Event that is matched by the Event type of the dispatched Event occurrence.
These logically OR'ed transitions are specified textually as a comma-separated list on the transition, as specified in §14.2.4.9:
[<trigger> [‘,’ <trigger>]* [‘[‘ <guard>’]’] [‘/’ <behavior-expression>]]
Unfortunately the UML spec is not specific in that respect (I thought, but Jim has the right answer). Anyway:
14.2.4.9 Transition
The default textual notation for a Transition is defined by the following BNF expression:
[<trigger> [‘,’ <trigger>]* [‘[‘ <guard>’]’] [‘/’ <behavior-expression>]]
Where is the standard notation for Triggers (see sub clause 13.3.4), is a Boolean expression for a guard, and the optional is an expression specifying the effect Behavior written in some vendor- specific or standard textual surface language (see sub clause 16.1). The trigger may be any of the standard trigger types. SignalEvent triggers and CallEvent triggers are not distinguishable by syntax and must be discriminated by their declaration elsewhere.
There are other places in the specs where this paragraph appears in similar way, but without explaining how multiple triggers will be treated. I assume that it's an OR-condition. But that's only an assumption. Alas, since you have not seen examples (me neither) it is probably an unknown fact. Just don't use it - that's indeed possible ;-) And if you happen to find an example, just ask the author what he meant. UML is about talking to each other.

Resources