Home

Rule Solver

image

Contents

1. WAUNNNVLHKE OO SOV RKOLDRUUVWUN ONWAWUR A AN To appreciate the expressiveness of the problem representation supported by Rule Solver you may compare it with a pure Java representation see Sudoku java in org jcp jsr331 samples Magic Square Problem 50 TM User Manual OpenRules Inc Rule Solver Let s consider a famous magic square problem A magic square is a square matrix where the sum of every row column and diagonal is equal to the same value The numbers in the magic square are consecutive and start with 1 See an example of the Magic Square located in the Passion Fa ade of the famous Sagrada Familia temple in Barcelona This problem can be defined and solved using the following Excel table Method void main RuleSolver rs int n 4 VarMatrix matrix cs Mariablematrix Square i ntn A AN post ALIDIE Constraint rs POS EAL Dash amp matrix flat post Sum constraints for rows columns and diagonals ae svi Sa aa Lj 23 rs post matrix diagonale Sum re post matriz diagonala Tu sum foe ne a O ee aie et ro POSt matrix row i TET ett gt Bs POSE matrix columna NES Sum findSolution rs System out printlin matrix Zebra Problem This problem is often called Einstein s Riddle because it is said to have been invented by Albert Einstein as a boy Some claim that Einstein said only 2 percent of the world s population
2. Here conditionConstraints are accumulated by using the method and defined for the JSR 331 class Constraint For example the rule IF Person Years at Current Employer lt I 240 OpenRules Inc Rule Solver User Manual AND Person Number of Jobs in Past Five Years gt 5 THEN Person Employment History Poor may be implemented in Java using the JSR 331 interface Var varl rs getVar Person Years at Current Employer Constraint cl rs linear varl lt 1 Var var2 rs getVar Person Number of Jobs in Past Five Years Constraint c2 rs linear var2 gt 5 Constraint conditionConstraints cl and c2 VarString var3 rs getVarString Person Employment History Constraint conclusionConstraint rs linear var3 Poor rs add conditionConstraints implies conclusionConstraint This way Rule Solver creates all constraints but it does not post activate them yet Posting Data Constraints Then Rule Solver assigns data to decision variables that are already known How does Rule Solver differentiate between known and unknown decision variables A glossary may explicitly specify which variables are unknown in the column Unknown that follows the column Domain If this optional column is not used then Rule Solver automatically defines them as those variables that are used inside decision table conclusions only Rule Solver
3. User Manual It will produce the following results Decision DefineOvenSchedule Create RuleSolver JSR 331 Implementation based on Constrainer 5 4 light Rule Solver version 6 2 0 addConstrainedVariables Decision has been initialized with RuleSolver Initial Problem Variables Decision DefineOvenSchedule Define Schedule Create RuleScheduler Decision DefineOvenSchedule Define Activities Decision DefineOvenSchedule Define Oven as Recoverable Resource Decision DefineOvenSchedule Define Oven Availabilityt Decision DefineOvenSchedule Define Resource Requirement Constraints After After Solve Solution A 5 B 3 C 7 p e E 6 Assigning Data Posting Constraints 1 gt 6 requires Oven 2 4 gt 7 requires Oven 1 4 gt 11 requires Oven 1 2 gt 2 requires Oven 1 4 gt 10 requires Oven 2 Here is a visual representation of the results Batches 3 2 O 2 2 Solution in Java 6 7 8 9 10 11 Now we solve the same problem in Java package org jcp jsr331 scheduler samples import import import import import javax javax javax javax javax constraints constraints constraints Solver constraints constraints scheduler impl SchedulingProblem Solution scheduler Activity scheduler Resource 66 O OpenRules Inc Rule Solver User Manual public final class Oven Schedule s ScheduleFactory newSchedule O
4. 2 Solve mode that uses Rule Solver In this mode the order of rules within a decision table and between decision tables does not matter and can be resolved automatically Functionally this mode is similar to famous RETE based rule engines with no needs for rules ordering Thus the same decision model expressed in business terms can serve as an input for both rule engines a regular sequential rule engine and an inferential constraint based rule engine Simple Examples The following examples demonstrate how to apply sequential Rule Engine and inferential Rule Solver to the same decision models Simple Decision Model DecisionHello In this example we will develop a simple application that should decide how to greet a customer during different times of the day The proper decision model might be a part of an interactive voice response IVR system For example if a 60 OpenRules Inc Rule Solver User Manual customer Robinson is a married woman and local time is 14 25 we want our decision to produce a greeting like Good Afternoon Mrs Robinson To make this example a little bit more complicated we will force the application to greet children with a greeting like Good Afternoon Little Robinson Decision Model We will use Excel to represent decisions related decision tables and several test cases We will start with the main table of the type Decision that consists of 3 sub d
5. Create RuleSolver JSR 331 Standard v 1 0 1 release 5 25 2012 JSR 331 Implementation based on Constrainer 5 4 light Rule Solver version 6 2 1 addConstrainedVariables Decision has been initialized with RuleSolver Initial Problem Variables Lucky 0 4 Chesterfield 0 4 55 OpenRules Inc Rule Solver User Manual fox 0 4 OldGolds 0 4 Ukrainian 0 4 horse 0 4 Parliament 0 4 yellow 0 4 tea 0 4 Kools 0 4 milk 0 4 juice 0 4 ivory 0 4 water 0 4 Japanese 0 4 ZEBRA 0 4 green 0 4 coffee 0 4 Norwegian 0 4 red 0 4 blue 0 4 Englishman 0 4 Spaniard 0 4 snail 0 4 dog 0 4 Decision FindZebra All Diff Constraints Decision FindZebra Zebra Constraints 1 Decision FindZebra Zebra Constraints 2 After Assigning Data After Posting Constraints Lucky 0 4 Chesterfield 0 4 fox 0 4 OldGolds 0 4 Ukrainian 1 4 horse 0 4 Parliament 1 4 yellow 0 4 tea 1 4 Kools 0 4 milk 2 juice 0 4 ivory 2 3 water 0 4 Japanese 1 4 ZEBRA 0 4 green 3 4 coffee 3 4 Norwegian 0 560 OpenRules Inc Rule Solver User Manual red 2 4 blue 1 Englishman 2 4 Spaniard 1 4 snail 0 4 dog 1 4 Solve Decision ZebraProblem green 4 ivory 3 blue 1 red 2 yellow 0 Norwegian 0 Ukrainian 1 Japanese 4 Englishman 2 Spaniard 3 juice 3 tea 1 milk 2 water 0 coffee 4 snail 2 dog 3 f
6. IF Total Income gt 403200 THEN Income Det nel ValidationResult Validation Result SUFFICIENT IF Total Income lt 403200 THEN Income Validation Result UNSUFFICIENT DetermineIncomeValidationResult DetermineDebtResearchResult Result High IF Mortgage Holder No AND Outside Credit Score gt 100 AND Outside Credit Score lt 550 DetermineDebtResearchResult THEN Debt Research Result High fal IF Mortgage Holder Yes THEN Debt Research On On On On On On On AND Loan Holder Yes AND Credit Card IF Mortgage Holder No AND Outside Credit i Score gt 550 AND Outside Credit Score lt 900 DetermineDebtResearchResult 300 OpenRules Inc Balance lt 0 THEN Debt Research Result Mid IF Mortgage Holder No AND Outside Credit Score gt 550 AND Outside Credit Score lt 900 AND Loan Holder Yes AND Credit Card Balance gt 0 AND Education Loan Balance gt 0 THEN Debt Research Result High IF Mortgage Holder No AND Outside Credit Score gt 550 AND Outside Credit Score lt 900 AND Loan Holder Yes AND Credit Card Balance gt 0 AND Education Loan Balance lt 0 AND Internal Credit Rating ISONEOF A B C THEN Debt Research Result High IF Mortgage Holder No AND Outside Credit Score gt 550 AND Outside Credit Score lt 900 AND Loan Holder Yes AND Credit Card Balance gt 0 AND Education Loan Balance lt 0 AND Internal Credit Rating ISONEOF D F THEN Debt Research Result Mid IF
7. 0 The a nk lives in the first ouse The Lucky Strike smoker drinks Lucky juice i orange juice Japanese Parliament The Japanese smokes Parliament We will use formulas with JSR 331 code to define neighboring constraints 530 OpenRules Inc DecisionTable ZebraConstraints2 linear decision V green V ivory plus 1 Constraint right linear decision V Chesterfield V fox plus 1 Constraint left linear decision V Chesterfield V fox minus 1 Constraint right linear decision V Kools V horse plus 1 Constraint left linear decision V Kools V horse minus 1 right or left right or left Var Norwegian V Norwegian Var blue V blue linear decision Norwegian blue plus 1 or linear decision Norwegian blue minus 1 Rule Solver User Manual The green house is immediately to the right of the ivory house The man who smokes Chesterfields lives in the house next to the man with the fox Kools are smoked in the house next to the house where the horse is kept The Norwegian lives next to the blue house To put everything together we will use the following table Decision Decision FindZebra All Diff Constraints AllDiffConstraints Zebra Constraints 1 ZebraConstraints1 Zebra Constraints 2 ZebraConstraints2 We will assume that data come
8. 99999 S 1 9 MORE 1000 9999 R 9 M 1 9 N 0 9 o e 9 Y 9 After Posting Constraints D 0 9 E 9 9 SEND 8801 9999 MONEY 10000 11198 S 8 9 MORE 1000 1199 R 0 9 M 1 N 0 9 o 1 Y 0 9 Solve Pure Java Solution You may want to compare the decision model with a pure Java solution the proper JSR 331 code will look as follows package org jcp jsr331 samples import javax constraints Problem import javax constraints ProblemFactory import javax constraints Var public class SendMoreMoney public static void main String args Problem p ProblemFactory newProblem SendMoreMoney define variables Var S p variable S 1 9 Var E p variable E 0 9 Var N p variable N 0 9 Var D p variable D 0 9 Var M p variable M 1 9 Var O p variable 0 0 9 Var R p variable R 0 9 40 TM OpenRules Inc Rule Solver User Manual Var Y p variable Y 0 9 Post all different constraint Var vars new Var S E N D M O R Y p postAl1Diff vars Define expression SEND int coefl 1000 100 10 1 Var sendVars S E N D Var SEND p scalProd coefl sendVars SEND setName SEND Define expression MOR Var moreVars M O R E Var MORE p scalProd coefl moreVars MORE setName MORE Define expression MONEY Var moneyVars
9. Age Group ageGroup Little Young Adult Current Hour hour 0 24 Greeting greeting Ta Morning Good Afternoon Good Evening Good Response ight Salutation salutation Mr Ms Mrs Little We will assume that the data for our model comes from a Java as defined by the following table of the type DecisionObject DecisionObject decisionObjects Customer Response decision get customer decision get response This completes the definition of our decision model Now we find solutions for this model starting with a regular sequential OpenRules Rule Engine Solution with Rule Engine The standard OpenRules installation comes with the proper decision project DecisionHelloCP in the workspace openrules solver This project has a Java 80 OpenRules Inc package hello with two Java classes Customer and Rule Solver simple Java beans with the following organization public class Customer String String String int String int name maritalStatus gender age ageGroup hour getters and setters public class Response String greeting String salutation String result getters and setters TM User Manual Response that are The main Java class Main java contains one method main that creates test instances of the classes Customer and Response puts them to the instance of Decision and executes this deci
10. DecisionTableExecuteTemplates xls contains a template with the fixed name DecisionTableTemplate and all Decision Tables are created based on it This template is a regular OpenRules single hit rules table It means that it is trying to execute rules in top down order by evaluating their conditions When all conditions inside a rule are evaluated as TRUE the rule s conclusion and possibly other related actions will be executed and all remaining rules will be ignored Rule Solver provides the configuration file DecisionTableSolveTemplates xls that substitutes the template DecisionTableTemplate with a different implementation that is actually a special RuleSequence decision table This table unconditionally executes all rules inside every decision table one after another However instead of evaluating rule conditions it simply creates new constraints similar to cl and c2 above and then AND s all previously defined conditions similarly to cl and c2 Thus all conditions from one rule will form a constraint conditionConstraints described in the previous example Then the conclusion will be converted to the conclusionConstraint that is based on the constrained variable associated with the conclusion s fact type operator and value Finally Rule Solver creates a new constraint conditionConstraints implies conclusionConstraint and adds it to the problem According to the JSR 331 this constraint
11. M O N E Y int coef2 10000 1000 100 10 1 Var MONEY p scalProd coef2 moneyVars MONEY setName MONEY p add MONEY Post constraint SI p post SEND plus MOR FI ND MORE MONEY lt O ti K F H G H Problem Resolution p getSolver findSolution p log Solution SEND MORE MONEY This code will produce Solution SEND 9567 MORE 1085 MONEY 10652 Based on the levels of expertise of your users you may decide what information to keep in Excel making it available to business users and what information to hard code in Java Solving Arithmetic Problems Let s consider a simple arithmetic problem There are four integer variables X Y Z and R that may take values 0 1 2 3 4 5 6 7 8 9 or 10 Considering that all variables should have different values find a solution that satisfies the following constraints 410 OpenRules Inc Rule Solver User Manual X lt Y Xt Y 2 Z gt Bis Let s create a decision model for this problem We will assume that the data for this problem is defined in a Java class XYZ public class XYZ int x y Z public int getX return x public void setX int x this x x public int getY return y public void setY int y this y y public int getZ return Z public v
12. Rule Solver Assuming that different letters represent different digits you need to solve the following puzzle Excel based Decision Model The standard Rule Solver installation comes with the proper decision project DecisionSendMoreMoney in the workspace openrules solver This project has only one file Decision xls that includes all needed Excel tables Our problem has only 8 different decision variables S E N D M O R and Y They are integer variables with domains from 0 to 9 Variables S and M have a possible minimal value of 1 because they at the beginning of the words SEND and MORE So first we will define a glossary Glossary glossary Fact Name S s 1 9 TRUE E e 0 9 TRUE N n 0 9 TRUE D Surd d 0 9 TRUE M Are m 1 9 TRUE O o 0 9 TRUE R r 0 9 TRUE Y y 0 9 TRUE SEND send 1000 9999 TRUE 360 OpenRules Inc Rule Solver User Manual MORE more 1000 9999 TRUE MONEY money 10000 99999 TRUE We added to the end of the glossary intermediate variables SEND MORE and MONEY that will be used to simplify the expression of the main problem constraint All these variables are unknown When we use a glossary we need to create actual data instances business objects In this case we will simple use the proper Excel tables Datatype Puzzle int s int e int n in
13. solutions as possible but no more the defined by the limit used in the statement decision put MaxSolutions maxNumberOfSolutions 3 Find an optimal solution the solver is trying to find a solution that minimizes an objective variable specified in the statement decision put Minimize nameOfCostVariable To maximize the cost variable use the statement decision put Maximize nameOfCostVariable During the optimization process Rule Solver considers no more solutions than a number specified in the statement decision put MaxSolutions maxNumberOfSolutions See example of all 3 problem solving modes in the example below 260 OpenRules Inc Rule Solver User Manual Using Templates Rule Solver never generates Java code Instead at run time it simply creates an instance of different JSR 331 classes and adds them to the already created constraint satisfaction problem All instances of constrained variables and constraints are added to the problem on the fly To do that Rule Solver effectively utilizes the existing OpenRules templatization mechanism OpenRules uses different rule templates to implement all tables included into the default not constraint based implementation of the decision model Such tables as Decision DecisionTable and Glossary are actually implemented based on rule templates defined in several configuration Excel files For example the file
14. tivi tivi CY CY CY CY CY CY CY CY CY CY masonry carpentry plumbing ceiling roofing painting windows facade garden movingIn un nnnnaonnnovo acC AC acC AC AC AC AC acC AC AC tivi tivi tivit tivit tivi tivi tivit CIVIC tivit Exception masonry carpentry plumbing ceiling rooting painting windows facade garden pi 3 8 peo rl r2 rl 12 rl tivit ty ty ty ty ty ty ty ty ty ty moving in 1 r r r z ee r r r r r 590 OpenRules Inc Posting startsAfterEnd s post carpentry gt masonry s post roofing gt carpentry s post plumbing gt masonry s post ceiling gt masonry s post windows gt roofing s post facade gt roofing s post facade gt plumbing s post garden gt roofing s post garden gt plumbing s post painting gt ceiling s post movingIn gt windows s post movingIn gt facade s post movingIn gt garden s post movingIn gt painting s logActivities public void solve Solution solution if solution null s log No solutions else s log SOLUTION s logActivities public static void main String args ScheduleActivities p p define p solve
15. you may print a solution using solution log or analyze it using the JSR331 Solution API If your decision is trying to find many feasible solutions then after decision execute you may write Solution solution Solution decision getOutput and to analyze the array of the produced solutions Implementation Restrictions and Future Improvements 1 Rule Solver only supports decision tables of the type DecisionTable and not DecisionTable1 or DecisionTable2 2 The current release only works with integer and string decision variables of the type Boolean real and set variables will be supported in the next releases 330 OpenRules Inc Rule Solver User Manual RULE SOLVER AS A BUSINESS ORIENTED CONSTRAINT SOLVER Rule Solver can be used as a business oriented constraint solver It provides an ability to represent and solve constraint satisfaction and optimization problems using Excel based decision tables oriented to business users Usually constraint solver requires a software expert familiar with a particular CP language or API Contrary Rule Solver allows a non technical user to define a constraint satisfaction problem using Excel based business rules decision tables without becoming a CP guru Rule Solver supports declarative application development concentrating on WHAT TO DO problem definition instead of HOW TO DO it problem resolution After a constraint satisfact
16. Constrainer 5 4 light Rule Solver version 6 2 0 addConstrainedVariables Decision has been initialized with RuleSolver Initial Problem Variables Marital Status Single Married Greeting Good Morning Good Afternoon Good Evening Good Night Age 9 120 Age Group Little Young Adult Gender Male Female Salutation Mr Ms Mrs Little Current Hour 24 Decision DetermineCustomerGreeting Define Greeting Word Decision DetermineCustomerGreeting Define Salutation Word Decision DetermineCustomerGreeting Define Age Group After Assigning Data Marital Status Married Greeting Good Morning Good Afternoon Good Evening Good Night Age 4 Age Group Little Young Adult Gender Female Salutation Mr Ms Mrs Little Current Hour 16 After Posting Constraints Marital Status Married Greeting Good Afternoon Age 4 Age Group Little Gender Female Salutation Little Current Hour 16 Solve Decision Good Afternoon Little Robinson s you can see in spite of the wrong order of rules Rule Solver managed to produce the correct solution Good Afternoon Little Robinson instead of the previous Good Afternoon null Robinson The produced execution trace explains how Rule Solver actually works 120 OpenRules Inc Rule Solver User Manual Step 1 First Rule Solver creates an instance of the predefined class RuleSolver that is based on JSR 331 Impl
17. Glossary glossary Decision Variable We will define a formula for the Cost in the following table DecisionT able DefineCost Is V X multiply SV Y minus V Z Finally we will add these formulas to the decision Decision FindXYZ BinaryConstraints DefineCost 45 OpenRules Inc 30 then Rule Solver will produce only 8 different solutions Find All Solutions but not more than 39 Solution 1 Cost 5 Y 4 X 3 Z 7 Solution 2 Cost 5 Y 7 x 2 z 9 Solution 3 Cost 6 Y 8 X 2 Z 10 Solution 4 Cost 7 Y 5 X 3 Z 8 Solution 5 Cost 9 Y 6 X 3 Z 9 Solution 6 Cost 11 Y 5 X 4 Z 9 Solution 7 Cost 11 Y 7 X 3 Z 10 Solution 8 Cost 14 Y 6 X 4 Z 10 the following statement to your Main java decision put Maximize Cost Rule Solver will produce Found a solution with 5 Found a solution with 6 Rule Solver User Manual If we try to run the same main program now with MaxSolutions being set to We may want to find a solution that maximizes the Cost To do that we will add 46 OpenRules Inc Found Found Found Found Found a a a a a solution solution solution solution solution with 7 with 9 with 11 with 14 with 14 Execution Profile Number of Choice Points 55 Number of Failures 44 Occupied memory 4842080 Execution time 49 msec Solution 6 Cos
18. MODE Solve enforces the use of Rule Solver instead of the default sequential rule engine After execution of this model with Rule Solver we will receive the following results Step 1 Decision DetermineLoanPreQualificationResults Create RuleSolver JSR 331 Implementation based on Constrainer 5 4 light Rule Solver version 6 2 0 addConstrainedVariables Decision has been initialized with RuleSolver Step 2 Initial Problem Variables Outside Credit Score 999 Education Loan Balance 1900099 100000000 Monthly Income 9 5000000 Credit Card Balance 1000009 100000006 Income Validation Result SUFFICIENT UNSUFFICIENT Debt Research Result High Mid Low Mortgage Holder Yes No Total Debt 0 500000 Total Income 500000 Loan Qualification Result QUALIFIED NOT QUALIFIED Loan Holder Yes No Internal Credit Rating A B C D F Internal Analyst Opinion High Mid Low Step 3 Decision DetermineLoanPreQualificationResults Calculate Internal Variables Decision DetermineLoanPreQualificationResults Validate Income Decision DetermineLoanPreQualificationResults Debt Research 200 OpenRules Inc Rule Solver User Manual Decision DetermineLoanPreQualificationResults Summarize Step 4 After Assigning Data Outside Credit Score 720 Education Loan Balance Monthly Income 5000 Credit Card Balance 2500 Income Validation Result SUFFICIENT UNSUF
19. Programming API is a Java Community Process standard that was awarded the Most Innovative JSR Award at Java One 2010 40 OpenRules Inc Rule Solver User Manual variety of templates that allow business analysts not necessarily familiar with CP or even Java to define their own scheduling resource allocation configuration and other constraint satisfaction problems and use standard CP solving methods to find their solutions DOCUMENT CONVENTIONS The regular Century Schoolbook font is used for information that is prescriptive by this specification The italic Century Schoolbook font is used for notes clarifying the text The Courier New font is used for code examples 50 OpenRules Inc Rule Solver User Manual RULE SOLVER AS INFERENTIAL RULE ENGINE Rule Solver can be used as an inferential Rule Engine that can execute OpenRules decision models It provides an alternative to the standard OpenRules sequential rule engine At the same time it provides a powerful validation mechanism that automatically checks OpenRules decision models for consistency and completeness The decision models defined using traditional OpenRules decision tables can be executed in two modes 1 Execute mode that uses a regular OpenRules rule engine In this default mode a user is expected to explicitly specify the order of rules within a decision table and the execution order of decision tables inside decisions
20. Schedule Define Activities Define Precedence Constraints Constrainer 5 4 light 620 OpenRules Inc Rule Solver User Manual After Assigning Data After Posting Constraints Solve Solution masonry 7 gt 7 carpentry 7 3 gt 10 roofing 1 1 gt 11 plumbing 7 8 gt 15 ceiling 7 3 gt 10 windows 11 1 gt 12 facade 15 2 gt 17 garden 15 1 gt 16 painting 2 gt 2 movingIn 17 1 gt 18 Example Resource Allocation The following problem deals with activities that require a common resource Let s consider 5 different orders activities that fire batches of bricks in an oven a resource with a limited capacity Each order s size and duration as well as the oven s capacity are described in the following figure Batches 01 2 3 S 6 8 9 10 11 Global capacity of the oven al 2 batches 1 day LB 1 batch 4 days 5 Activities I batch 4 days D 1 batch 2 days 2 batches 4 days 630 OpenRules Inc Rule Solver User Manual This is a simple example of a joint scheduling and resource allocation problem where we allow a solver to decide when to perform different activities based on resource availability Solution in Excel Now we will see how this problem can be presented and solved directly in Excel Let s define our decision model Decision DefineOvenSchedule Define Schedule DefineSched
21. The line s post plumbing gt masonry constraints throws TM Rule Solver User Manual s scheduleActivities Exception new ScheduleActivities posts the constraint Carpentry starts after the end of Masonry The method solve uses a predefined method scheduleActivities that simply defines start times for all activities while satisfying all posted constraints When we run this code it will produce SOLUTION masonry 0 7 gt 7 carpentry 7 3 gt 10 plumbing 7 8 gt 15 ceiling 7 3 gt 10 roofing 10 1 gt 11 60 O OpenRules Inc Rule Solver User Manual painting 10 2 gt 12 windows 11 1 gt 12 facade 15 2 gt 17 garden 15 1 gt 16 moving in 17 1 gt 18 Here the line movingIn 17 1 gt 18 means that the activity movingIn will start on day 17 will last one day and will end on day 18 Solution in Excel Now we will see how the same problem can be presented and solved directly in Excel Rule Solver provides s for different scheduling constructs So our decision model will be defined by the following table Decision Schedule Activities Define Schedule DefineSchedule Define Activities DefineActivities Define Precedence DefinePrecedenceConstraints Constraints We may define schedule in the following table DecisionTable DefineSchedule Then
22. decision with an extension html By default this report is placed in the folder report of the main decision folder If you want to change the report path say to c temp report you may achieve it by stating 280 OpenRules Inc Rule Solver User Manual decision put report On decision put reportPath c temp report If the name of the decision was ScheduleActivitiesWithAlternativeResources then the generated report will be placed to the file c temp report Report ScheduleActivities WithAlternativeResources html If you want to also use a custom report s name instead of the decision s name say MyReport you may add one more line decision put reportName MyReport The report will be placed to c temp report MyReport html If the folder report does not exist in c temp it will be automatically created Below is an exampleof the execution report for the sample project DecisionLoan OpenRules Solver Execution Report Decision DetermineLoanPreQualificationResults Wed Apr 23 16 41 58 EDT 2014 Assigning Data To Decision Variables Decision Variables Outside Credit Score 620 290 OpenRules Inc Rule Solver User Manual Loan Qualification Result QUALIFIED NOT QUALIFIED ae Posting If Then Constraints Posted If Then Constraints cual Total Debt 216000 CalculateInternalVariables e Total Income 460800 CalculateInternalVariables
23. j lt 9 j if data i j 0 matrix post i j data i j that uses the following Data table Data MatrixInt problem1 6 5 0 0 7 0 0 oO OoO o o oau oy oyR IN 0 0 4 8 6 0 0 0 5 Q RRBI OJO NIOJO0 O O Rule Solver User Manual To post all Sudoku constraints on this matrix we will use the following decision table DecisionTable DefineSudokuConstraints ActionAllDiff Variables x00 x01 x02 x03 x04 x05 x06 x07 x08 x10 x11 x12 x13 x14 x15 x16 x17 x18 x20 x21 x22 x23 x24 x25 x26 x27 x28 X30 x31 x32 x33 x34 x35 x36 x37 x38 Row Constraints x40 x41 x42 x43 x44 x45 x46 x47 x48 480 OpenRules Inc Rule Solver User Manual x50 x51 x52 x53 x54 x55 x56 x57 x58 x60 x61 x62 x63 x64 x65 x66 x67 x68 x70 x71 x72 x73 x74 x75 x76 x77 x78 x80 x81 x82 x83 x84 x85 x86 x87 x88 x00 x10 x20 x30 x40 x50 x60 x70 x80 x01 x11 x21 x31 x41 x51 x61 x71 x81 x02 x12 x22 x32 x42 x52 x62 x72 x82 2 x03 x13 x23 x33 x43 x53 x63 x73 x83 D x04 x14 x24 x34 x44 x54 x64 x74 x84 8 x05 x15 x25 x35 x45 x55 x65 x75 x85 x06 x16 x26 x36 x46 x56 x66 x76 x86 3 x07 x17 x27 x37 x47 x57 x67 x77 x87 x08 x18 x28 x38 x48 x58 x68 x78 x88 x00 x01 x02 x10 x11 x12 x20 x21 x22 x03 x04 x05 x13 x14 x15 x23 x24 x25 x06 x07 x08 x16 x17 x18 x26 x27 x28 2 X30 x31 x32 x40 x41 x42 x50 x51 x52 g X33 x34 x35 x43 x44 x45 x53 x54 x
24. may require more than one resource is interpreted as a requirement for alternative resources We will add sub decision Define Workers and Define Resource Requirement Constraints to the table Decision Decision ScheduleActivitiesWithAlternativeResources Define Schedule DefineSchedule Define Activities DefineActivities Define Precedence DefinePrecedenceConstraints Constraints Define Workers DefineWorkers Define Resource Requirement ResourceRequirementConstraints Constraints 730 OpenRules Inc Rule Solver User Manual The following table defines alternative resources BET EE EE GAGE Joe disjunctive 1 Jack disjunctive 1 Jim disjunctive 1 The next table creates resource requirement constraints listing alternatives divided by the OR sign DecisionT able ResourceRequirementConstraints masonry Joe Jack 1 carpentry Joe Jim 1 roofing Joe Jim 1 plumbing Jack 1 ceiling Joe Jim 1 windows Joe Jim 1 fa ade Joe Jack 1 garden Joe Jim Jack 1 painting Jack Jim 1 movingIn Joe Jim 1 That s it Now the same Java launcher will produce the following results Decision ScheduleActivitiesWithAlternativeResources Create RuleSolver JSR 331 Implementation based on Constrainer 5 4 light Rule Solver version 6 2 0 addConstrainedVariables Decision has been
25. reports the state of all known and unknown constrained variables Posting Problem Constraints After posting data constraint Rule Solver posts activates problem constraints that correspond to all rules defined in all decision tables The order of constraint posting is not important as it does not affect the final results Rule Solver reports the state of all known and unknown constrained variables after constraint posting Because of constraint propagation that may depend on the 250 OpenRules Inc Rule Solver User Manual applied underlying CP solver a combination of data and problem constraints may instantiate all variables or it may diagnose possible conflicts In many cases constraint posting is sufficient to instantiate all constraint variables select single values from their domain Solving the Problem In some cases constraint posting is not sufficient to instantiate all constraint variables That s why Rule Solver always executes its default search algorithm to find a single solution of an automatically created constraint satisfaction problem Rule Solver also saves all found values of constrained variables back to the proper attributes of the business objects based on which these variables were created A user may also control how to solve the problems choosing one of 3 options 1 Find a solution the is the default option 2 Find all solutions the solver is trying to find as many different
26. states that if the 270 OpenRules Inc Rule Solver User Manual constraint conditionConstraints is satisfied then the constraint conclusionConstraint also should be satisfied While the DecisionTableTemplate may contain more complicated constructions the very fact that the generated CSP can be reconfigured by simply changing the template directly in Excel makes this approach extremely flexible extensible and customizable for different needs Using JSR 331 The use of the standard JSR 331 allows a user not to commit to a particular CP solver A user may try different underlying solvers with the same decision model before choosing the most suitable one based on its technical and business applicability A user may switch between different underlying CP solvers compliant with the JSR 331 without any changes in the code Decision Execution Reports OpenRules provides an ability to generate decision execution reports in the HTML format To generate an execution report you should add the following setting to the decision s Java launcher decision put report On before calling decision execute By default execution reports are not generated as they are needed mainly for decision analysis Reports are regenerated for every decision run When you use the OPENRULES MODE equal to Solve Rule Solver generates an execution report The name of the generated report is formed using the name of the proper
27. the following results Decision ScheduleActivitiesWithwWorker Create RuleSolver JSR 331 Implementation based on Constrainer 5 4 light Rule Solver version 6 2 0 addConstrainedVariables Decision has been initialized with RuleSolver Initial Problem Variables Decision ScheduleActivitiesWithWorker Create RuleScheduler Decision ScheduleActivitieswWithwWorker Decision ScheduleActivitiesWithWorker Decision ScheduleActivitiesWithWorker Decision ScheduleActivitiesWithWorker Define Schedule Define Activities Define Precedence Constraints Define Worker Define Resource Requirement Constraints Assigning Data After Posting Constraints Solve Solution masonry 7 gt 7 requires Worker 1 carpentry 7 3 gt 10 requires Worker 1 roofing 1 1 gt 11 requires Worker 1 plumbing 11 8 gt 19 requires Worker 1 ceiling 19 3 gt 22 requires Worker 1 windows 22 1 gt 23 requires Worker 1 facade 23 2 gt 25 requires Worker 1 garden 25 1 gt 26 requires Worker 1 painting 26 2 gt 28 requires Worker 1 movingIn 28 1 gt 29 requires Worker 1 Example Scheduling Construction Jobs with a Limited Budget Now we will add an additional requirement to the above problem Along with worker constraints we have to consider budget constraints Each activity requires the payment of 1 000 per day Let s assume that a bank agreed
28. to finance the house constructions for the total amount of 29 000 However the sum is available in two installations 13 000 is available at the start of the 70 OpenRules Inc Rule Solver User Manual project and 16 000 is available 15 days afterwards How could we still construct the house under these constraints We need to extend our decision model by adding a resource Budget and the proper requirement constraints Here is the updated decision Decision ScheduleActivitiesWithWorkerBudget Define Schedule DefineSchedule Define Activities DefineActivities Define Precedence Constraints DefinePrecedenceConstraints Define Worker amp Budget DefineResources Define Budget Limitations SetBudgetCapacities Define Resource Requirement Constraints ResourceRequirementConstraints Now we will add both Worker and Budget resources in the following table DecisionTable DefineResources Worker Recoverable 1 Budget Consumable 30000 The updated resource requirement table will look as follows DecisionTable ResourceRequirementConstraints Worker masonry 1 carpentry Worker 1 roofing Worker 1 plumbing Worker 1 ceiling Worker 1 windows Worker 1 facade Worker 1 710 OpenRules Inc Rule Solver User Manual garden Worker 1 paint
29. we will define activities DecisionTable Define Activities masonry 7 carpentry 3 roofing 1 plumbing 8 3 1 2 ceiling windows facade 610 OpenRules Inc garden painting movingIn And finally we will define precedence constraints Rule Solver User Manual DecisionTable DefinePrecedenceConstraints ActionActOperAct Activity Operator Activity Day carpentry gt masonry roofing gt carpentry plumbing gt masonry ceiling gt masonry windows gt roofing fagade gt plumbing fagade gt roofing garden gt roofing garden gt plumbing movingIn gt windows movingIn gt fagade movingIn gt garden movingIn gt painting The model is ready to be executed by this Java launcher public static void main String args String fileName file rules Decision x1s System setProperty OPENRULES MODE Solve Decision decision new Decision ScheduleActivities fileName decision execute It will produce the following results Decision ScheduleActivities Create RuleSolver JSR 331 Implementation based on Rule Solver version 6 2 0 addConstrainedVariables xk K Decision has been initialized with RuleSolver Initial Problem Variables Decision ScheduleActivities Create RuleScheduler Decision ScheduleActivities Decision ScheduleActivities Define
30. 3 gt 10 requires Worker 1 requires Budget 1000 roofing 1 1 gt 11 requires Worker 1 requires Budget 1000 plumbing 11 8 gt 19 requires Worker 1 requires Budget 1000 ceiling 19 3 gt 22 requires Worker 1 requires Budget 1000 windows 22 1 gt 23 requires Worker 1 requires Budget 1000 720 OpenRules Inc Rule Solver User Manual facade 23 2 gt 25 requires Worker 1 requires Budget 1000 garden 25 1 gt 26 requires Worker 1 requires Budget 1009 painting 26 2 gt 28 requires Worker 1 requires Budget 1000 movingIn 28 1 gt 29 requires Worker 1 requires Budget 1000 Example Scheduling Construction Jobs with Alternative Resources Now let s consider a construction job scheduling example with alternative resources that are required to execute those jobs Let s assume that we have 3 workers Joe Jim and Jack with different skills Each job requires only one of these workers depending on their skills masonry requires Joe or Jack carpentry requires Joe or Jim plumbing requires Jack ceiling requires Joe or Jim roofing requires Joe or Jim painting requires Jack or Jim windows requires Joe or Jim facade requires Joe or Jack garden requires Joe or Jack or Jim movingIn requires Joe or Jim We will extend the previously described basic construction job scheduling example We need to add 3 disjunctive resources Joe Jim and Jack The fact that an activity
31. 55 2 X36 x37 x38 x46 x47 x48 x56 x57 x58 x x60 x61 x62 x70 x71 x72 x80 x81 x82 3 xX63 x64 x65 x73 x74 x75 x83 x84 x85 x66 x67 x68 x76 x77 x78 x86 x87 x88 This table creates AllDiff constraints for all arrays listed in every row of this decision table This completes the decision model To execute this model we may use this Java method public static void main String args String fileName file rules Decision x1s System setProperty OPENRULES MODE Solve Decision decision new Decision DefineAndSolveSudoku fileName decision execute decision execute PrintSolution decision To print a solution we will use this Excel s table 490 OpenRules Inc Rule Solver User Manual Method void PrintSolution Decision decision System out_printin RuleSolver solver decision get solver System out println solver get VarMatrix x We will receive the following results Decision DefineAndSolveSudoku Create RuleSolver JSR 331 Implementation based on Constrainer 5 4 light Rule Solver version 6 2 0 addConstrainedVariables Decision has been initialized with RuleSolver Initial Problem Variables Decision DefineAndSolveSudoku Create 9x9 Matrix Decision DefineAndSolveSudoku Enter Known Problem Data Decision DefineAndSolveSudoku Define Main Constraints After Assigning Data After Posting Constraints Solve Solution
32. Calculate Internal Variables Conclusion Total Debt Is 165600 Conclusion Total Income Is 360000 Decision DetermineLoanPreQualificationResults Validate Income Conclusion Income Validation Result Is SUFFICIENT Decision DetermineLoanPreQualificationResults Debt Research Conclusion Debt Research Result Is High Decision DetermineLoanPreQualificationResults Summarize Conclusion Loan Qualification Result Is QUALIFIED Decision has been finalized Please note that the variable Loan Qualification Result depends on the variables Income Validation Result and Debt Research Result So for the sequential rule engine it is extremely important that sub decisions Validate Income and Debt Research are specified before the sub decision Summarize Now we find a solution for the same decision model using OpenRules Rule Solver that resolves rules sequencing issues automatically 190 OpenRules Inc Rule Solver User Manual Solution with Rule Solver The main Java class MainCP java contains one method main that is similar to the previous one but contains one extra line before creation of the decision public static void main String args String fileName file rules main Decision xls System setProperty OPENRULES MODE Solve Decision decision new Decision DetermineLoanPreQualificationResults fileName decision execute The statement System setProperty OPENRULES
33. E englishman 0 4 TRUE spaniard 0 4 TRUE juice 0 4 TRUE tea 0 4 TRUE milk 0 4 TRUE water 0 4 TRUE coffee 0 4 TRUE snail 0 4 TRUE dog 0 4 TRUE fox 0 4 TRUE horse 0 4 TRUE zebra 0 4 TRUE chesterfield 0 4 TRUE parliament 0 4 TRUE lucky TRUE oldGolds 0 4 TRUE kools TRUE OpenRules Inc Rule Solver User Manual It defines our decision variables in the domain from 0 to 4 assuming that our houses are numbered as 0 1 2 3 and 4 We will define AllDiff constraints for all variables using this decision table DecisionTable AllDiffConstraints green ivory blue red yellow Norwegian Ukrainian Japanese Englishman Spaniard juice tea milk water coffee snail dog fox horse ZEBRA Chesterfield Parliament Lucky OldGolds Kools We may define unconditional linear constraints using the following decision table DecisionTable ZebraConstraints1 _ X lt oper gt Y Englishman _ red The PEUR at lives in the red ouse Spaniard dog The Spaniard owns the dog coffee green Coffee is drunk in the green house Ukrainian tea The Ukrainian drinks tea OldGolds snail The Old Golds smoker owns snails Kools _ yellow Kools are ee in the yellow ouse milk 2 Milk is drunk in the middle house Norwegian
34. FICIENT Debt Research Result High Mid Low Mortgage Holder Yes Total Debt 500000 Total Income 580000 Loan Qualification Result QUALIFIED NOT QUALIFIED Loan Holder No Internal Credit Rating A Internal Analyst Opinion Low Step 5 After Posting Constraints Outside Credit Score 720 Education Loan Balance Monthly Income 5000 Credit Card Balance 2500 Income Validation Result SUFFICIENT Debt Research Result High Mortgage Holder Yes Total Debt 165600 Total Income 360000 Loan Qualification Result QUALIFIED Loan Holder No Internal Credit Rating A Internal Analyst Opinion Low Step 6 Solve The descriptions of the green steps are similar to the ones described in the previous example s you can see after all execution steps described in the previous example we received the same results as those produced by the rule engine The rule engine produced Conclusion Loan Qualification Result Is QUALIFIED while Rule Solver instantiated the variable Loan Qualification Result with the value QUALIFIED Loan Qualification Result QUALIFIED 210 OpenRules Inc Rule Solver User Manual Here again pure constraint propagation was sufficient to find one and only one solution of this problem However contrary to the rule engine now we can freely change the order of sub decisions in the main table Decision Decision Modeling wit
35. Mortgage Holder No AND Outside Credit Score gt 550 AND Outside Credit Score lt 900 AND Loan Holder No AND Credit Card Balance gt 0 THEN Debt Research Result Low IF Mortgage Holder No AND Outside Credit Score gt 550 AND Outside Credit Score lt 900 AND Loan Holder No AND Credit Card Balance lt 0 AND Education Loan Balance lt 0 THEN Debt Research Result Low IF Mortgage Holder No AND Outside Credit Score gt 550 AND Outside Credit Score lt 900 AND Loan Holder No AND Credit Card Balance lt 0 AND Education Loan Balance gt 0 AND Internal Credit Rating ISONEOF D F THEN Debt Research Result High IF Mortgage Holder No AND Outside Credit Score gt 550 AND Outside Credit Score lt 900 AND Loan Holder No AND Credit Card Balance lt 0 AND Education Loan Balance gt 0 Rule Solver User Manual DetermineDebtResearchResult DetermineDebtResearchResult DetermineDebtResearchResult DetermineDebtResearchResult DetermineDebtResearchResult DetermineDebtResearchResult DetermineDebtResearchResult 310 OpenRules Inc Rule Solver User Manual AND Internal Credit Rating ISONEOF A B C THEN Debt Research Result Low IF Mortgage Holder No AND Internal Analyst Opinion High THEN Debt Research Result DetermineDebtResearchResult High IF Mortgage Holder No AND Internal Analyst Opinion Mid THEN Debt Research Result DetermineDebtResearchResult Mid IF Mortgage Holde
36. OPEN Ai I FA IN AY RULE SOLVER Constraint Programming with OpenRules 6 3 1 USER MANUAL OpenRules Inc www openrules com May 2014 OpenRules Inc Table of Contents Introduction Document Conventions Rule Solver as Inferential Rule Engine Simple Examples Simple Decision Model DecisionHello TM Rule Solver User Manual Decision Model Solution with Rule Engine maa DB WN A Solution with Rule Solver 11 Simple Decision Model DecisionLoan 14 Decision Model 14 Solution with Rule Engine 19 Solution with Rule Solver 20 Decision Modeling with Rules Solver Rule Solver Benefits 22 22 How Rule Solver Works 22 Generating CSP 23 Adding Constrained Variables 24 Adding Constraints 24 Posting Data Constraints 25 Posting Problem Constraints 25 Solving the Problem 26 Using Templates 27 Using JSR 331 28 Decision Execution Reports 28 OpenRules Solver Execution Report Decision DetermineLoanPreQualificationResults 29 29 Wed Apr 23 16 41 58 EDT 2014 29 Assigning Data To Decision Variables 29 Posting If Then Constraints 30 Posted If Then Constraints 30 Decision Output 33 Implementation Restrictions and Future Improvements 33 Rule Solver as a Business Oriented Constraint Solve
37. can solve it Here are the problem constraints 1 There are five houses 2 The Englishman lives in the red house 3 The Spaniard owns the dog 4 Coffee is drunk in the green house 510 OpenRules Inc Rule Solver User Manual 5 The Ukrainian drinks tea 6 The green house is immediately to the right of the ivory house 7 The Old Gold smoker owns snails 8 Kools are smoked in the yellow house 9 Milk is drunk in the middle house 10 The Norwegian lives in the first house 11 The man who smokes Chesterfields lives in the house next to the man with the fox 12 Kools are smoked in the house next to the house where the horse is kept 13 The Lucky Strike smoker drinks orange juice 14 The Japanese smokes Parliaments 15 The Norwegian lives next to the blue house Where is the Zebra Let s start with a glossary Glossary glossary Decision Variables Business Concept Attribute Domain Unknown Colors Norwegian Ukrainian People Japanese Englishman Spaniard Drinks Pets Chesterfield Parliament Cigarettes Lucky OldGolds Kools Zebra Problem green 0 4 TRUE ivory 0 4 TRUE blue 0 4 TRUE red 0 4 TRUE yellow 0 4 TRUE norwegian 0 4 TRUE ukrainian 0 4 TRUE japanese 0 4 TRU
38. clipse IDE To use the Rule Solver with Eclipse IDE simply import the project com openrules solver and different decision projects such as DecisionLoanXP into your Eclipse workspace You may run Java samples directly from Eclipse by selecting their sources with a right click and then Run as Java Application To switch between underlying solvers just select the Project Properties and simply change Libraries inside Java Build Path TECHNICAL SUPPORT Direct all your technical questions to support openrules com or to these Google discussion groups OpenRules Forum and JSR 331 Forum 770
39. e column Domain So Rule Solver automatically defines that only variables that are used inside decision table conclusions are unknown Those variables 130 OpenRules Inc Rule Solver User Manual are AgeGroup Greeting and Salutation and as you can see their domains continue to contain multiple possible values Step 5 Then Rule Solver posts activates constraints that correspond to the rules defined in our decision tables The order of constraint posting really does not affect the final results Rule Solver reports the state of our constrained variables after constraint posting After Posting Constraints Marital Status Married Greeting Good Afternoon Age 4 Age Group Little Gender Female Salutation Little Current Hour 16 As you can see in this simple case constraint posting was sufficient to instantiate all constraint variables select single values from their domain Step 6 However in many practical cases constraint posting is not sufficient and Rule Solver always executes its default search algorithm to find a single solution of an automatically created constraint satisfaction problem Rule Solver also saves all found values of constrained variables back to the proper attributes of the business objects based on which these variables were created Simple Decision Model DecisionLoan In this example we will demonstrate a simple loan pre qualification model
40. ecisions Decision DetermineCustomerGreeting Define Age Group DefineAgeGroup Define Greeting Word DefineGreeting Define Salutation Word DefineSalutation The first sub decision Define Age Group will be implemented using the following decision table DecisionTable DefineAgeGroup Condition Condition Age Age gt 0 lt 5 Is Little gt 5 lt 20 Is Young gt 20 Is Adult The second sub decision Define Greeting Word will be implemented using the following decision table Condition Condition I Current Hour Current Hour Greeting gt 0 lt 11 Is Good Morning gt 11 lt 17 Is Good Afternoon gt 17 lt 22 Is Good Evening gt 22 lt 24 Is Good Night 70 OpenRules Inc Rule Solver User Manual The third sub decision Define Salutation Word will be implemented using the following decision table DecisionTable DefineSalutation Condition Condition Condition Gender Marital Status Age Group Is Lite Is Little Is Female Is Married Is Mrs Is Female Is Single Av Little Is Ms Is Male Is Mr The proper Glossary for this model can be defined as follows Glossary glossary Variable Name Gender gender Male Female Marital Status maritalStatus Single Married Age Customer age 0 120
41. ementation based on Constrainer 5 4 light Step 2 Then Rule Solver generates a constraint satisfaction problem by adding constrained variables based on the Glossary and actual business objects and constraints based on decision tables So it adds Constrained Variables and shows their initial state as Marital Status Single Married Greeting Good Morning Good Afternoon Good Evening Good Night Age 120 Age Group Little Young Adult Gender Male Female Salutation Mr Ms Mrs Little Current Hour 24 3 Step 3 When Rule Solver executes the sub decisions from the table Decision Decision DetermineCustomerGreeting Define Greeting Word Decision DetermineCustomerGreeting Define Salutation Word Decision DetermineCustomerGreeting Define Age Group it actually creates the proper constraints but does not post activate them yet Step 4 Then Rule Solver assigns data to decision variables that are already known In our case those variables are Marital Status Age Gender and Current Hour After Assigning Data Marital Status Married Greeting Good Morning Good Afternoon Good Evening Good Night Age 4 Age Group Little Young Adult Gender Female Salutation Mr Ms Mrs Little Current Hour 16 Please note that our Glossary does not explicitly specify which variables are unknown otherwise there will be one more column Unknown following th
42. feasible values are removed from the domains of the variables through reasoning about the constraints Major CP Concepts CP supports a clear separation between Problem Definition and Problem Resolution At the very high level a business user that defines a CSP is presented with only 6 major concepts e Problem for problem definition o Constrained Variable o Constraint e Solver for problem resolution o Search Strategy o Solution While different constraint solvers use diverse names and representations for CP concepts semantically these 6 concepts are invariants for the majority of solvers JSR 331 provides a unified naming convention and detailed specifications for these concepts You may want to read the JSR 331 User Manual which contains a variety of Java examples Below we explain how to represent and solve different CSPs using MS Excel and OpenRules decision tables Contrary to Java Rule Solver allows subject matter experts non programmers to utilize the power of constraint 35 OpenRules Inc Rule Solver User Manual programming Rule Solver provides a set of templates defined in Excel that allow a user to define and solve different CSPs using only simple Excel based decision tables The following example will demonstrate how to create decision models for simple CSPs Introductory Example SEND MORE MONEY This example demonstrates how to represent and solve a simple puzzle using
43. h Rules Solver Previous examples demonstrate how Rule Solver may be used instead of the standard rule engine For the same Excel based decision model Rule Solver executes all related business rules and either infers a decision or diagnoses conflicts among rules and input data Rule Solver Benefits Rule Solver brings several important benefits to decision modeling No explicit ordering between decision tables No explicit ordering of rules within decision tables Automatic validation of conflicts between rules across all decision tables Automatic check of decision models for completeness and an ability to find a decision when rules do not cover all possible combinations of decision variables How Rule Solver Works Formally we may describe a decision model as follows There is a set of business objects X I Xi Xn Each business object Xi contains decision variables Vi Vi Vm with possible values Dj vii Vik for each variable Vi There is a set of rules R Ri Rr where a rule Rx defines relationships between different decision variables by specifying the allowed combinations for all variables in that rule 220 OpenRules Inc Rule Solver User Manual The rules from set R are grouped into rule sets usually called Decision Tables Execution of a decision model should cause the assignment of values to all decision variables that satisfy all rules To execute a decisio
44. in terms of activities and resources Activities may have an unknown start duration and end and may require or produce different resources Resources may have different types e g recoverable like humans or consumable like money and their limited capacities may vary over time The package includes major temporal and capacity constraints specified in accordance with the JSR 331 requirements We will describe this package below Now we will consider the following examples of scheduling problems presented in Java or with Rule Solver templates Example Scheduling Construction Jobs Let s assume that we plan to construct a house The construction requires the following activities with the following fixed durations and precedence temporal constraints 580 OpenRules Inc Rule Solver TM User Manual Here arrows represent temporal constraints like Carpentry starts after the end of Masonry The numbers near each activity represent its durations in days Solution in Java First consider a pure Java code for this simple problem package org jcp jsr331 scheduler samples import javax constraints import javax constraints scheduler public final class ScheduleActivities Schedule S ScheduleFactory newSchedule ScheduleActivities 0 40 public void define throws defining jobs Ac Ac Ac Ac Ac Ac Ac Ac Ac Ac tivi tivi tivi tivi tivi tivi tivi tivi
45. ing Worker 1 movingIn Worker 1 masonry Budget 1000 carpentry Budget 1000 roofing Budget 1000 plumbing Budget 1000 ceiling Budget 1000 windows Budget 1000 fa ade Budget 1000 garden Budget 1000 painting Budget 1000 movingIn Budget 1000 And finally the fact that during the first 15 days only 15 000 are available can be expressed using the following table DecisionTable SetBudgetCapacities ActionResourceCap Resource From To Capacity Budget 0 15 15000 Now the same Java launcher will produce the following results Decision ScheduleActivitiesWithWorkerBudget Create RuleSolver JSR 331 Implementation based on Constrainer 5 4 light Rule Solver version 6 2 0 addConstrainedVariables Decision has been initialized with RuleSolver Initial Problem Variables Decision ScheduleActivitiesWithWorkerBudget Define Schedule Create RuleScheduler Decision ScheduleActivitiesWithWorkerBudget Define Activities Decision ScheduleActivitiesWithWorkerBudget Define Precedence Constraints Decision ScheduleActivitiesWithWorkerBudget Define Worker amp Budget Decision ScheduleActivitiesWithWorkerBudget Define Budget Limitations Decision ScheduleActivitiesWwithWworkerBudget Define Resource Requirement Constraints After Assigning Data After Posting Constraints Solve Solution masonry 7 gt 7 requires Worker 1 requires Budget 1000 carpentry 7
46. initialized with RuleSolver Initial Problem Variables Decision ScheduleActivitiesWithAlternativeResources Define Schedule Create RuleScheduler Decision ScheduleActivitiesWwithAlternativeResources Define Activities Decision ScheduleActivitiesWithAlternativeResources Define Precedence Constraints Decision ScheduleActivitiesWithAlternativeResources Define Workers Decision ScheduleActivitiesWithAlternativeResources Define Resource Requirement Constraints After Assigning Data 740 OpenRules Inc Rule Solver User Manual After Posting Constraints Solve Solution masonry 7 gt 7 requires Jack 1 carpentry 7 3 gt 10 requires Jim 1 roofing 1 1 gt 11 requires Jim 1 plumbing 7 8 gt 15 requires Jack 1 ceiling 7 3 gt 10 requires Joe 1 windows 11 1 gt 12 requires Jim 1 facade 15 2 gt 17 requires Jack 1 garden 15 1 gt 16 requires Jim 1 painting 2 gt 2 requires Jim 1 movingIn 17 1 gt 18 requires Jim 1 INSTALLATION Rule Solver can be installed as an component of the complete version of OpenRules and available in the workspace openrules solver You will download and unzip this folder to your hard drive It is self sufficient and can be used with Windows Explorer or Eclipse IDE Structure Unzipped openrules solver includes the following projects Project com openrules solver This project conta
47. ins an implementation of Rule Solver Folder src with source files o com openrules solver source code for Rule Solver o com openrules solver samples Rule Solver examples including MissManners that deals with set constrained variables o org jcp jsr331 samples sources with JSR 331 examples o org jcp j3sr331 scheduler samples sources with scheduling examples Folder lib with supporting jar files o jsr331 jar dJSR 331 jar files with 3 open source implementations 750 OpenRules Inc O Folder O O Rule Solver User Manual apache jar Apache Commons jars choco jar jars for Choco s implementation of the JSR 331 jacop jar jars for JaCoP s implementation of the JSR 331 constrainer jar jars for Constrainer s implementation of the JSR 331 scheduler jar Scheduler s jar file that also includes all sources rules with Excel files for all Rule Solver samples common Templates xls basic OpenRules templates for defining and solving CSPs common ScheduleTemplates xls OpenRules templates for scheduling CSPs common RulesSolver xls common Excel files that defines Rule Solver environment called from all other Excel files lt Name gt xls various Rule Solver examples without decisions Project openrules config This project contains standard OpenRules jars in the folder lib and decision tem
48. ion getEngine Then Rule Solver adds constrained variables using the following method 230 OpenRules Inc Rule Solver User Manual solverVar solver addConstrainedVariables getGlossary This method iterates through the decision model s glossary and for each decision variable creates a constrained variable of one of the following types Var for integer constrained variables VarString for string constrained variables VarBool for Boolean constrained variables VarReal for real constrained variables VarSet for set constrained variables Note The current version is limited to only two types Var and VarString Adding Constrained Variables Rule Solver automatically converts decision variable domains from the glossary to the domains of the constrained variables as they are specified by JSR 331 While the glossary does not specify a particular type of the decision variables the concrete types of constrained variables are defined based on the provided data instances For example a constrained variable that corresponds to the decision variable Monthly Income will be created using the following JSR 331 method rs variable Monthly Income 0 50000000 Adding Constraints During processing the tables of the type Decision Rule Solver executes all decision tables and for every rule adds a conditional constraint that has the following form conditionConstraints implies conclusionConstraint
49. ion problem is specified in Excel based decision tables it will be automatically solved by an underlying constraint solver Being based on the standard JSR 331 Constraint Programming API defined by the Java Community Process Rule Solver allows a user to switch between different JSR 331 compliant solvers without any changes in the application code Constraint Satisfaction Problem CSP Many real life problems that deal with multiple alternatives with many unknowns subject to different constraints can be presented and solved as constraint satisfaction problems CSP Formal Definition Formally a constraint satisfaction problem is defined by e aset of variables Vi V2 Vn and e aset of constraints Ci C2 Cm 34 OpenRules Inc Rule Solver User Manual Each variable Vi has a non empty domain Di of possible values Each constraint Cj involves some subset of the variables and specifies the allowable combinations of values for that subset A state of the problem is defined by an assignment of values to some or all of the variables A solution to a CSP is an assignment that satisfies all the constraints If a CSP requires a solution that maximizes or minimizes an objective function it is called a constraint optimization problem We will use the abbreviation CSP for both types of problems The main CSP search technique interleaves various forms of search with constraint propagation in which in
50. lanatory All these tables extend decision templates predefined in Rule Solver file DecisionTableSolveTemplates xls included in the standard installation Find One Solution After the execution of the above main method we will receive these results Decision FindXYZ Create RuleSolver JSR 331 Implementation based on Constrainer 5 4 light Rule Solver version 6 2 0 addConstrainedVariables Decision has been initialized with RuleSolver Initial Problem Variables Y 0 10 Xx 0 10 7 0 10 Decision FindXYZ Define Var Z Decision FindXYZ Binary Constraints After Assigning Data Y 9 10 x 0 10 7 0 10 After Posting Constraints Y 1 10 x 0 9 Z 6 10 Solve Decision x 2 y 4 z 6 Find All Solutions If you want to find not one but many possible solutions of this problem you may add the following statement to your Main java program just before decision execute decision put MaxSolutions 30 Then Rule Solver will produce 21 different solutions Find All Solutions but not more than 30 44 OpenRules Inc Rule Solver User Manual Solution 1 Solution 2 Solution 3 Find Optimal Solution Now let s add a new decision variable Cost defined in the domain 5 20 and equals to Cost X Y Z First we will add an int variable cost to our Java bean XYZ Then we will modify the Glossary GI
51. leActivities also use another strategy strategyAssignResources Putting these two strategies in the solver strategy list we allow a solver to first try to schedule activities and then to try to assign the required resource capacities to them When resource assignments fail a solver will backtrack and will try different placements of activities in time Here are the produced results Solution A 5 1 gt 6 requires oven 2 B 3 4 gt 7 requires oven 1 C 7 4 gt 11 requires oven 1 D 0 2 gt 2 requires oven 1 E 6 4 gt 10 requires oven 2 Resource oven tO l tl 1 t2 0 t3 1 t4 1 t5 3 t6 3 t7 3 t8 3 t9 3 t10 1 Execution Profile Number of Choice Points 5 Number of Failures 2 Execution time 31 msec Now the method logActivities also shows the required resources with required capacities in brackets The method logResources shows the resource oven with its daily capacities assigned to their possible minimums The produced statistics shows that there were two failures when the solver had to reconsider previously selected start times for some activities Learn By Examples We can extend the previously described basic construction job scheduling example to demonstrate more complex scheduling and resource allocation problems 68 O OpenRules Inc Rule Solver User Manual Example Scheduling Construction Jobs with a Worker Previously
52. lems are job scheduling resource allocation planning product configuration and other decision support problems with many business constraints CP provides a great foundation for the development of smart optimization and decision support engines There are multiple powerful commercial and open source constraint solvers available on the market today OpenRules Business Decision Management System BDMS includes a special component called a Rule Solver that empowers OpenRules with constraint programming functionality Rule Solver can be used for two major purposes 1 Rule Solver as an inferential rule engine for decision models o Analternative to the standard OpenRules sequential rule engine that executes decision models in a way similar to famous RETE based rule engines no needs for rule ordering o A powerful mechanism for consistency validation of OpenRules decision models 2 Rule Solver as a business oriented constraint solver o An ability to represent constraint satisfaction problems using Excel based decision tables oriented to business users o An ability to solve constraint satisfaction problems with any JSR 331 compliant constraint solver This user manual explains how to install and use Rule Solver It is aimed at developers of real world decision models that need a more sophisticated mechanism to compare with traditional rule engines Rule Solver includes a 1 JSR 331 Constraint
53. lusion Age Group Is Little Decision DetermineCustomerGreeting Define Salutation Word Conclusion Salutation Is Little Decision has been finalized Decision Good Afternoon Little Robinson There are many other examples and more powerful decision table types described in the OpenRules User Manual However the standard OpenRules is rule engine sequential and relies on the strictly defined execution order of rules inside the table Decision Let s change this order as follows Decision DetermineCustomerGreeting Define Greeting Word DefineGreeting Define Salutation Word DefineSalutation Define Age Group DefineAgeGroup As you can see now the standard rule engine will execute the rules DefineAgeGroup after the rules DefineSalutation which use the decision variable Age Group defined by DefineAgeGroup So the variable will remain undefined null and the execution results will be quite bad 10 OpenRules Inc Rule Solver User Manual Decision DetermineCustomerGreeting Decision has been initialized Decision DetermineCustomerGreeting Define Greeting Word Conclusion Greeting Is Good Afternoon Decision DetermineCustomerGreeting Define Salutation Word Decision DetermineCustomerGreeting Define Age Group Conclusion Age Group Is Little Decision has been finalized Decision Good Afternoon null Robinson Now we find a solution for the same decision m
54. n 36 Brown Thus our data is specified and we should connect instances of our test objects with business concepts specified on the glossary It can be done using the following table of the type DecisionObject DecisionObject decisionObjects Customer customers 0 Request loanRequests 0 Internal internal This completes the definition of our decision model The next step is to find solutions for this model We will start with a regular sequential OpenRules rule engine that will execute our decision 18 OpenRules Inc Rule Solver User Manual Solution with Rule Engine The standard OpenRules installation comes with the proper decision project DecisionLoanCP in the workspace openrules solver The main Java class Main java contains one method main that creates and executes our Excel based decision public static void main String args String fileName file rules main Decision x1s Decision decision new Decision DetermineLoanPreQualificationResults FileName decision execute Note that here we omitted the statement System setProperty OPENRULES MODE Execute because the mode Execute is used by default After execution of this code we will receive the following results Decision DetermineLoanPreQualificationResults Decision has been initialized Decision DetermineLoanPreQualificationResults
55. n model Rule Solver does the following 1 Reads a decision model created by business analysts directly from the rule repository usually from a set of Excel files 2 Generates a constraint satisfaction problem CSP using JSR 331 CP API o Creates a CSP instance o Creates constrained variables for all unknown decision variables described in the decision model s glossary o Creates constraints that correspond to the rules defined in all decision tables 3 Validate the consistency of the model by checking the consistency of the generated CSP and points to possible conflicts using the business terms of the initial decision model 4 Executes the decision model against concrete data using the following steps o instantiating all constrained variables for which input data is defined o posting all constraints that correspond to rules from all decision tables o if constraint propagation by itself does not find single values for all decision variables does not instantiate all constrained variables then runs a constraint solver s search strategy that finds a solution of the CSP Generating CSP Rule Solver creates a CSP instance during initialization of the decision model It is done by the standard method customInitializeDecision within the file DecisionTemplateSolveTempalte xls The actual CSP is an instance of the predefined class RuleSolver created by the following method RuleSolverFactory newRuleSolver solver decis
56. odel using OpenRules Rule Solver that resolves rules sequencing issues automatically Solution with Rule Solver The project DecisionHelloCP include another Java class MainCP that uses the same classes Customer and Response but with the following main method public class Main public static void main String args String fileName file rules main Decision xls System setProperty OPENRULES MODE Solve 111 Decision decision new Decision DetermineCustomerGreeting FileName Customer customer new Customer customer setName Robinson customer setGender Female customer setMaritalStatus Married customer setAge 4 customer setHour 16 Response response new Response decision put customer customer decision put response response decision put trace On decision execute out println Decision response getGreeting response getSalutation customer getName This code is exactly the same as above with only difference in this statement System setProperty OPENRULES MODE Solve 110 OpenRules Inc Rule Solver User Manual It forces OpenRules to use Rule Solver instead of the default rule engine In this case the execution results of the same decision model with the latest order of sub decisions will look as follows Decision DetermineCustomerGreeting Create RuleSolver JSR 331 Implementation based on
57. oid setZ int z this z Zz public String toString return x x y y z Z The main method to execute the decision model will look like below public static void main String args String fileName file rules main Decision x1s System setProperty OPENRULES MODE Solve Decision decision new Decision FindXYZ fileName XYZ xyz new XYZ decision put xyz xyz decision put trace On decision execute out println NnDecision xyz Let s define a glossary 4220 OpenRules Inc Rule Solver User Manual Glossary glossary Decision Variable X X 0 10 TRUE Y XYZ y 0 10 TRUE Z z 0 10 TRUE We may map the business concept XYZ to the actual object of the type XYZ using this DecisionObject table DecisionObject decisionObjects XYZ decision get xyz Our decision FindX YZ can be described in thios table Decision FindXYZ Define Var Z XplusYeqZ Binary Constraints BinaryConstraints And here are the proper decision tables for the problem constraints DecisionTable BinaryConstraints ActionXoperY X lt oper gt Y X lt Y Z gt 5 DecisionTable XplusYeqZ ActionXoperYcompareZ X lt oper gt Y lt compare gt Z X Y Z 430 OpenRules Inc Rule Solver User Manual Hopefully these tables are self exp
58. otal Income Total Debt Internal 0 500000 0 500000 We will assume that the data for our model comes not from Java but rather from tables defined in Excel The following table defines a datatype Customer Datatype Customer String fullName String SSN int monthlylncome int monthlyDebt String mortgageHolder int outsideCreditScore String loanHolder int creditCardBalance int educationLoanBalance String internalCreditRating String internalAnalystOpinion The following table defines a datatype LoanRequest Datatype LoanRequest String customer int amount String purpose int term String incomeValidationResult String debtResearchResult String loanQualificationResult 170 OpenRules Inc Rule Solver User Manual The following table defines a datatype InternalVariables Datatype InternalVariables int totallncome int totalDebt These internal variables can be created in the following table Variable InternalVariables internal Initially they are unknown we use zeros Now we may define test requests using the following Data table Data LoanRequest loanRequests 7 ME incomeValid debtResearch loanQualific customer amoun urpose r Pep ationResult Result ationResult Peter N Home 2 2 9 Johnson Agony Improvement r i Mary B 15000 Educatio
59. ox 0 horse 1 ZEBRA 4 Chesterfield 1 Parliament 4 Lucky 3 OldGolds 2 Kools 0 House 1 fox yellow Kools water Norwegian House 2 Chesterfield Ukrainian horse tea blue House 3 OldGolds milk red Englishman snail House 4 Lucky juice ivory Spaniard dog House 5 Parliament Japanese ZEBRA green coffee The proper project DecisionZebra is a part of the standard Rule Solver installation Solving Scheduling Problems The current version of the JSR 331 does not yet include a scheduling package So OpenRules developed a simple package javax constraints scheduler on the top of the standard JSR 331 interface It allows a user to define and solve different scheduling and resource allocation problems Rule Solver also provides OpenRules Excel templates that utilize the package org jcp jsr331 scheduler allowing a user to present scheduling problems directly in Excel General Model Scheduling is the process of placing activities in proper time sequence and allocating the correct resources to activities over time While there is a great diversity in scheduling problems there are a lot of constraints and strategies that are common for many problems The package 570 OpenRules Inc Rule Solver User Manual javax constraints scheduler implements the following general scheduling model Schedule Temporal Constraints Resource JJ Requirement Constraints A scheduling problem can be defined
60. plates additional Additionally to the standard templates Rule Solver comes with one template DecisionTableSolveTemplates xls Decision Projects There are many sample projects such as DecisionHelloCP DecisionLoanCP DecisionScheduleActivities and others Licenses Rule Solver is available under the terms of the most popular Open Source license known as GNU General Public License GPLv2 The included software is provided under the terms of open source licenses included in the folders for the proper solvers 760 OpenRules Inc Rule Solver User Manual Using a Standalone Version You may use Rule Solver directly from your file system All projects such as DecisionLoanXP contain a batch file run bat The folder com openrules solver contains batch files that can be used to run different examples For example runZebra bat will execute the example Zebra xls To run any example you may double click on the proper run lt Name gt bat file For example runOven bat will execute the problem defined in the file rules Oven xls If you work with UNIX LINUX you need to replace bat files with similar sh files To switch between CP solvers you need to modify the file run bat For example to switch from constrainer to choco put rem in front of set SOLVER lib constrainer and remove rem in front of set SOLVER lib choco Working under E
61. r Constraint Satisfaction Problem CSP Formal Definition 34 34 34 Major CP Concepts 35 Introductory Example SEND MORE MONEY 36 Excel based Decision Model 36 Pure Java Solution 40 Solving Arithmetic Problems 41 20 OpenRules Inc TM Rule Solver User Manual Find One Solution 44 Find All Solutions 44 Find Optimal Solution 45 Sudoku Problem 47 Magic Square Problem 50 Zebra Problem 51 Solving Scheduling Problems 57 General Model 57 Example Scheduling Construction Jobs 58 Solution in Java 59 Solution in Excel 61 Example Resource Allocation 63 Solution in Excel 64 Solution in Java 66 Learn By Examples 68 Example Scheduling Construction Jobs with a Worker 69 Example Scheduling Construction Jobs with a Limited Budget 70 Example Scheduling Construction Jobs with Alternative Resources 73 Installation 75 Structure 75 Project com openrules solver 75 Project openrules config 76 Decision Projects 76 Licenses 76 Using a Standalone Version 77 Working under Eclipse IDE 77 Technical Support 77 30 OpenRules Inc Rule Solver User Manual INTRODUCTION Today Constraint Programming CP has become a leading technique for solving complex constraint satisfaction and optimization problems in manufacturing telecom logistics finance and other industries Among such prob
62. r No AND Internal Analyst Opinion Low THEN Debt Research Result DetermineDebtResearchResult Low IF Income Validation Result UNSUFFICIENT THEN Loan Qualification DetermineLoanQualificationResult Result NOT QUALIFIED IF Income Validation Result SUFFICIENT AND Debt Research Result Low THEN Loan _ DetermineLoanQualificationResult Qualification Result NOT QUALIFIED IF Income Validation Result SUFFICIENT AND Debt Research Result ISONEOF Mid High THEN Loan Qualification Result QUALIFIED DetermineLoanQualificationResult Solution 1 Outside Credit Score 735 m Education Loan Balance o Monthly Income 4o00 Credit Card Balance 1200 Income Validation Result SUFFICIENT Debt Research Result Hin Mortgage Holder Yes 320 OpenRules Inc Rule Solver User Manual Loan Qualification Result QUALIFIED Monthly Debt 3000 Loan Holder Yes Internal Credit Rating Internal Analyst Opinion If some errors occur during the constraint posting they will be shown in red Decision Output Actually when you execute a decision using a constraint based inference engine it always returns solution s as a decision s output When your decision is trying to find one feasible or an optimal solution then after calling Decision s method decision execute you may write Solution solution Solution decision getOutput If the solution is null it means no solution is found Otherwise
63. rchResult Condition Condition Condition Mortgage Outside Outside Credit Card Holder Credit Score Credit Score Holder Balance And the fourth decision Summarize will be implemented using the following decision table DecisionTable DetermineLoanQualificationResult Condition Condition Conclusion Income Validation Debt Research Loan Qualification Result Result t i NOT Is UNSUFFICIENT Is QUALIFIED NOT Is SUFFICIENT Is Low Is QUALIFIED Is Is SUFFICIENT One Mid High Is QUALIFIED Of The proper Glossary for this model can be defined as follows Monthly monthlylncome 0 5000000 Income bg mortgageHolder Yes No Sera Credit Customer outsideCreditScore 0 999 Loan Holder loanHolder Yes No aia creditCardBalance 1000000 100000000 16 OpenRules Inc Education Loan Balance Internal Credit Rating Internal Analyst Opinion educationLoanBalance 1000000 100000000 Rule Solver User Manual internalCreditRating A B C D F internalAnalystOpinion High Mid Low Income Validation Result Debt Research Result Loan Qualification Result Request incomeValidationResult SUFFICIENT UNSUFFICIENT debtResearchResult High Mid Low loanQualificationResult AATE NOPGUMIRED T
64. s from Java that uses the following class public class ZebraProblem int green ivory blue red yellow int norwegian ukrainian japanese englishman spaniard int juice tea milk water coffee int snail dog fox horse zebra int chesterfield parliament lucky oldGolds kools automatically generated getters setters and toString 54 OpenRules Inc Rule Solver User Manual The glossary will be mapped with the actual Java objects using this table DecisionObject decisionObjects Zebra Problem z decision get problem Now we are ready to execute this Java launcher public static void main String args String fileName file rules main Decision x1s System setProperty OPENRULES MODE Solve Decision decision new Decision FindZebra fileName ZebraProblem zp new ZebraProblem decision put problem zp decision put trace On decision execute out println nDecision Zp decision execute printSolution decision To print a solution it will use the following method Method void print Solution Decision decision RuleSolver solver solver decision for int house 0 house lt 5 house System out_print nHouse house 1 Var vars solver getVarsWithValue house for int i 0 i lt vars_length i System out print vars i getName It will produce the following results Decision FindZebra
65. sion public class Main public static void main String args String fileName file rules main Decision x1s System setProperty OPENRULES MODE Execute Decision Customer customer setGender Female customer customer customer customer Response decision decision decision decision out println Decision decision new Decision DetermineCustomerGreeting fileName customer new Customer setName Robinson setMaritalStatus Married setAge 4 setHour 16 response new Response put customer customer put response response put trace On execute response getGreeting Fo response getSalutation customer getName 90 OpenRules Inc Rule Solver User Manual This code uses a predefined OpenRules class Decision that extends HashMap and allows a user to put and get any object to the decision using keywords like Customer The above statement System setProperty OPENRULES MODE Execute reinforces the fact that we will use the default execution mode that is based on the standard OpenRules rule engine After execution of this code we will receive the following results Decision DetermineCustomerGreeting Decision has been initialized Decision DetermineCustomerGreeting Define Greeting Word Conclusion Greeting Is Good Afternoon Decision DetermineCustomerGreeting Define Age Group Conc
66. t 14 Y 6 X 4 Z 1e Rule Solver User Manual The proper decision project DecisionX YZ can be found in the standard Rule Solver installation in the workspace openrules solver Sudoku Problem The objective of this very popular game is to fill a 9x9 grid so that each column each row and each of the nine 3x3 boxes also called blocks contain the digits from 1 to 9 only one time each The standard Rule Solver installation comes with the proper decision project DecisionSudoku in the workspace openrules solver This project has only one file Decision xls that includes all needed Excel tables We will start with the main table Decision and will not use a glossary at all Decision DefineAndSolveSudoku Create 9x9 Matrix solver decision variableMatrix x 1 9 9 9 Enter Known Problem Data EnterSudokuData Define Main Constraints DefineSudokuConstraints 66 9 The very first sub decision creates a 9x9 matrix x of constrained integer variables defined on the domain 1 9 The element in the row i and column j has name xij 470 OpenRules Inc We will enter Sudoku data using this Excel method Method boolean EnterSudokuData Decision decision RuleSolver solver decision get solver VarMatrix matrix solver get VarMatrix x int data Matrixint getMatrix problem1 for int i 0 i lt 9 i for int j 0
67. t d int m int 0 int r int y int send int more int money Variable Puzzle puzzle s e n d m o r y send more money S E N D M O R Y SEND MORE MONEY 0 0 0 0 0 0 0 0 0 0 0 The initial values 0 will be ignored as all our variables are unknown To connect the data objects with the glossary we need the following table DecisionObject decisionObjects I Puzzle puzzle Now we need to define our intermediate variables SEND MORE and MONEY as scalar products using the following table 370 OpenRules Inc Rule Solver User Manual DecisionTable AddScalarProducts SEND 1000 100 10 1 S E N D MORE 1000 100 10 1 M O R E MONEY 10000 1000 100 10 1 M O N E Y The first row of this decision table defines SEND as a scalar product S 1000 E 100 N 10 1 D Similarly the second and third rows define variables MORE and MONEY using the proper scalar products Now we may define the main problem constraint SEND MORE MONEY DecisionTable MainConstraint SEND MORE MONEY To state that our 8 main decision variables are different we may use a decision table for the AllDiff constraint DecisionTable AllDifferentConstraint S E N D M O R Y And finally we need a table of the type Decision that puts all constraints together Decision SendMoreMoney Add Intermediate Variables AddScalarProducts Main Cons
68. that should decide whether to approve or decline a loan application Decision Model We will use Excel to represent decisions related decision tables and several test cases We will start with the main table of the type Decision that consists of 4 sub decisions 140 OpenRules Inc Rule Solver User Manual Decision DetermineLoanPreQualificationResults Decisions Execute Rules Calculate Internal Variables CalculatelnternalVariables Validate Income DeterminelncomeValidationResult Debt Research DetermineDebtResearchResult Summarize DetermineLoanQualificationResult The first sub decision Calculate Internal Variables will be implemented using the following decision table DecisionTable CalculatelnternalVariables Conclusion Conclusion Total Debt Total Income oO Is l Monthly Debt l Loan Term l Monthly Income l Loan Term The second sub decision Validate Income will be implemented using the following decision table DecisionTable DeterminelncomeValidationResult Condition Conclusion Total Income Income Validation Result Is More l Total Debt 2 Is SUFFICIENT Than lt l Total Debt 2 Is UNSUFFICIENT The third sub decision Debt Research will be implemented using a more complex decision table 150 OpenRules Inc Rule Solver User Manual Decision Table DetermineDebtResea
69. traint MainConstraint All Different AllDifferentConstraint This completes our decision model To print the result directly from Excel we may add one more method PrintSolution 38 OpenRules Inc Rule Solver User Manual Method void PrintSolution Decision decision System out println n SISEND in SHMORE To execute this model with Rule Solver we will use a Java class Main java with the following main method public static void main String args String fileName file rules Decision xls System setProperty OPENRULES MODE Solve Decision decision new Decision SendMoreMoney fileName decision put trace On decision execute decision execute PrintSolution decision Here are the execution results Decision SendMoreMoney Create RuleSolver JSR 331 Implementation based on Constrainer 5 4 light Rule Solver version 6 2 0 addConstrainedVariables Decision has been initialized with RuleSolver Initial Problem Variables D 9 E 0 9 SEND 1000 9999 MONEY 10000 99999 S 1 9 MORE 1000 9999 R 0 9 M 1 9 N 0 9 o 9 Y 0 9 Decision SendMoreMoney Add Intermediate Variables Decision SendMoreMoney Main Constraint Decision SendMoreMoney All Different After Assigning Data D 9 E 9 SEND 100 9999 39 OpenRules Inc Rule Solver User Manual MONEY 190000
70. ule Define Activities DefineActivities Define Oven as Recoverable DefineOvenAsResource Resource Define Oven Availability SetOvenCapacities Define Resource Requirement Constraints ResourceRequirementConstraints This decision table creates a schedule with a makespan 11 days DecisionTable DefineSchedule This table defines all activities DecisionTable DefineActivities Mm U lNn UWwW gt aBalrmo laA A 640 OpenRules Inc Rule Solver User Manual The resource Oven can be created using this table DT DefineOvenAsResource Oven 3 This problem does not have precedence constraints but it has resource requirement constraints that are presented in this table DT ResourceRequirementConstraints A Oven 2 B Oven 1 C Oven 1 D Oven 1 E Oven 2 The resource Oven has limits to its capacities as defined in the following table DT SetOvenCapacities Resource From To Capacity Oven 0 1 2 Oven 1 2 1 Oven 2 3 0 Oven 3 5 1 Oven 5 10 3 Oven 10 11 1 The model is ready to be executed by this Java launcher public static void main String args String fileName file rules Decision x1s System setProperty OPENRULES MODE Solve Decision decision new Decision DefineOvenSchedule fileName decision execute 65 O OpenRules Inc Rule Solver
71. ven 0 40 public void define throws Exception setStart 0 setEnd 11 Activity A s activity A 1 Activity B s activity B 4 Activity C s activity C 4 Activity D s activity D 2 Activity E s activity E 4 Resource oven s resource oven 3 oven setCapacityMax 0 2 oven setCapacityMax l 1 oven setCapacityMax 2 0 oven setCapacityMax 3 1 oven setCapacityMax 4 1 oven setCapacityMax 10 1 requires oven requires oven requires oven requires oven requires oven se Ao WS NRPRPEN se public void solve Solver solver s getSolver solver setSearchStrategy s strategyScheduleActivities solver addSearchStrategy s strategyAssignResources Solution solution solver findSolution if solution null s log No Solutions else s log Solution s logActivities s logResources solver logStats public static void main String args throws Exception Oven p new Oven p define p solve 670 OpenRules Inc Rule Solver User Manual Here the line Resource oven s resource oven 3 defines a new discrete resource oven with a maximum capacity of 3 batches The following lines set the maximal capacity for the oven for every day when the oven has a capacity less than 3 Note that the solving method along with the strategy strategySchedu
72. we had pure scheduling constraints between different construction activities Now let s assume that additionally all of the activities require a resource worker in order to be processed One worker is required to perform all the activities Because the worker can only perform one task at a time we cannot schedule two activities at the same time as we could in the basic example In addition to the decision tables that define activities and precedence constraints in the pure scheduling example we will need to add a resource Worker and the proper requirement constraints Here is the updated decision Decision ScheduleActivitiesWithWorker Define Schedule DefineSchedule Define Activities DefineActivities Define Precedence Constraints DefinePrecedenceConstraints Define Worker DefineWorker Define Resource Requirement Constraints ResourceRequirementConstraints We will add a worker using this table DecisionTable DefineWorker Worker Recoverable 1 The next table defines the worker requirement constraints DecisionTable ResourceRequirementConstraints masonry Worker 1 carpentry Worker 1 roofing Worker 1 690 OpenRules Inc Rule Solver User Manual plumbing Worker 1 ceiling Worker 1 windows Worker 1 fa ade Worker 1 garden Worker 1 painting Worker 1 movingIn Worker 1 Now the same Java launcher will produce

Download Pdf Manuals

image

Related Search

Related Contents

Manual del usuario - Instructions Manuals  業務委託仕様書.  Intel CHIPSET MB886 User's Manual      DigiMax 96k Owner`s Manual  Sima STP-1000T  Manuel d`utilisation  

Copyright © All rights reserved.
Failed to retrieve file