rules, events and workflow
TRANSCRIPT
The SkyNet funding bill is passed.
The system goes online on August 4th, 1997.
Human decisions are removed from strategic defense.
SkyNet begins to learn at a geometric rate.
It becomes self-aware at 2:14am Eastern time, August 29th
In a panic, they try to pull the plug.
And, Skynet fights back
Mark ProctorProject Lead
Agenda
Community
History
Declarative Programming
Drools Expert
Drools Fustion
jBPM
Roadmap
Boot Camps
San Francisco 2009 (40+ attendees)Sponsored by Third Pillar
Sun, FAMC, OSDE, Kaseya, Fedex, TU Group, Intermountain Healthcare, Gap, Sony Pictures, Lockheed Martin, Kaiser, HP, Wells Fargo, US Navy Research, FOLIOfn, Boeing .....
San Diego 2010 (80+ attendess)Sponsored by US Navy
5 day event, with 2 days focus on the healthcare industry
OSDE, AT&T, SAIC, US Navy Research, Kaiser, Clinica, Intermountain Healthcare, GE Healthcare, VA, Boeing, Nationwide ....
Books
Introduction to Expert SystemsPeter Jackson
Expert Systems, Principles and ProgrammingJoseph C. Giarratano and Gary D. Riley
Oh And There are Drools Books Too
History
It All Started Here Birth of CDSS
Clinical Decision Support Systems
DendralBaobabMycinGuidonNeomycinTeiresiasPuffEmycinWMSaconCentaurWheezeGravidaClot
Oncocin
1970s
1980s
Because Not Everyone
Is As Smart As He Is
Business Rules Engines
OPS5ARTClipsJessDrools 2JRules
1980s
2010s
Drools 3
1990s
2000s
Drools 4Drools 5
Drools History
Drools 2Rete like XML Scripting language
Drools 3 Based on Clips functionality
Iterative improves to JRules syntax with Clips functionality
Drools 4More declarative
Basic functional programming feature with from
Basic Rule Flow
Basic BRMS
Drools 5Improved functional programming with 'accumulate'
More Advanced Rule Flow integration
Complex Event ProcessTemporal Comparators
Sliding Time Windows
Production ready BRMS (Guvnor)
Drools History
Drools 5.1Differential Diff (true modify)
Drools 5.2Freeform expressions between patterns
Multi-function accumulates
Prolog like derivation queries
Decision tables and rule templates (Guvnor)
Pure GWT (Guvnor)
Drools 5.3...
Declarative Programming
Integrated Systems
Semantic
OntologiesRulesEventProcessesWorkflowsRules Workflows
EventProcesses
Semantic
Ontologies
Integrated Systems
Drools
Grid
Drools
Planner
Drools
Semantics
Drools
Chance Business Logic integration System
Drools
Guvnor
Drools
Fusion
JBPM5(Drools Flow)
Drools
Expert
Rules and processes
loosely coupledtightly coupledspecificgenericDecisionServicesProcessRulesSCOPECOUPLING?
Business Logic Lifecycle
Declarative Programming
Production Rule Systems PRD (forward chaining)Reactive
when Alarm( status == alert )
then send( warning )
Logic Programming LP (backward chaining)Query
descendant( mary, jane)
Functional Programming FPMap,Fold, Filter
avg([12, 16, 4, 6])Returns single value 9.5
round([10.3, 4.7, 7.8] )Returns List [10, 5, 8]
Description LogicPerson Has Name and
LivesAt Address
Concepts Overview
Concepts Overview
Concepts Overview
Drools Expert
Classes
rule increase balance for AccountPeriod Credits when ap : AccountPeriod() acc : Account( $accountNo : accountNo ) CashFlow( type == CREDIT, accountNo == $accountNo, date >= ap.start && = ap.start and cf.date = ap.start && = ap.start && Everything is ok
Executing
Fire kitchenFire = new Fire( name2room.get( "kitchen" ) );Fire officeFire = new Fire( name2room.get( "office" ) );
FactHandle kitchenFireHandle = ksession.insert( kitchenFire );FactHandle officeFireHandle = ksession.insert( officeFire );
ksession.fireAllRules();
> Raise the alarm> Turn on the sprinkler for room kitchen> Turn on the sprinkler for room office
Executing
ksession.retract( kitchenFireHandle );ksession.retract( officeFireHandle );
ksession.fireAllRules()
> Turn off the sprinkler for room office> Turn off the sprinkler for room kitchen> Cancel the alarm> Everything is ok
rule "Status output when things are ok" when not Alarm() not Sprinkler( on == true ) then println( "Everything is ok" );end
not Bus( color = red )
Conditional Elements
exists Bus( color = red )
forall ( $bus : Bus( floors == 2 ) Bus( this == $bus, color == red ) )
forall ( $bus : Bus( color == red ) )
Accumulate CE
rule "accumulate"when $sum : Number( intValue > 100 ) from accumulate( Bus( color == "red", $t : takings ) sum( $t ) )then print "sum is + $sum;end
Accumulate CE
Patterns and CE's can be chained with 'from'
rule "collect"when $zipCode : ZipCode() $sum : Number( intValue > 100 ) from accumulate( Bus( color == "red", $t : takings ) from $hbn.getNamedQuery(Find Buses) .setParameters( [ zipCode : $zipCode ] ) .list(), sum( $t ) )then print "sum is + $sum;end
Timers
rule name timer ( cron: 0 0/15 * * * * )when Alarm( )then sendEmail( Alert Alert Alert!!! )
Field Name Mandatory? Allowed Values Allowed Special CharactersSeconds YES 0-59 , - * /Minutes YES 0-59 , - * /Hours YES 0-23 , - * /Day of month YES 1-31 , - * ? / L WMonth YES 1-12 or JAN-DEC , - * /Day of week YES 1-7 or SUN-SAT , - * ? / L #Year NO empty, 1970-2099 , - * /
Send alert every quarter of an hour
Calendars
rule "weekdays are high priority" calendars "weekday" timer (int:0 1h)when Alarm()then send( "priority high - we have an alarm );end
rule "weekend are low priority" calendars "weekend" timer (int:0 4h)when Alarm()then send( "priority low - we have an alarm );end
Execute now and after
1 hour durationExecute now and after
4 hour duration
Backward Chaining
query isContainedIn( String x, String y ) Location( x, y; ) or ( Location( z, y; ) and ?isContainedIn( x, z; ) )end
rule reactiveLook when Here( place : place) ?isContainedIn( place, "keys"; )then System.out.println( "We have found your keys" );end
Drools Fusion
Drools Fusion: Enables...
Event Detection:From an event cloud or set of streams, select all the meaningful events, and only them.
[Temporal] Event Correlation:Ability to correlate events and facts declaring both temporal and non-temporal constraints between them.
Ability to reason over event aggregation.
Event Sequencing:A ( B OR C ) D
Event Abstraction:Ability to compose complex events from atomic events AND reason over them
Drools Fusion: Features
Support to Event semantics:Usually immutable, but not enforced
Strong temporal relationships
Managed lifecycle
Point-in-time and Interval events
Time semanticsDiscrete
Temporal relationshipsAll 13 operators defined by James Allen (+ negations)
Event Driven Architecture (EDA)
Event Driven Architecture (EDA) is a software architecturepattern promoting the production, detection, consumption of,and reaction to events. An event can be defined as "asignificant change in state"[1]. For example, when aconsumer purchases a car, the car's state changes from "forsale" to "sold". A car dealer's system architecture may treatthis state change as an event to be produced, published,detected and consumed by various applications within thearchitecture.
CEP vs EDA vs SOA
CEP is component of EDA
EDA is **not** SOA 2.0
Complementary architectures
MetaphorIn our body:SOA is used to build our muscles and organs
EDA is used to build our sensory system
$c : Custumer( type == VIP )BuyOrderEvent( customer == $c ) from entry-point Home Broker Stream
Scalability
EntryPoint entryPoint = session.getEntryPoint( Home Broker Stream );entryPoint.insert( event ) ;
So lets allow multiple named entry points for those streamsSo now we can insert different streams concurrentlyPatterns can now optional specify their entry-point. When not specified uses the default entry-point
declare StockTick @role( event )end
declare StockTick @role( event ) @timestamp( timestampAttr )
companySymbol : String stockPrice : double timestampAttr : longend
Automatic Life-Cycle Management
Just use the declare statement to declare a type as an event and it will be retracted when it is no longer needed The declare statement can also specify an internal model, that external objects/xml/csv map on to. We support Smooks and JAXB
$c : Custumer( type == VIP )$oe : BuyOrderEvent( customer == $c ) from entry-point Home Broker Stream BuyAckEvent( relatedEvent == $oe.id, this after[1s, 10s] $oe ) from entry-point Stock Trader Stream
coincides
before
after
meets
metby
overlaps
overlappedby
during
includes
starts
startedby
finishes
finishedby
Operators
BackAckEvent must occur between 1s and 10s 'after' BuyOrderEventThe Full set of Operators are supported
Drools Fusion: Temporal Reasoning
Drools Fusion: Temporal Reasoning
$c : Custumer( type == VIP )$oe : BuyOrderEvent( customer == $c ) from entry-point Home Broker Stream not BuyAckEvent( relatedEvent == $oe.id, this after[1s, 10s] $oe ) from entry-point Stock Trader Stream
Operators
Existing Drools 'not' Conditional Elements can be used to detect non-occurrence of eventsBackAckEvent must occur between 1s and 10s 'after' BuyOrderEvent
Aggregations
$n : Number( intValue > 100 ) from accumulate( $s : StockTicker( symbol == RHAT ) over window:time( 5s ), average( $s.price ) )
Over 5 secondsAggregate ticker price for RHAT over last 5 secondsThe pattern 'Number' reasons 'from' the accumulate result
Aggregations
acc( $s : StockTicker( symbol == RHAT ) over window:time( 5s );
$min : min( $s.price ), $min : min( $s.price ), $avg : avg( $s.price );
$min > 10 && $max < 20 && $avg > 16 )
Over 5 secondsfunctionsAccumlate over dataGuard constraint
Aggregations
Rule Engines do not deal with aggregations
$n : Number( intValue > 100 ) from accumulate( $s : StockTicker( symbol == RHAT ) over window:time( 5s ), average( $s.price ) )
Over 5 secondsAggregate ticker price for RHAT over last 5 secondsThe pattern 'Number' reasons 'from' the accumulate result
CEP Applied at FedEx Custom Critical
Time specific deliveries for critical freight
Exclusive use non-stop door-to-door services
Blended Surface and Air services to minimize cost and transit time
Extra care in handling and specially equipped vehiclesTemperature Control, Secured Services, Hazardous Material, Constant Surveillance
* Presented by Adam Mollemkopf at ORF 2009
CEP Applied at FedEx Custom Critical
* Presented by Adam Mollemkopf at ORF 2009
CEP Applied at FedEx Custom Critical
* Presented by Adam Mollemkopf at ORF 2009
CEP Applied at FedEx Custom Critical
* Presented by Adam Mollemkopf at ORF 2009
CEP Applied at FedEx Custom Critical
* Presented by Adam Mollemkopf at ORF 2009
CEP Applied at FedEx Custom Critical
* Presented by Adam Mollemkopf at ORF 2009
CEP Applied at FedEx Custom Critical
* Presented by Adam Mollemkopf at ORF 2009
CEP Applied at FedEx Custom Critical
* Presented by Adam Mollemkopf at ORF 2009
At least 50% of Alerts can be reasoned automatically, promoting staff savings and improved Customer and Driver experiences.
Risk Avoidance via pro-active monitoringReduction in insurance claims and shipment service failures
Minimum 30% efficiency gains in shipment monitoring , saving at least 15% of Operations staff cost.
CEP Applied at FedEx Custom Critical
Some numbers (from early 2010):24 x 7 sessions, no downtime
Average of 500k+ facts/events concurrently in memoryBusiness hours: 1M+ facts/events concurrently
Response time for reasoning cycles:Average: 150 ms
Peak: 1.2 sec
Several hundred rules
TMS and Inference
rule "Issue Child Bus Pass"when $p : Person( age < 16 )then insert(new ChildBusPass( $p ) );endrule "Issue Adult Bus Pass"when $p : Person( age >= 16 )then insert(new AdultBusPass( $p ) );end
Couples the logicWhat happens when the Child stops being 16?
TMS and Inference
BadMonolithic
Leaky
Brittle integrity - manual maintenance
TMS and Inference
A rule logically inserts an object
When the rule is no longer true, the object is retracted.
when $p : Person( age < 16 )then logicalInsert( new IsChild( $p ) )endwhen $p : Person( age >= 16 )then logicalInsert( new IsAdult( $p ) )end
de-couples the logicMaintains the truth by
automatically retracting
TMS and Inference
rule "Issue Child Bus Pass"when $p : Person( ) IsChild( person == $p )then logicalInsert(new ChildBusPass( $p ) );endrule "Issue Adult Bus Pass"when $p : Person( age >= 16 ) IsAdult( person == $p )then logicalInsert(new AdultBusPass( $p ) );end
The truth maintenance cascades
TMS and Inference
rule "Issue Child Bus Pass"when $p : Person( ) not( ChildBusPass( person == $p ) )then requestChildBusPass( $p );end
The truth maintenance cascades
TMS and Inference
GoodDe-couple knowledge responsibilities
Encapsulate knowledge
Provide semantic abstractions for those encapsulation
Integrity robustness truth maintenance
Some decisions are complex
What insurance premiumshould I charge?
Some decisions are complex
Business considerationsApplicant's age
Applicant's experience
Sailing qualifications
Value of vessel
Type of cover
Some decisions are complex
Business considerationsApplicant's ageOnly insure people over 25 years of age
If less than 35 add 10% surcharge
If less than 45 add 5% surcharge
Some decisions are complex
Business considerationsApplicant's experienceIf sailing < 5 years then charge +10%
Sailing qualificationsNone charge +100%
Etc...
Enter the decision table
Extract of decision table
Decision Table
Decision Table
rule "Pricing bracket_10"
when Driver(age >= 18, age 1000 ) from accumulate( e:
ProcessStartedEvent(
processInstance.processId == "com.sample.order.OrderProcess" ) over
window:size(1h), count(e) )then System.err.println( "WARNING: Nb of
order processes in the last hour > 1000: " + nbProcesses
);end
Rules and Process Together
Exceptional Control Flow
90%
5%3%2%
Exceptional Control Flow
90%Rule1When...Then...Rule2When...Then...Rule3When...Then...5%3%2%
Example: Clinical DSS
Interception
Buy Order AcknowledgementBuy Order RequestProcess PaymentConfirmation
Terminate
When StockMark status == crashThen Terminate Buy Request Process Start System Shutdown Process
Stock Buy Order Request
Interception and Redirection
Get DestinationGet DatesGet OriginProcess PaymentConfirmation
Terminate
When Origin != USA and Destination == USAThen Suspend Flight Booking Process Start ESTA Process OnSuccess Resume Flight Booking OnFailure Terminate Flight Booking
Simple Flight Booking Process
Drools flow in Oryx
Drools flow in Eclipse
Questions?
Questions?
Dave Bowman: All right, HAL; I'll go in through the emergency airlock.
HAL: Without your space helmet, Dave, you're going to find that rather difficult.
Dave Bowman: HAL, I won't argue with you anymore! Open the doors!
HAL: Dave, this conversation can serve no purpose anymore. Goodbye.
Joshua: Greetings, Professor Falken.Stephen Falken: Hello, Joshua.Joshua: A strange game. The only winning move is not to play. How about a nice game of chess?
Click to edit the title text format
Click to edit the outline text format
Click to edit the title text format
Click to edit the outline text formatSecond Outline LevelThird Outline LevelFourth Outline LevelFifth Outline LevelSixth Outline LevelSeventh Outline LevelEighth Outline LevelNinth Outline Level
This is the title
Second line of the title
Click to edit the outline text formatSecond Outline LevelThird Outline LevelFourth Outline LevelFifth Outline LevelSixth Outline LevelSeventh Outline LevelEighth Outline LevelNinth Outline Level
Click to edit the title text format
Click to edit the text format
Click to edit the title text format
Click to edit the text format
CashFlow
dateamounttypeaccountNo
12-Jan-07100CREDIT1
2-Feb-07200DEBIT1
18-May-0750CREDIT1
9-Mar-0775CREDIT1
???Page ??? (???)04/05/2011, 12:38:29Page / CashFlow
dateamounttype
12-Jan-07100CREDIT
9-Mar-0775CREDIT
???Page ??? (???)04/05/2011, 12:38:29Page / CashFlow
dateamounttype
2-Feb-07200DEBIT
???Page ??? (???)04/05/2011, 12:38:29Page / AccountingPeriod
startend
01-Jan-0731-Mar-07
???Page ??? (???)04/05/2011, 12:38:30Page / Account
accountNobalance
10
???Page ??? (???)04/05/2011, 12:38:30Page / Account
accountNobalance
1-25
???Page ??? (???)04/05/2011, 12:38:30Page /