Package net.sourceforge.jFuzzyLogic.rule

Examples of net.sourceforge.jFuzzyLogic.rule.Variable


    //    VAR_INPUT             
    //       service : REAL;
    //       food : REAL
    //    END_VAR

    Variable service = new Variable("service");
    Variable food = new Variable("food");
    functionBlock.setVariable(service.getName(), service);
    functionBlock.setVariable(food.getName(), food);

    //    VAR_OUTPUT
    //       tip : REAL;
    //    END_VAR

    Variable tip = new Variable("tip");
    functionBlock.setVariable(tip.getName(), tip);

    //    FUZZIFY service
    //       TERM poor := (0, 1) (4, 0) ;
    //       TERM good := (1, 0) (4,1) (6,1) (9,0);
    //       TERM excellent := (6, 0) (9, 1);
    //    END_FUZZIFY

    Value poorX[] = { new Value(0), new Value(4) };
    Value poorY[] = { new Value(1), new Value(0) };
    MembershipFunction poor = new MembershipFunctionPieceWiseLinear(poorX, poorY);

    MembershipFunction good = new MembershipFunctionTrapetzoidal(new Value(1), new Value(4), new Value(6), new Value(9));

    Value exX[] = { new Value(6), new Value(9), new Value(10) };
    Value exY[] = { new Value(0), new Value(1), new Value(1) };
    MembershipFunction excellent = new MembershipFunctionPieceWiseLinear(exX, exY);

    LinguisticTerm ltPoor = new LinguisticTerm("poor", poor);
    LinguisticTerm ltGood = new LinguisticTerm("good", good);
    LinguisticTerm ltExcellent = new LinguisticTerm("excellent", excellent);

    service.add(ltPoor);
    service.add(ltGood);
    service.add(ltExcellent);

    //    FUZZIFY food
    //       TERM rancid := (0, 1) (1, 1) (3,0) ;
    //       TERM delicious := (7,0) (9,1) (10,1);
    //    END_FUZZIFY

    Value ranX[] = { new Value(0), new Value(1), new Value(3) };
    Value ranY[] = { new Value(1), new Value(1), new Value(0) };
    MembershipFunction rancid = new MembershipFunctionPieceWiseLinear(ranX, ranY);

    Value delX[] = { new Value(7), new Value(9), new Value(10) };
    Value delY[] = { new Value(0), new Value(1), new Value(1) };
    MembershipFunction delicious = new MembershipFunctionPieceWiseLinear(delX, delY);

    LinguisticTerm ltRancid = new LinguisticTerm("rancid", rancid);
    LinguisticTerm ltDelicious = new LinguisticTerm("delicious", delicious);

    food.add(ltRancid);
    food.add(ltDelicious);

    //    DEFUZZIFY tip
    //       TERM cheap := (0,0) (5,1) (10,0);
    //       TERM average := (10,0) (15,1) (20,0);
    //       TERM generous := (20,0) (25,1) (30,0);
    //       METHOD : COG;
    //       DEFAULT := 0;
    //    END_DEFUZZIFY

    MembershipFunction cheap = new MembershipFunctionTriangular(new Value(0), new Value(5), new Value(10));
    MembershipFunction average = new MembershipFunctionTriangular(new Value(10), new Value(15), new Value(20));
    MembershipFunction generous = new MembershipFunctionTriangular(new Value(20), new Value(25), new Value(30));

    LinguisticTerm ltCheap = new LinguisticTerm("cheap", cheap);
    LinguisticTerm ltAverage = new LinguisticTerm("average", average);
    LinguisticTerm ltGenerous = new LinguisticTerm("generous", generous);

    tip.add(ltCheap);
    tip.add(ltAverage);
    tip.add(ltGenerous);

    tip.setDefuzzifier(new DefuzzifierCenterOfGravity(tip));

    //    RULEBLOCK No1
    //       ACCU : MAX;
    //       AND : MIN;
    //       ACT : MIN;
View Full Code Here


    for( int i = 0; i < terms.length; i++ ) {
      if( terms[i] == null ) // Null function => Nothing to do
      values[i] = Double.NaN;
      else if( terms[i] instanceof Variable ) {
        // Variable's value
        Variable var = ((Variable) terms[i]);
        if( var.isOutputVarable() ) throw new RuntimeException("Can't use an output variable '" + var.getName() + "' for a function (It may create a race condition)");
        values[i] = var.getValue();
      } else if( terms[i] instanceof Value ) {
        Value term = (Value) terms[i];
        values[i] = term.getValue();
      } else if( terms[i] instanceof MffFunction ) {
        // Function's value
View Full Code Here

          for( Rule r : ruleBlock.getRules() )
            System.out.println(r);

          // Show variable
          Variable var = ruleBlock.getVariable("credLimMul");
          JFreeChart chart = var.chart(false); // Code adapted by: Carmelo (cswi)
          DialogGraph.execute(chart);
        }

        // Calculate error (mean square)
        double desiredCredLim = credLimXL[scoreInd][incomeInd] / 100;
View Full Code Here

  public static void main(String args[]) {
    FIS fis = new FIS();

    FunctionBlock fb = new FunctionBlock(fis);

    Variable v = new Variable("a", 0.0, 20.0);
    MembershipFunction triangular = new MembershipFunctionTriangular(new Value(0.0000343232), new Value(10.0), new Value(13.0));

    LinguisticTerm t1 = new LinguisticTerm("lt1", triangular);
    LinguisticTerm t2 = new LinguisticTerm("lt2", triangular);

    v.add(t1);
    v.add(t2);

    Variable v_out = new Variable("out", 0.0, 20.0);
    MembershipFunction triangularOut = new MembershipFunctionTriangular(new Value(2.0), new Value(10.0), new Value(13.0));
    v_out.setDefaultValue(2.0);
    v_out.setDefuzzifier(new DefuzzifierCenterOfGravity(v_out));

    fb.setVariable("a", v);
    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);
View Full Code Here

    Tree child = tree.getChild(0);
    String varName = child.getText();

    // Get variable (or create a new one)
    Variable variable = getVariable(varName);
    if( variable == null ) {
      variable = new Variable(varName);
      setVariable(varName, variable);
      Gpr.debug("Variable '" + varName + "' does not exist => Creating it");
    }

    //---
    // Explore each sibling in this level
    //---
    for( int childNum = 1; childNum < tree.getChildCount(); childNum++ ) {
      child = tree.getChild(childNum);
      String leaveName = child.getText();
      if( debug ) Gpr.debug("\t\tChild: " + child.toStringTree());

      if( leaveName.equalsIgnoreCase("TERM") ) {
        // Linguistic term
        LinguisticTerm linguisticTerm = fclTreeFuzzifyTerm(child, variable);
        variable.add(linguisticTerm);
      } else if( leaveName.equalsIgnoreCase("ACCU") ) // Accumulation method
      throw new RuntimeException("Accumulation method (ACCU) must be defined at RULE_BLOCK");
      // ruleAccumulationMethodType = child.getChild(0).getText();
      else if( leaveName.equalsIgnoreCase("METHOD") ) // Defuzzification method
      defuzzificationMethodType = child.getChild(0).getText();
      else if( leaveName.equalsIgnoreCase("DEFAULT") ) {
        // Default value
        String defaultValueStr = child.getChild(0).getText();
        if( defaultValueStr.equalsIgnoreCase("NC") ) variable.setDefaultValue(Double.NaN); // Set it to "No Change"?
        else variable.setDefaultValue(Gpr.parseDouble(child.getChild(0))); // Set value
      } else if( leaveName.equalsIgnoreCase("RANGE") ) {
        // Range values (universe min / max)
        double universeMin = Gpr.parseDouble(child.getChild(0));
        double universeMax = Gpr.parseDouble(child.getChild(1));
        if( universeMax <= universeMin ) throw new RuntimeException("Range's min is grater than range's max! RANGE := ( " + universeMin + " .. " + universeMax + " );");
        variable.setUniverseMax(universeMax);
        variable.setUniverseMin(universeMin);
      } else throw new RuntimeException("Unknown/Unimplemented item '" + leaveName + "'");
    }

    // Defuzzification method
    Defuzzifier defuzzifier = createDefuzzifier(defuzzificationMethodType, variable);
    variable.setDefuzzifier(defuzzifier);

    return variable;
  }
View Full Code Here

    if( debug ) Gpr.debug("Tree: " + tree.toStringTree());
    Tree child = tree.getChild(0);
    String varName = child.getText();

    // Get variable (or create a new one)
    Variable variable = getVariable(varName);
    if( variable == null ) {
      variable = new Variable(varName);
      setVariable(varName, variable);
      Gpr.debug("Variable '" + varName + "' does not exist => Creating it");
    }

    // Explore each sibling in this level
    for( int childNum = 1; childNum < tree.getChildCount(); childNum++ ) {
      child = tree.getChild(childNum);
      if( debug ) Gpr.debug("\t\tChild: " + child.toStringTree());
      String leaveName = child.getText();

      if( leaveName.equalsIgnoreCase("TERM") ) {
        LinguisticTerm linguisticTerm = fclTreeFuzzifyTerm(child, variable);
        variable.add(linguisticTerm);
      } else throw new RuntimeException("Unknown/Unimplemented item '" + leaveName + "'");
    }

    return variable;
  }
View Full Code Here

    if( debug ) Gpr.debug("Tree: " + tree.toStringTree());
    for( int childNum = 0; childNum < tree.getChildCount(); childNum++ ) {
      Tree child = tree.getChild(childNum);
      if( debug ) Gpr.debug("\tChild: " + child.toStringTree());
      String varName = child.getText();
      Variable variable = new Variable(varName);
      if( debug ) Gpr.debug("\tAdding variable: " + varName);

      if( varibleExists(variable.getName()) ) Gpr.debug("Warning: Variable '" + variable.getName() + "' duplicated");
      else setVariable(varName, variable); // OK? => Add variable
    }
  }
View Full Code Here

   * @param variableName : Variable's name
   * @param value : variable's value to be setted
   * @return this
   */
  public void setVariable(String variableName, double value) {
    Variable var = getVariable(variableName);
    if( var == null ) throw new RuntimeException("No such variable: '" + variableName + "'");
    var.setValue(value);
  }
View Full Code Here

TOP

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

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.