home Forums Media: Applications, Publications, Videos, Links and Examples Android function for get result…

Tagged: 

This topic contains 5 replies, has 2 voices, and was last updated by Chandana Chandana 1 year, 3 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2590
    Chandana
    Chandana
    Participant

    I am new from fuzzy logic..I need make function for get fuzzy output result.

    I have 4 inputs

    color_1(RBG or HEX color)
    color_2(RBG or HEX color)
    color_3(RBG or HEX color)

    I have existing defined out put for each result
    if output A if color is color_1 and color_3
    if output B if color is color_2 and color_3
    if output C if color is color_1 and color_3

    I need pass each input to fuzzy function and get results.

    public String fuzzyLogicEx(String color_1,String color_2,String color_3) {

    Engine engine = new Engine();
    engine.setName(“SnakeDetection”);
    engine.setDescription(“”);

    //how to set inputs???

    OutputVariable mSteer = new OutputVariable();
    mSteer.setName(“snake”);
    mSteer.setDescription(“”);
    mSteer.setEnabled(true);
    mSteer.setRange(0.000, 1.000);
    mSteer.setLockValueInRange(false);
    mSteer.setAggregation(new Maximum());
    mSteer.setDefuzzifier(new Centroid(100));
    mSteer.setDefaultValue(Double.NaN);
    mSteer.setLockPreviousValue(false);
    mSteer.addTerm(new Ramp(“cobra”,1));

    engine.addOutputVariable(mSteer);

    RuleBlock mamdani = new RuleBlock();
    mamdani.setName(“mamdani”);
    mamdani.setDescription(“”);
    mamdani.setEnabled(true);
    mamdani.setConjunction(null);
    mamdani.setDisjunction(null);
    mamdani.setImplication(new AlgebraicProduct());
    mamdani.setActivation(new General());
    mamdani.addRule(Rule.parse(“if color is color_1 and color_3”, engine));
    mamdani.addRule(Rule.parse(“if obstacle is right then mSteer is left”, engine));

    OutputVariable outputVariable = new OutputVariable();
    engine.process();
    System.out.println(“Answer is ” + outputVariable.getValue())

    return outputVariable.getValue();
    }

    #2591
    Chandana
    Chandana
    Participant

    how to set inputs which i passed and how to get output results?

    #2592
    Chandana
    Chandana
    Participant

    I was trying this also but error occurred

    public static String fuzzyLogicEx() throws IOException, URISyntaxException {
    String configurationFile = “C:\\Users\\chandana\\Documents\\NetBeansProjects\\TestFuzzy\\src\\testfuzzy\\ObstacleAvoidance.fll”;
    Engine engine = null;
    try {
    engine = new FllImporter().fromFile(new File(configurationFile));
    } catch (Exception ex) {
    FuzzyLite.logger().log(Level.SEVERE, ex.toString(), ex);
    }
    System.out.println(new JavaExporter().toString(engine)); //this will print the engine in Java code
    return null;
    }
    ################################
    #File: ObstacleAvoidance.fll
    Engine: ObstacleAvoidance
    InputVariable: obstacle
    enabled: true
    range: 0.000 1.000
    lock-range: false
    term: left Ramp 1.000 0.000
    term: right Ramp 0.000 1.000
    OutputVariable: mSteer
    enabled: true
    range: 0.000 1.000
    lock-range: false
    aggregation: Maximum
    defuzzifier: Centroid 100
    default: nan
    lock-previous: false
    term: left Ramp 1.000 0.000
    term: right Ramp 0.000 1.000
    RuleBlock: mamdani
    enabled: true
    conjunction: none
    disjunction: none
    implication: AlgebraicProduct
    activation: General
    rule: if obstacle is left then mSteer is right
    rule: if obstacle is right then mSteer is left

    ###########################################################

    run:
    2017-09-24 15:26:17 SEVERE testfuzzy.FuzzyFormFile fuzzyLogicEx : java.lang.RuntimeException: [import error] expected a colon at here:
    java.lang.RuntimeException: [import error] expected a colon at here:
    at com.fuzzylite.imex.FllImporter.fromString(FllImporter.java:109)
    at com.fuzzylite.imex.Importer.fromFile(Importer.java:70)
    at testfuzzy.FuzzyFormFile.fuzzyLogicEx(FuzzyFormFile.java:27)
    at testfuzzy.FuzzyFormFile.main(FuzzyFormFile.java:17)

    Exception in thread “main” java.lang.NullPointerException
    at com.fuzzylite.imex.JavaExporter.toString(JavaExporter.java:88)
    at testfuzzy.FuzzyFormFile.fuzzyLogicEx(FuzzyFormFile.java:31)
    at testfuzzy.FuzzyFormFile.main(FuzzyFormFile.java:17)
    Java Result: 1

    #2593
    Juan Rada-Vilela
    Juan Rada-Vilela
    Keymaster

    Hi,

    thanks for your post.

    The problem with your FLL is a bug having multiple # in a line.
    Can you please remove the lines with “######…”?

    #2594
    Juan Rada-Vilela
    Juan Rada-Vilela
    Keymaster

    … And I think the file “C:\\Users\\chandana\\Documents\\NetBeansProjects\\TestFuzzy\\src\\testfuzzy\\ObstacleAvoidance.fll”; is not accessible somehow, that would be the NullPointerException you found in the log.

    #2599
    Chandana
    Chandana
    Participant

    Thank you

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.