Adding decisions in Array

57 views
Skip to first unread message

indranil nanda

unread,
Apr 14, 2017, 8:40:45 AM4/14/17
to OpenRules

Recently we started exploring OpenRules and was trying to make a decisionmodel based on excel only.

And we are stuck in a situation for which were not able to locate any suitable sample application in 6.4.1 download.

 

I want to know is it possible to put decisions from different DTs in to an array.

 

So what we want to achieve is, let we have possible decisions

 

Data DecisionImportance decisionImportances

myDecision

importance

My Decision

Importance

Decision1

9

Decision2

10

Decision3

15

Decision4

12

Decision5

6

-99 //null or no decision

 

Now based on customer data(input), 1st decision table will give Decision 1/null, 2nd decision table will give Decision2 or null etc.

 

So I want to collect all these decisions in a Array and want to do some logic based on importance  to provide the final decision.

 

//DecisionTable ViewMyShipment1

If

If

Then

var1

var2

Recommendation[0]

Yes

Yes

Decision1

 

 

//DecisionTable ViewMyShipment2

If

If

Then

Var3

Var4

Recommendation[1]

Yes

Yes

Decision2

 

 

So my question is how to write this (Then/Action/Conclusion) to put into decision array.

 

Believe I can do += and to concatenate all decisions in a String and then split in Java. But is there any other alternative.

OpenRules Support

unread,
Apr 14, 2017, 8:49:02 AM4/14/17
to OpenRules
You probably want to create an array of recommendations (not array of decisions). The standard workspace "openrules.dmn" provides two examples that deal with arrays of variables: DecisionAggregatedValues and DecisionUserv. It seems your example is simpler and if you may specify a more clear logic with input data and expected results of what you actually trying to achieve we will be glad to provide a solution for you.

Support

indranil nanda

unread,
Apr 14, 2017, 7:02:59 PM4/14/17
to OpenRules

Glossary glossary

Variable

Business Concept

Attribute

Var 1

Customer

var1

Var 2

var2

Var 3

var3

Var 4

var4

Var 5

var5

Var 6

var6

Var 7

var7

Var 8

var8

Var 9

var9

Var 10

var10

Recommendations

Recommendations

recommendations

Recommendation Name

RecommendationWeightage

recommendationName

Weight

weight

Recommendation Name For Consumers

recommendationNameForConsumers

Datatype Recommendations

String[]

recommendations

Data RecommendationWeightage recommendationWeightages

recommendationName

weight

recommendationNameForConsumers

Recommendation Name

Weight

Recommendation Name For Consumers

recommendation1

1

IS_ELIGIBLE_FOR_RECOMMENDATION_1

recommendation2

2

IS_ELIGIBLE_FOR_RECOMMENDATION_2

recommendation3

4

IS_ELIGIBLE_FOR_RECOMMENDATION_3

DT DeciosnForRecommendation1

If

If

Conclusion

Var1

Var2

Recommendations

A

B

recommendation1

DT DeciosnForRecommendation2

If

If

Conclusion

Var3

Var4

Recommendations

C

D

recommendation2

 

In Java side:

I am reading the Constant data recommendationWeightage  from Excel file.

And I am expecting the recommendation[] will contain some data like [“recommendation1”, “recommendation5”, “recommendation6”] etc.

Now based on priority/weightage I am going to sort those data. And give some top 5 or top 2 record.

 

So I have doubt in how to add recommendations dynamically in to the array.

Cause the examples I saw, there it is part of data which is fed in to the decision model.

But what I want, is to add output of different decision tables into the array.

So believe I have to update something in the sections of DT highlighted in yellow.



-----------------------------------------------------

-----------------------------------------------------

-----------------------------------------------------

----------------------------------------------------- 

OpenRules Support

unread,
Apr 15, 2017, 9:35:28 AM4/15/17
to OpenRules
Hi Indranil,

We created a sample working project that (we believe) demonstrates how to resolve your problem. It may be useful for other customers as well. You may download this working project from


Here is the problem description. We have an array of Customers and an array of Products. Customers may like certain features and products may have (or not) these features. Each feature may have a weight/importance that contributes to the score when we assign a product to a customer. Here is an example of the scoring rules:


To execute these rules for every customer, you may use a table like this one:

The Java class Customer contains an array of all products that will be evaluated using these rules. Then we may evaluate (score) all products using Java standard method Arrays.sort(products). Note that our Java class Product implements Comparable<Product> and here is a simple compareTo() method:

        public int compareTo(Product product) {
if(product.customerScore > this.customerScore)
return 1;
else 
return -1;
}

If you need more complex comparison of products, this method may actually call an Excel-based decision table.

We are attaching the complete file DecisionSortArray.xls with test data: Here are the execution results for the first customer:

=== Customer: Robinson
Decision Run has been initialized
Decision RecommendCustomerProducts: Evaluate All Customer Products
Execute Rules <EvaluateOneProduct> for a collection Products of the type Product
Conclusion: Eligible Is false [false]
Conclusion: Customer Score = 0 [0]
Conclusion: Eligible Is true [true]
Conclusion: Customer Score += 3 [3]
Conclusion: Eligible Is false [false]
Conclusion: Customer Score = 0 [0]
Conclusion: Eligible Is false [false]
Conclusion: Customer Score = 0 [0]
Conclusion: Eligible Is true [true]
Conclusion: Customer Score += 3 [3]
Conclusion: Eligible Is false [false]
Conclusion: Customer Score = 0 [0]
Conclusion: Eligible Is true [true]
Conclusion: Customer Score += 3 [3]
Conclusion: Eligible Is true [true]
Conclusion: Customer Score += 5 [8]
Conclusion: Eligible Is false [false]
Conclusion: Customer Score = 0 [0]
Conclusion: Eligible Is false [false]
Conclusion: Customer Score = 0 [0]
Conclusion: Eligible Is true [true]
Conclusion: Customer Score += 5 [5]
Decision RecommendCustomerProducts: Sort Products
Decision RecommendCustomerProducts: Show Result
Customer [name=Robinson, maritalStatus=Married, gender=Female, products=, likesFeature1=true, likesFeature2=false, likesFeature3=true]
Recommended Products:
Product [name=Product D, hasFeature1=true, hasFeature2=true, hasFeature3=true, customerScore=8, eligible=true]
Product [name=Product Y, hasFeature1=false, hasFeature2=true, hasFeature3=true, customerScore=5, eligible=true]
Product [name=Product C, hasFeature1=true, hasFeature2=true, hasFeature3=false, customerScore=3, eligible=true]
Product [name=Product A, hasFeature1=true, hasFeature2=true, hasFeature3=false, customerScore=3, eligible=true]
Decision has been finalized

Hope it will help you with your own problem. Good luck,

OpenRules Support
DecisionSortArray.xls

OpenRules Support

unread,
Apr 16, 2017, 10:08:47 PM4/16/17
to OpenRules
The next release will include a more elegant way to sort arrays of objects using a new Decision's method sort(ComparableDecisionVariable[] array). We attached a working decision model in the file "DecisionSortPassengers.xls" that sorts an array of passengers using their frequent flyer status (GOLD, SILVER, or BRONZE) and number of miles. Here is the comparison logic for any two passengers:


The Java class Passenger.(attached) does not contain any compareTo() and should simply extend the standard OpenRules class ComparableDecisionVariable. If you like this way of sorting more, we could make an alpha version available for you upon your request.

Support
Passenger.java
DecisionSortPassengers.xls

indranil nanda

unread,
Apr 17, 2017, 12:15:43 PM4/17/17
to OpenRules
Hi, 

Appreciate for checking out different possibilities.
For the last solution (Passenger) do we have to make Passenger1, Passenger2 classes in Java separately.
Because looks like I have to make duplicate entries (Passenger1, Passenger2 etc) with same attributes for each passenger in the Glossary.
Let me know if I am wrong.

And regarding new alpha release: I don't mind sorting in the Java as of now.

Thanks again.

Regards
Indranil 

OpenRules Support

unread,
Apr 17, 2017, 12:34:35 PM4/17/17
to OpenRules
No, of course one Java class Passenger is enough. You just need to define Passenger1 and Passenger2 in the Glossary to use their attributes inside the comparison decision table "ComparePassengers". And only you may decide where better to keep different pieces of your logic: in Excel-based rules or in Java. It really depends on your particular problem, and it is nice to have both possibilities to choose from.

Support
Reply all
Reply to author
Forward
0 new messages