We have moved back to London in the Victorian era to solve Agatha’s death mystery and thus to face this month’s Challenge, following the usual Agatha Christie’s style.
This is our response to the challenge posted by LinkedIn group The Decision Model for the month of November and has the following statement:
Decision Model “Who killed Agatha?”
“Someone in Dreadsbury Mansion killed Aunt Agatha. Agatha, the butler, and Charles live in Dreadsbury Mansion, and are the only ones to live there. A killer always hates, and is no richer than his victim. Charles hates no one that Agatha hates. Agatha hates everybody except the butler. The butler hates everyone not richer than Aunt Agatha. The butler hates everyone whom Agatha hates. No one hates everyone. Who killed Agatha?”
Although this kind of problem is more oriented to Optimization techniques and Operations Research, we will try to solve the mystery through a Rule project using IBM Operational Decision Manager V8.6.
We have designed a decision service solution using Rule Designer, taking advantage of the new ODM features. The decision service is named DreadsburyMansion-Rules and has a unique operation, DreadsburyMansion-RulesOperation. We have chosen this solution because this environment, in addition to supporting a clear and managed definition of decision service operations and deployment configurations, extends the collaborative environment of Rule Designer and Decision Center, further enabling developers and business users to work together.
We break-up the information of the statement in three groups that define:
- The hate relationship between the inhabitants of the mansion.
- The wealth level comparison between each mansion’s inhabitants and the victim.
- The restrictions that the killer must fulfill.
First, we define the input and output parameters. The input are the inhabitants of Dreadsbury Mansion, for that, we have defined an array of type Inhabitant. The output is the solution of the mystery, so we have defined the type Solution that contains the list of killers. Nobody said the killer is a single person.
Each of the inhabitants of the mansion has two kinds of relationships, one concerning hate with the rest of the inhabitants and the other concerning wealth level comparation with the victim, Agatha. We are going to define the hate relationships in the input data, while the wealth relationship will be determined by the business rules using the hate relationships of each inhabitants defined in the input.
We also create a variable to determine whether the input data fulfills the constraint No one hates everyone. It is set to true by default, and it will change to false if the rule that checks that restriction is fulfilled.
Taking into account the break-up of the statement, and as seen in the image below, we define the ruleflow for sequencing rule execution. The ruleflow contains the following tasks:
- 1-Hate Restrictions – Check that the input data fulfill the hate restriction Noone hates everyone.
- 2-Wealth – Set whether the inhabitant of the mansion is not richer than the victim.
- Initialize the list of suspects – Initializing the list of suspects, who are all residents of the mansion.
- 3-ResolutionOfTheMystery – Solving the mystery, that is, executing the restrictions the killer must fulfill.
- #RuleTask1 – To check if the input fulfills the hate restriction, we use the following rule:
If the condition that check if some of the inhabitants hates all others is fulfilled, the No one hates everyone variable is set to false and therefore will not continue to execute other tasks.
- #RuleTask2 – According to the statement, an inhabitant of the mansion is richer than the victim if it is not hated by the butler, so to establish whether an inhabitant is richer than the victim we execute the following rule:
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/11/TheButlerHatesEveryoneNotRicherThanRule.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″]
This rule initializes the isRicherThanTheVictim attribute to false to each of the inhabitants of the mansion hated by the butler.
- #ActionTask – Initializing the list of suspects. Firts, all the inhabitants of the mansion are suspects of killing Aunt Agatha.
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/11/inicializacionSospechosos.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”949″ height=”260″]
- #RuleTask3 – We apply the restrictions that the killer must fulfill on the suspects list. The set of rules that define these restrictions are:
#Rule1: A killer always hates
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/11/AKillerAlwaysHates.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”1052″ height=”524″]
#Rule2: The killer is no richer than his victim
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/11/AKillerIsNoRicherThanRule.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”1057″ height=”525″]
In the Decision Center Business console we can see the way that the rules are organized in the following folder structure:
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/11/DecisionCenterRules.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”511″ height=”535″]
We can now execute our service and find out who the killer is… what a thrill!! We will generate a test based on an Excel file. We generate an Excel scenario file, populate it with scenario data, and then upload it to Decision Center. The rules are executed against the scenarios and a report compares the expected results with the results that are obtained at execution time.
In the Scenarios tab we define the inhabitants of the mansion, Agatha, Charles and the butler.
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/11/Excel1_scenario.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”649″ height=”264″]
In the inhabitant tab we set for each inhabitant of the mansion the hate relationship with the rest, according to the statement of the problem. The statement is categorically establishing who Agatha and the butler hate. However, it’s more ambiguous with regards to who Charles hates. Charles hates no one that Agatha hates, but that does not mean he hates others. We will suppose that Charles hates the butler, it is the only person he can hate because Agatha hates herself and Charles, “Agatha hates everybody except the butler“.
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/11/Excel1_inhabitants.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”493″ height=”260″]
In the Expected Results tab we define the list of killers. We suppose that the killers are Agatha, in this case we are talking about suicide, and Charles.
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/11/Excel1_expectedResults.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”562″ height=”261″]
To execute the Excel scenario file that we have populated, we upload it to Decision Center.
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/11/DecisionCenterTest.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”1164″ height=”406″]
We check that the report contains the list of killers we expect.
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/11/Report1.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″]
Now we suppose that Charles does not hate anyone. That is not entirely clear in the statement. In our Excel file we modify the inhabitant tab as follows:
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/11/Excel2_inhabitants.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”505″ height=”266″]
In this case, Agatha has committed suicide, and the list of killers does not match the expected results. Charles has been removed from the list of suspects because he does not suit with the restriction that check if the killer always hates, that is, the killer hates at least one inhabitant of the mansion.
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/11/Report2.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”1436″ height=”795″]
Instead of assuming that Charles hates no one, let’s consider another restriction related to the definition of a murder, because that is what has happened in the Dreadsbury Mansion, a murder. One of the features of BRMS systems is to change the logical decision in an agile way, and as we can see in this example, in a natural language close to the business user. We create the following rule:
- #Rule: It is not a suicide
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/11/ItisNotASuicide.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”1171″ height=”527″]
We add the new rule into the ResolutionOfTheMystery rule task:
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/11/DecisionCenterRules21.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”541″ height=”688″]
We modify the expected results removing Agatha from them:
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/11/Excel3_expectedResults.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”537″ height=”258″]
Inserting this restriction in the ruleflow, we check that Agatha has been removed from the list of killers and only Charles appears.
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/11/Report3.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”1436″ height=”795″]
We have solved the mystery … Charles is the killer.
____________________________________________________
The Decision Model LinkedIn group, confirm me that I came to an invalid conclusion, and it has clarified me one of the constraints that the killer must fulfill. The statement says:
‘A killer always hates, and is no richer than his victim.’ With this statement, I understood that the killer always hates, someone, not necessarily the victim, and he is no richer than his victim. Well, this is not true. With that statement, what it means is that the killer always hates his victim and the killer is no richer than her.
This is another of the most common problems when specifications are not sufficiently concise. However, it will serve as an example to see how a BRMS system is very easy to change the logical decision in an agile way.
The steps are:
- In Decision Center, we remove the rule #It is not a suicide. In the rule task #RuleTask-ResolutionOfTheMystery we are only the rules #A killer always hates and #The killer is no richer than his victim.
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/11/DecisionCenterRules.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”511″ height=”535″]
- In Decision Center, we change the rule #A killer always hates under the new definition.
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/12/AKillerAlwaysHates2.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”1147″ height=”524″]
One of the new utilities in Decision Center, it is the possibility to compare different versions of rules. If we compare this rule with the last version, we can see how it has changed under the new specifications:
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/12/DecisionCenterRulesComparison.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”1436″ height=”731″]
- We change the Excel scenario file’s Expected Results tab and we upload it to Decision Center.
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/12/Excel1_expectedResults2.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”582″ height=”255″]
- We execute the new Excel scenario file in Decision Center.
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/12/Report4.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″]
We see that the result has completely changed. There has not been a murder, Agatha has committed suicide.