After discover this funny problem in this post we’ve solved it by creating a Decision Service under IBM ODM 8.6 technology. Although it’s clear that it’s not a realistic stuff (we all know that werewolves don’t live int graveyards) is a good example that shows how to define the calculation of a risk.
This is our proposal to the problem posed by the LinkedIn group “The Decision Model” with the following statement:
Decision Model: “Determine the Risk of Meeting a Werewolf“
Trying to determine the risk of meeting a Werewolf based upon two factors: Phase of the Moon, and Distance from Graveyard. Here are the rules:
Fact Type: Phase of the Moon
Values: New Moon, Half Moon, Three-Quarter Moon, Full Moon
Rule Family: Phase of the Moon Risk
Conditions | Conclusions
New Moon | .01
Half Moon | .25
Three-Quarter Moon | .50
Full Moon | .75Fact Type: Miles from Graveyard
Values: < 5 miles, between {5 miles, 25 miles}, > 25 miles
Rule Family: Miles from Graveyard Risk
Conditions | Conclusions
<5 miles | .75
between {5 miles, 25 miles} | .25
> 25 miles | .01Fact Type: Werewolf Risk
Values: Phase of the Moon, Miles from Graveyard
Rule Family: Werewolf Risk Weights
Conditions | Conclusion
Phase of the Moon | .75
Miles from Graveyard | .5Calculate Werewolf Risk:
(Phase of the Moon weight * Phase of the Moon Risk) + (Miles from Graveyard weight * Miles from Graveyard Risk) = Werewolf Risk
First, we define a new MoonPhase type with an static domain populated with the different Moon Phases to use as an input argument:
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/10/01BOM_MoonDomain.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”1011″ height=”558″]
With this new MoonPhase type we can define the two input parameters (“the input moon phase” and “the input miles from graveyard”) ant the output calculated risk (“the output werewolf risk”)
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/10/02OperationParameters.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”1062″ height=”513″]
We also define a set of internal variables to store the risks and the weights to be used for the final calculation:
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/10/02-Variables.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”734″ height=”502″]
Decision Table: Phase of the Moon Risk Table
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/10/rule01.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”841″ height=”519″]
Decision Table: Miles from Graveyard Risk Table
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/10/rule02.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”855″ height=”533″]
Decision rule: value of the variable “Miles from Graveyard Weight”. This could have been done directly on the definition of the variable, but in this way the user will have a business rule on wich control this value.
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/10/rule03.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”844″ height=”517″]
Decision rule: value of the variable “Moon Phase Weight”. This could have been done directly on the definition of the variable, but in this way the user will have a business rule on wich control this value.
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/10/rule04.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”841″ height=”537″]
Decision rule: Calculate Warewolf Risk
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/10/rule05.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”843″ height=”281″]
Rules are organized in the project with the following folders:
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/10/04-Rules.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”539″ height=”674″]
To create the ruleflow we assign each folder to a different ruletask and ordering as follows:
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/10/03-Ruleflow1.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”463″ height=”631″]
Now we can test our service. To do this we create a new test based on an Excel file with 3 different scenarios on it:
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/09/11A.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″]
We define also the expected results for each scenario:
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/09/11BExcel.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″]
We create the test in the Decision Center and upload our Excel file on it:
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/10/Test01.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”858″ height=”374″]
We run the test and check how the report indicates that one of the three scenarios failed:
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/10/Test02.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”855″ height=”715″]
The expected result for the first scenario is correct:
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/10/TestScenario01.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”860″ height=”635″]
Our expected result (0,25) doesn’t match the execution result (0,3125) of the second scenario :
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/10/TestScenario02.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”858″ height=”721″]
The expected result for the third scenario is correct:
[image url=”https://www.decidesoluciones.es/wp-content/uploads/2014/10/TestScenario03.jpg” raw=”true” alignment=”center” margin_left=”0″ margin_right=”0″ margin_top=”0″ margin_bottom=”0″ width=”846″ height=”722″]
Our Decision Service is completed and confirming us that in full moon nights staying at home is the best option.
Until the next challenge!