● 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 Proctor Project Lead
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
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 Proctor
Project Lead
2
Business Logic integration Platform
DroolsGuvnor
DroolsFusion
DroolsFlow
DroolsExpert
Introduction
Drools Expert
Learn by Example
5
D a t e d a t ed o u b l e a m o u n ti n t t y p el o n g a c c o u n t N o
C a s h f l o w
l o n g a c c o u n t N od o u b l e b a l a n c e
A c c o u n t
D a t e s t a r tD a t e e n d
A c c o u n t i n g P e r i o d
Classes
6
AccountaccountNo balance
1 0
increase balance for AccountPeriod Credits
select * from Account acc, Cashflow cf, AccountPeriod apwhere acc.accountNo == cf.accountNo and cf.type == CREDIT cf.date >= ap.start and cf.date <= ap.end
decrease balance for AccountPeriod Debits
select * from Account acc, Cashflow cf, AccountPeriod apwhere acc.accountNo == cf.accountNo and cf.type == DEBIT cf.date >= ap.start and cf.date <= ap.end
A c c o u n t A c c o u n t i n g P e r i o d C a s h f l o w
v i e w 1 v i e w 2
m a i n v i e w
T a b l e s
V i e w s
V i e w
A c c o u n t A c c o u n t i n g P e r i o d C a s h f l o w
r u l e 1 r u l e 2
a g e n d a
O b j e c t T y p e s
R u l e s
a g e n d a
Production Rule SystemApproximated by SQL and Views
17
rule “Print blance for AccountPeriod” salience -50 when ap : AccountPeriod() acc : Account( ) then System.out.println( acc.accountNo + “ : “ acc.balance ); end
rule “increase balance for AccountPeriod Credits” ruleflow-group “calculation” when ap : AccountPeriod() acc : Account( $accountNo : accountNo ) CashFlow( type == CREDIT, accountNo == $accountNo, date >= ap.start && <= ap.end, $ammount : ammount ) then acc.balance += $amount; end
rule “Print blance for AccountPeriod” ruleflow-group “report” when ap : AccountPeriod() acc : Account( ) then System.out.println( acc.accountNo + “ : “ acc.balance ); end
ruleflow-group
RuleFlow
19
Two Phase System
Working Memory Action
retract
modifyinsert
Agenda Evaluation
Select Rule to Fire
exit
No RuleFound
Fire Rule
Determine possible rules to
fire
RuleFound
Conditional Elements
21
not Bus( color = “red” )
From CE for Expressions
exists Bus( color = “red” )
forall ( $bus : Bus( floors == 2 )
Bus( this == $bus, color == “red” ) )
forall ( $bus : Bus( color == “red” ) )
From CEfor Expressions
23
From CE for Expressions
rule “Find all the pets for a given owner”when $owner : Person( name == “mark” ) Pet( name == “rover” ) from $owner.pets
Using 'from' to reason over the nested list
24
'from' can work on any expression, not just a nested field on a bound variable.
From CE for Expressions
rule “Find People for given zip code”when $zipCode : ZipCode() Person( ) from $hbn.getNamedQuery(“Find People”) .setParameters( [ “zipCode” : $zipCode ] ) .list()
Hibernate session
Collect CE
26
Collect CE
rule "accumulate"
when
$list : List( intValue > 100 )
from collect( Bus( color == "red" ) )
then
print "red buses “ + $list;
end
Accumulate CE
28
Accumulate CE
rule "accumulate"
when
$sum : Number( intValue > 100 )
from accumulate( Bus( color == "red", $t : takings )
init( sum = 0 ),
action( sum += $t ),
result( sum ) )
then
print "sum is “ + $sum;
end
29
Accumulate CE
rule "accumulate"
when
$sum : Number( intValue > 100 )
from accumulate( Bus( color == "red", $t : takings ) sum( $t ) )
then
print "sum is “ + $sum;
end
30
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
TimersCalendars
32
Timers
rule “name” timer 1m30swhen $l : Light( status == “on” )then SendEmail( “turn the light off” )
rule “name” timer (int: 0 1m30)when $l : Light( status == “on” )then SendEmail( “turn the light off” )
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 ) )
end
when
$p : Person( age >= 16 )
then
logicalInsert( new IsAdult( $p ) )
end
de-couples the logic
Maintains the truth by automatically retracting
39
TMS and Inference
rule "Issue Child Bus Pass"
when
$p : Person( )
IsChild( person =$p )
then
logicalInsert(new ChildBusPass( $p ) );
end
rule "Issue Adult Bus Pass"
when
$p : Person( age >= 16 )
IsAdult( person =$p )
then
logicalInsert(new AdultBusPass( $p ) );
end
The truth maintenance cascades
40
TMS and Inference
rule "Issue Child Bus Pass"
when
$p : Person( )
not( ChildBusPass( person == $p ) )
then
requestChildBusPass( $p );
End The truth maintenance cascades
41
TMS and Inference
Good● De-couple knowledge responsibilities● Encapsulate knowledge● Provide semantic abstractions for those encapsulation● Integrity robustness – truth maintenance