How to implement less and more than rules with decision table in drools?

I would like to implement simple rules based on smaller and larger values ​​in drools using a decision table.

Simply implement the rules in drl, for example:

rules "less than" when Example(value < 10) then System.out.println("Less than 10") end rules "equals" when Example(value = 10) then System.out.println("Equals 10") end rules "greater than" when Example(value > 10) then System.out.println("Greater than 10") end 

But how can I translate it into a decision table in drools? All the examples I've seen so far are comparisons in the status cell. Is it even possible to perform a comparison in a value cell?

The whole example that I saw is in the format:

 CONDITION | ACTION Example | value | -----------------------------------|------------------------------------- 10 | System.out.println("equals to 10") 

But this applies only to rule 1, and the implementation of the following has a completely different meaning:

 CONDITION | CONDITION | CONDITION | ACTION Example value | value > $1 | value < $1 | -----------+------------+------------+---------------- 10 | 10 | 10 | ??? 

Can the following be done?

 CONDITION | ACTION Example | value | -----------------------------------+---------------------------------------- 10 | System.out.println("equals to 10") > 10 | System.out.println("greater than 10") < 10 | System.out.println("less than 10") 

What is the correct way to implement these rules?

+4
source share
3 answers

I found out that I can achieve what I need by putting just $ param in the cell of the constraint field and putting all the constraint in the value cells. Therefore, the decision table looks like this:

 CONDITION | ACTION Example | $param | System.out.println("$param"); -------------------------------+----------------------------------- value == 10 | equals to 10 value > 10 | greater than 10 value < 10 | less than 10 
+6
source

You can specify part of the condition as a value. In the header, you can give " value $ param " to evaluate. (BTW, in order to be able to enter values ​​such as == 10, you must change the format of the cell to text in Excel)

 CONDITION | ACTION Example | value $param | -----------------------------------+---------------------------------------- == 10 | System.out.println("equals to 10") in (10, 11) | System.out.println("is 10 or 11") > 10 | System.out.println("greater than 10") < 10 | System.out.println("less than 10") 
+5
source

You can look at it

http://s11.postimage.org/oya6zxr83/Screenshot.png

here we take userlocation and count from the user and check if there is less counter than the initial count of each city, and if the condition is met, the cycle will work until the cycle condition.

Hope this will be helpful.

+1
source

All Articles