To jest stara wersja strony!


Opis

Szymon Frenkel sfrenkel@student.bez-spamu.agh.edu.pl

Analyze how to design Drools rules with XTT2

  • Pokrewny projekt: Drools_X - Grzegorz Stopa

Spotkania

20090423

  • zaimpl. przykłady w drools, potem hqed

20090402

  • kategoryzacja przykładów, opis, ile reguł, atr, etc, czego dotyczą

20090326

* …

20090319

20090312

20090225

Zapoznanie z działaniem Drools.

Projekt

1. Przykłady systemów ekspertowych w Drools

Zastosowanie w zarządzaniu produkacją

www.ibm.com/developerworks/java/library/j-drools

  • Opis

The problem to solve

  • A company named XYZ builds two types of computer machines: Type1 and Type2. A machine's type is defined by its architecture.
  • An XYZ computer can serve multiple functions. Four functions are currently defined: DDNS Server, DNS Server, Gateway, and Router.
  • XYZ performs several tests on each machine before it is shipped out.
  • The tests performed on each machine depend on each machine's type and functions. Currently, five tests are defined: Test1, Test2, Test3, Test4, and Test5.
  • When tests are assigned to a computer, a tests due date is also assigned to the machine. Tests assigned to the computer should be conducted no later than this due date. The due date's value depends on the tests that were assigned to the machine.
  • XYZ has automated much of the process for executing the tests using an internally developed software application that can determine a machine's type and functions. Then, based on these properties, the application determines which tests to execute and their due date.
  • Currently, the logic that assigns the tests and tests due date to a computer is part of this application's compiled code. The component that contains this logic is written in the Java language.
  • The logic for assigning tests and due dates is changed more than once a month. The developers must go through a tedious process every time they need to implement it in the Java code.


  • Własności
  • 10 reguł
  • 5 jedno-atrybutowych
  • 5 dwu-atrybutowych


  • kod źródłowy
rule "Tests for type1 machine"
 
salience 100
when
	machine : Machine( type == "Type1" )
then	
	Test test1 = testDAO.findByKey(Test.TEST1);
	Test test2 = testDAO.findByKey(Test.TEST2);
	Test test5 = testDAO.findByKey(Test.TEST5);
	machine.getTests().add(test1);
	machine.getTests().add(test2);
	machine.getTests().add(test5);
	insert( test1 );
	insert( test2 );
	insert( test5 );
end
 
rule "Tests for type2, DNS server machine"
salience 100
when
	machine : Machine( type == "Type2", functions contains "DNS Server")
then	
	Test test5 = testDAO.findByKey(Test.TEST5);
	Test test4 = testDAO.findByKey(Test.TEST4);
	machine.getTests().add(test5);
	machine.getTests().add(test4);
	insert( test4 );
	insert( test5 );		
end
 
rule "Tests for type2, DDNS server machine"
salience 100
when
	machine : Machine( type == "Type2", functions contains "DDNS Server")
then	
	Test test2 = testDAO.findByKey(Test.TEST2);
	Test test3 = testDAO.findByKey(Test.TEST3);
	machine.getTests().add(test2);
	machine.getTests().add(test3);
	insert( test2 );
	insert( test3 );		
end
 
rule "Tests for type2, Gateway machine"
salience 100
when
	machine : Machine( type == "Type2", functions contains "Gateway")
then		
	Test test3 = testDAO.findByKey(Test.TEST3);
	Test test4 = testDAO.findByKey(Test.TEST4);
	machine.getTests().add(test3);
	machine.getTests().add(test4);
	insert( test3 );
	insert( test4 );		
end
 
rule "Tests for type2, Router machine"
salience 100
when
	machine : Machine( type == "Type2", functions contains "Router")
then	
	Test test3 = testDAO.findByKey(Test.TEST3);
	Test test1 = testDAO.findByKey(Test.TEST1);
	machine.getTests().add(test3);
	machine.getTests().add(test1);
	insert( test1 );
	insert( test3 );					
end
 
rule "Due date for Test 5"
salience 50
when
	machine : Machine()
	Test( id == Test.TEST5 )
then	
	setTestsDueTime(machine, 14);				
end
 
rule "Due date for Test 4"
salience 40
when
	machine : Machine()
	Test( id == Test.TEST4 )
then	
	setTestsDueTime(machine, 12);				
end
 
rule "Due date for Test 3"
salience 30
when
	machine : Machine()
	Test( id == Test.TEST3 )
then	
	setTestsDueTime(machine, 10);				
end
 
rule "Due date for Test 2"
salience 20
when
	machine : Machine()
	Test( id == Test.TEST2 )
then	
	setTestsDueTime(machine, 7);				
end
 
Rule "Due date for Test 1"
salience 10
when
	machine : Machine()
	Test( id == Test.TEST1 )
then	
	setTestsDueTime(machine, 3);				
end

Przykład systemu dla firmy

www.onjava.com/pub/a/onjava/2007/01/17/building-enterprise-services-with-drools-rule-engine.html?page=4

  • Opis

Reguły opisują podejmowanie decyzji przyznania pożyczki na podstawie określonych kryteriów.

  • Własności
  • 9 reguł
  • 1 jedno-atrybutowa
  • 6 dwu-atrybutowych
  • 2 trój-atrybutowe


  • kod źródłowy
    rule "Age verification"
        when
            Borrower(age < 18)
            $loanApp : LoanApplication()
        then
            $loanApp.addFeedbackMessage(FeedbackMessages.MIN_AGE);
    end
 
    rule "Credit score"
 
        when
            Borrower(creditScore <= 600)
            $loanApp : LoanApplication()
        then
            $loanApp.addFeedbackMessage(FeedbackMessages.MIN_CREDIT_SCORE);
    end
 
    rule "Loan Amount limits"
        when
            $loanApp : (LoanApplication(loanAmount <= 100000.0) or
            LoanApplication(loanAmount >= 400000.0))
        then
            $loanApp.addFeedbackMessage(FeedbackMessages.LOAN_AMOUNT_LIMITS);
    end
 
    rule "Maximum Loan-to-value ratio"
        when
            $loanApp : LoanApplication(loanToValueRatio > 80.0)
        then
            $loanApp.addFeedbackMessage(FeedbackMessages.LTV);
    end
 
    rule "Income multiples"
        salience -3
        when
            Borrower( $grossIncome : grossIncome )
            Property( value > (new Double($grossIncome.doubleValue()*3)))
            $loanApp : LoanApplication()
        then
            $loanApp.setAffordabilityFlag(Flag.NOT_AFFORDABLE);
    end
 
    rule "Affordability Model"
        salience -4
        when
            Borrower( $affordableLoanAmount : affordableLoanAmount )
            Property( value > (new Double($affordableLoanAmount.doubleValue())))
            $loanApp : LoanApplication()
        then
            $loanApp.setAffordabilityFlag(Flag.NOT_AFFORDABLE);
    end
 
    rule "Property type"
        when
            Property(purpose != Flag.OWNER_OCCUPIED)
            $loanApp : LoanApplication()
        then
            $loanApp.addFeedbackMessage(FeedbackMessages.PROP_TYPE);
    end
 
    rule "Property age"
        when
            Property(yearBuilt < 1965)
            $loanApp : LoanApplication()
        then
            $loanApp.addFeedbackMessage(FeedbackMessages.PROP_YEAR_BUILT);
    end
    rule "Underwriting decision"
 
        when
            $loanApp : (LoanApplication(affordabilityFlag == Flag.NOT_AFFORDABLE) or
            LoanApplication( feedbackMsgSize > 0))
        then
            $loanApp.setStatus(Flag.FAILED);
    end

Przykład reguł w XMLu

www.onjava.com/pub/a/onjava/2005/08/03/drools.html?page=5

  • Opis

Przykład zapisania reguł Drools w XMLu

  • Własności
  • 1 reguła dwu-atrybutowa


  • Kod źródłowy
<?xml version="1.0"?>
<rule-set>
  <!-- Ensure stock price is not too high-->      
  <rule name="Stock Price Low Enough">
    <!-- Params to pass to business rule -->
    <parameter identifier="stockOffer">
      <class>StockOffer</class>
    </parameter>
    <!-- Conditions or 'Left Hand Side' 
        (LHS) that must be met for 
         business rule to fire -->
    <!-- note markup -->
    <java:condition>
      stockOffer.getRecommendPurchase() == null
    </java:condition>
    <java:condition>
      stockOffer.getStockPrice() < 100
    </java:condition>
    <!-- What happens when the business 
                      rule is activated -->
    <java:consequence>
        stockOffer.setRecommendPurchase(
                              StockOffer.YES);  
          printStock(stockOffer);
    </java:consequence>
  </rule>
</rule-set>

Bilety

http://downloads.jboss.com/drools/docs/4.0.7.19894.GA/html/ch10.html#d0e6737

  • Opis

Prosty systemie przydzielania biletów klientom, wykorzystuje zależności czasowe.

  • Własności
  • 5 reguł dwu-atrybutowych


  • Kod źródłowy
rule "New Ticket"
	salience 10
	when
		customer : Customer( )
		ticket : Ticket( customer == customer, status == "New" )	
	then
		System.out.println( "New : " + ticket );		
end
 
rule "Silver Priority"
	duration 3000
	when
		customer : Customer( subscription == "Silver" )	
		ticket : Ticket( customer == customer, status == "New" )	
	then
		modify( ticket ) {setStatus( "Escalate" )} 		
end
 
rule "Gold Priority"
	duration 1000
	when
		customer : Customer( subscription == "Gold" )	
		ticket : Ticket( customer == customer, status == "New" )	
	then
		modify( ticket ) {setStatus( "Escalate" )}	
end
 
rule "Platinum Priority"
	when
		customer : Customer( subscription == "Platinum" )	
		ticket : Ticket( customer == customer, status == "New" )	
	then
		ticket.setStatus( "Escalate" );
		modify ( ticket ) {setStatus( "Escalate" )}
end
 
rule "Escalate"
	when
		customer : Customer( )	
		ticket : Ticket( customer == customer, status == "Escalate" )	
	then
		sendEscalationEmail( customer, ticket );
end
 
rule "Done"
	when
		customer : Customer( )	
		ticket : Ticket( customer == customer, status == "Done" )	
	then
		System.out.println( "Done : " + ticket );		
end

2. Testowanie systemów Drools

Wstęp

System 1

System 2

System 3

Sprawozdanie

Prezentacja

Materiały

pl/miw/2009/miw09_xtt_drools.1243323624.txt.gz · ostatnio zmienione: 2019/06/27 15:58 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0