Package net.sourceforge.jFuzzyLogic.rule

Examples of net.sourceforge.jFuzzyLogic.rule.Rule


    ruleBlock.setName("No1");
    ruleBlock.setRuleAccumulationMethod(new RuleAccumulationMethodMax());
    ruleBlock.setRuleActivationMethod(new RuleActivationMethodMin());

    //       RULE 1 : IF service IS poor OR food is rancid THEN tip IS cheap;
    Rule rule1 = new Rule("Rule1", ruleBlock);
    rule1.addAntecedent(service, "poor", false);
    rule1.addAntecedent(food, "rancid", false);
    rule1.addConsequent(tip, "cheap", false);
    ruleBlock.add(rule1);

    //       RULE 2 : IF service IS good THEN tip IS average;
    Rule rule2 = new Rule("Rule2", ruleBlock);
    rule2.addAntecedent(service, "good", false);
    rule2.addConsequent(tip, "average", false);
    ruleBlock.add(rule2);

    //       RULE 3 : IF ((service IS good) OR (service IS excellent)) AND food IS delicious THEN tip is generous;
    Rule rule3 = new Rule("Rule3", ruleBlock);
    RuleTerm term1 = new RuleTerm(service, "good", false); // Create 'terms'
    RuleTerm term2 = new RuleTerm(service, "excellent", false);
    RuleTerm term3 = new RuleTerm(food, "delicious", false);

    RuleExpression antecedentOr = new RuleExpression(term1, term2, new RuleConnectionMethodOrMax()); // Combine terms using connection methods: OR, AND
    RuleExpression antecedentAnd = new RuleExpression(antecedentOr, term3, new RuleConnectionMethodAndMin());
    rule3.setAntecedents(antecedentAnd); // Set antecedent

    rule3.addConsequent(tip, "generous", false);
    ruleBlock.add(rule3);

    //    END_RULEBLOCK
    //
    //    END_FUNCTION_BLOCK
View Full Code Here


    v_out.add(t2);

    RuleBlock rules = new RuleBlock(fb);
    rules.setName("No1");

    Rule r = new Rule("Rule1", rules);

    r.addAntecedent(v, "lt1", false);
    r.addConsequent(v_out, "lt2", false);

    rules.add(r);

    HashMap<String, RuleBlock> ruleBlocksMap = new HashMap<String, RuleBlock>();
View Full Code Here

  void checkDeMorgan(FIS fis) {
    // De Morgan's laws test
    FunctionBlock fb = fis.getFunctionBlock(null);
    RuleBlock rb = fb.getRuleBlocks().values().iterator().next();
    List<Rule> rules = rb.getRules();
    Rule r1 = rules.get(0);
    Rule r2 = rules.get(1);
    Rule r3 = rules.get(2);
    Rule r4 = rules.get(3);

    r1.getDegreeOfSupport();

    // Set different values for 'food' and 'service'. Evaluate the system and show variables
    //    for( double service = 0.0, food = 1; service <= 10; service += 0.1 ) {
    for( double x1 = 0; x1 <= 1.0; x1 += 0.01 ) {
      for( double x2 = 0; x2 <= 1.0; x2 += 0.01 ) {
        // Evaluate system using these parameters
        fis.getVariable("x1").setValue(x1);
        fis.getVariable("x2").setValue(x2);
        fis.evaluate();

        // DeMorgan law: NOT(x1 IS small OR x2 IS small) == NOT(x1 IS small) AND NOT(x2 IS small)
        double diff = Math.abs(r1.getDegreeOfSupport() - r2.getDegreeOfSupport());
        if( diff > EPSILON ) throw new RuntimeException(String.format("x1: %2.2f\tx2:%2.2f\t=> r1: %2.2f\tr2: %2.2f", x1, x2, r1.getDegreeOfSupport(), r2.getDegreeOfSupport()));

        // DeMorgan law: NOT(x1 IS small OR x2 IS small) == NOT(x1 IS small) AND NOT(x2 IS small)
        diff = Math.abs(r3.getDegreeOfSupport() - r4.getDegreeOfSupport());
        if( diff > EPSILON ) throw new RuntimeException(String.format("x1: %2.6f\tx2:%2.6f\t=> r3: %2.6f\tr4: %2.6f", x1, x2, r3.getDegreeOfSupport(), r4.getDegreeOfSupport()));

      }
    }
  }
View Full Code Here

TOP

Related Classes of net.sourceforge.jFuzzyLogic.rule.Rule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.