Package net.sourceforge.jFuzzyLogic.rule

Examples of net.sourceforge.jFuzzyLogic.rule.RuleBlock


    //    RULEBLOCK No1
    //       ACCU : MAX;
    //       AND : MIN;
    //       ACT : MIN;
    RuleBlock ruleBlock = new RuleBlock(functionBlock);
    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
    HashMap<String, RuleBlock> ruleBlocksMap = new HashMap<String, RuleBlock>();
    ruleBlocksMap.put(ruleBlock.getName(), ruleBlock);
    functionBlock.setRuleBlocks(ruleBlocksMap);

    //---
    // Show generated FIS (FCL) and show animation
    //---
View Full Code Here


    // Load FIS (Fuzzy Inference System)
    //---
    FIS fis = FIS.load("fcl/qualify.fcl");
    FunctionBlock functionBlock = fis.getFunctionBlock(null);
    // functionBlock.chart();
    RuleBlock ruleBlock = functionBlock.getFuzzyRuleBlock(null);

    //---
    // Create a list of parameter to optimize
    //---
    ArrayList<Parameter> parameterList = new ArrayList<Parameter>();
    // Add variables.
    // Note: Fuzzy sets' parameters for these (scoring and credLimMul) variables will be optimized
    Parameter.parameterListAddVariable(parameterList, ruleBlock.getVariable("scoring"));
    Parameter.parameterListAddVariable(parameterList, ruleBlock.getVariable("credLimMul"));

    // Add every rule's weight
    for( Rule rule : ruleBlock.getRules() ) {
      Parameter.parameterListAddRule(parameterList, rule);
    }

    //---
    // Create an error function to be optimized (i.e. minimized)
View Full Code Here

    fb.setVariable("out", v_out);

    v_out.add(t1);
    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>();

    ruleBlocksMap.put(rules.getName(), rules);

    fb.setRuleBlocks(ruleBlocksMap);

    // Print, save and load
    System.out.println(fb.toString());
View Full Code Here

      else if( leaveName.equalsIgnoreCase("VAR_OUTPUT") ) fclTreeVariables(child);
      else if( leaveName.equalsIgnoreCase("FUZZIFY") ) fclTreeFuzzify(child);
      else if( leaveName.equalsIgnoreCase("DEFUZZIFY") ) fclTreeDefuzzify(child);
      else if( leaveName.equalsIgnoreCase("RULEBLOCK") ) {
        // Create and parse RuleBlock
        RuleBlock ruleBlock = new RuleBlock(this);
        String rbname = ruleBlock.fclTree(child);

        if( rbname.equals("") ) rbname = "RuleBlock_" + ruleBlockCount; // Create name if none is given
        ruleBlockCount++;

        // Add RuleBlock
View Full Code Here

    ArrayList<String> al = new ArrayList<String>(ruleBlocks.keySet());
    Collections.sort(al);
    StringBuffer ruleBlocksStr = new StringBuffer();
    for( Iterator<String> it = al.iterator(); it.hasNext(); ) {
      String ruleSetName = it.next();
      RuleBlock ruleBlock = getFuzzyRuleBlock(ruleSetName);

      // Convert ruleSet to string (using FLC?)
      ruleBlocksStr.append(ruleBlock.toStringFcl());
    }

    // Build the whole thing
    return "FUNCTION_BLOCK " + name + "\n\n" //
        + varsIn + "\n" //
View Full Code Here

   * @param fis
   */
  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);

View Full Code Here

TOP

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

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.