home Forums # Technical Support fuzzy job selection

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1869
    Unknown
    Member

    package com.example.mahamad.fuzzyapp;

    import android.content.Intent;
    import android.support.v7.app.ActionBarActivity;
    import android.os.Bundle;
    import android.text.TextUtils;
    import android.util.Log;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    import android.widget.Toast;
    import com.fuzzylite.Engine;
    import com.fuzzylite.FuzzyLite;
    import com.fuzzylite.Op;
    import com.fuzzylite.defuzzifier.Centroid;
    import com.fuzzylite.imex.FldExporter;
    import com.fuzzylite.norm.s.Maximum;
    import com.fuzzylite.norm.t.Minimum;
    import com.fuzzylite.rule.Rule;
    import com.fuzzylite.rule.RuleBlock;
    import com.fuzzylite.term.Triangle;
    import com.fuzzylite.variable.InputVariable;
    import com.fuzzylite.variable.OutputVariable;

    public class MainActivity extends ActionBarActivity {
    public static final String TAG = MainActivity.class.getSimpleName();
    TextView Rr;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Engine engine = new Engine();

    engine.setName(“simple-dimmer”);
    InputVariable interest = new InputVariable();
    interest.setEnabled(true);
    interest.setName(“Interest”);
    interest.setRange(0, 10);
    interest.addTerm(new Triangle(“LOW”, 0, 2.5, 5));
    interest.addTerm(new Triangle(“MEDIUM”, 2.5, 5, 7.5));
    interest.addTerm(new Triangle(“HIGH”, 5, 7.5, 10));

    engine.addInputVariable(interest);

    InputVariable drive = new InputVariable();
    drive.setName(“Drive”);
    drive.setEnabled(true);
    drive.setRange(0, 10);
    drive.addTerm(new Triangle(“LOW”, 0, 2.5, 5));
    drive.addTerm(new Triangle(“MEDIUM”, 2.5, 5, 7.5));
    drive.addTerm(new Triangle(“HIGH”, 5, 7.5, 10));

    engine.addInputVariable(drive);

    InputVariable salary = new InputVariable();
    salary.setName(“Salary”);
    salary.setEnabled(true);
    salary.setRange(0, 10000);
    salary.addTerm(new Triangle(“LOW”, 0, 2500, 5000));
    salary.addTerm(new Triangle(“MEDIUM”, 2500, 5000, 7500));
    salary.addTerm(new Triangle(“HIGH”, 5000, 7500, 10000));

    engine.addInputVariable(salary);

    OutputVariable jobE = new OutputVariable();
    jobE.setEnabled(true);
    jobE.fuzzyOutput().setAccumulation(new Maximum());
    jobE.setDefuzzifier(new Centroid(200));
    jobE.setLockValidOutput(false);
    jobE.setLockOutputRange(false);
    jobE.setName(“JobE”);
    jobE.setRange(0, 1);
    jobE.setDefaultValue(Double.NaN);
    jobE.addTerm(new Triangle(“LOW”, 0, 0.25, 0.5));
    jobE.addTerm(new Triangle(“MEDIUM”, 0.25, 0.5, 0.75));
    jobE.addTerm(new Triangle(“HIGH”, 0.5, 0.75, 1));
    engine.addOutputVariable(jobE);
    RuleBlock ruleBlock = new RuleBlock();
    ruleBlock.setEnabled(true);
    ruleBlock.setName(“”);
    ruleBlock.setConjunction(new Minimum());
    ruleBlock.setDisjunction(new Maximum());
    ruleBlock.setActivation(new Minimum());

    ruleBlock.addRule(Rule.parse(“if Interest is LOW and Drive is LOW and Salary is LOW then JobE is LOW”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is LOW and Drive is LOW and Salary is MEDIUM then JobE is LOW”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is LOW and Drive is LOW and Salary is HIGH then JobE is MEDIUM”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is LOW and Drive is MEDIUM and Salary is LOW then JobE is MEDIUM”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is LOW and Drive is MEDIUM and Salary is MEDIUM then JobE is MEDIUM”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is LOW and Drive is MEDIUM and Salary is HIGH then JobE is MEDIUM”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is LOW and Drive is HIGH and Salary is LOW then JobE is MEDIUM”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is LOW and Drive is HIGH and Salary is MEDIUM then JobE is MEDIUM”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is LOW and Drive is HIGH and Salary is HIGH then JobE is MEDIUM”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is MEDIUM and Drive is LOW and Salary is LOW then JobE is LOW”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is MEDIUM and Drive is LOW and Salary is MEDIUM then JobE is MEDIUM”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is MEDIUM and Drive is LOW and Salary is HIGH then JobE is MEDIUM”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is MEDIUM and Drive is MEDIUM and Salary is LOW then JobE is MEDIUM”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is MEDIUM and Drive is MEDIUM and Salary is MEDIUM then JobE is MEDIUM”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is MEDIUM and Drive is MEDIUM and Salary is HIGH then JobE is MEDIUM”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is MEDIUM and Drive is HIGH and Salary is LOW then JobE is MEDIUM”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is MEDIUM and Drive is HIGH and Salary is MEDIUM then JobE is MEDIUM”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is MEDIUM and Drive is HIGH and Salary is HIGH then JobE is HIGH”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is HIGH and Drive is LOW and Salary is LOW then JobE is MEDIUM”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is HIGH and Drive is LOW and Salary is MEDIUM then JobE is MEDIUM”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is HIGH and Drive is LOW and Salary is HIGH then JobE is MEDIUM”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is HIGH and Drive is MEDIUM and Salary is LOW then JobE is MEDIUM”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is HIGH and Drive is MEDIUM and Salary is MEDIUM then JobE is MEDIUM”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is HIGH and Drive is MEDIUM and Salary is HIGH then JobE is HIGH”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is HIGH and Drive is HIGH and Salary is LOW then JobE is MEDIUM”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is HIGH and Drive is HIGH and Salary is MEDIUM then JobE is HIGH”, engine));
    ruleBlock.addRule(Rule.parse(“if Interest is HIGH and Drive is HIGH and Salary is HIGH then JobE is HIGH”, engine));

    engine.addRuleBlock(ruleBlock);

    double Result;
    StringBuilder status = new StringBuilder();
    if (!engine.isReady(status))
    throw new RuntimeException(“Nao foi possivel gerar o arquivo. ”
    + “O seguintes erros foram encontrados:\n” + status.toString());

    engine.setInputValue(“Interest”,1);
    engine.setInputValue(“Drive”,1);
    engine.setInputValue(“Salary”,10000);
    engine.process();
    //double Result;
    //Result=jobE.defuzzify();
    Rr=(TextView)findViewById(R.id.F);
    String Res;
    // Res=Double.toString(Result);
    Rr.setText(String.valueOf( engine.getOutputVariable(“JobE”).defuzzify()));
    // engine.getOutputVariable(“PD”).defuzzify();

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
    return true;
    }

    return super.onOptionsItemSelected(item);
    }
    }
    this is my code the problem is :-
    for input values 1 for interest , 1 for drive & 10000 for salary same result with
    2,2,10000 & 3,3, 10000
    the result is 0.50000000002
    why??
    the other problem as example the values 10 for interest ,10 for drive & 10000 for salary get the result NAN & the same result with 0,0,0
    why??
    thanks in advance

    #1870

    Hi,

    please, export your engine to FLL using System.out.println(new FllExporter().toString(engine)), copy the FLL code and evaluate it in QtFuzzyLite. If your controller was correctly configured, and you are not obtaining the output you expect, please post the FLL code in this forum and I will try to help you.

    Cheers.

    #1871
    Unknown
    Member

    if i don’t have QtFuzzyLite ??

    #1872

    Well, download it from http://www.fuzzylite.com/downloads . You can either purchase a license of QtFuzzyLite 5, or use the free community version QtFuzzyLite 4.

    #1873
    Unknown
    Member

    InputVariable: Interest
    enabled: true
    range: 0.000 10.000
    term: LOW Triangle 0.000 2.500 5.000
    term: MEDIUM Triangle 2.500 5.000 7.500
    term: HIGH Triangle 5.000 7.500 10.100
    InputVariable: Drive
    enabled: true
    range: 0.000 10.000
    term: LOW Triangle 0.000 2.500 5.000
    term: MEDIUM Triangle 2.500 5.000 7.500
    term: HIGH Triangle 5.000 7.500 10.100
    InputVariable: Salary
    enabled: true
    range: 0.000 10000.000
    term: LOW Triangle 0.000 2500.000 5000.000
    term: MEDIUM Triangle 2500.000 5000.000 7500.000
    term: HIGH Triangle 5000.000 7500.000 10002.000
    OutputVariable: JobE
    enabled: true
    range: 0.000 1.000
    accumulation: Maximum
    defuzzifier: Centroid 200
    default: nan
    lock-valid: false
    lock-range: false
    term: LOW Triangle 0.000 0.250 0.500
    term: MEDIUM Triangle 0.250 0.500 0.750
    term: HIGH Triangle 0.500 0.750 1.000
    RuleBlock:
    enabled: true
    conjunction: Minimum
    disjunction: Maximum
    activation: Minimum
    rule: if Interest is LOW and Drive is LOW and Salary is LOW then JobE is LOW
    rule: if Interest is LOW and Drive is LOW and Salary is MEDIUM then JobE is LOW
    rule: if Interest is LOW and Drive is LOW and Salary is HIGH then JobE is MEDIUM
    rule: if Interest is LOW and Drive is MEDIUM and Salary is LOW then JobE is MEDIUM
    rule: if Interest is LOW and Drive is MEDIUM and Salary is MEDIUM then JobE is MEDIUM
    rule: if Interest is LOW and Drive is MEDIUM and Salary is HIGH then JobE is MEDIUM
    rule: if Interest is LOW and Drive is HIGH and Salary is LOW then JobE is MEDIUM
    rule: if Interest is LOW and Drive is HIGH and Salary is MEDIUM then JobE is MEDIUM
    rule: if Interest is LOW and Drive is HIGH and Salary is HIGH then JobE is MEDIUM
    rule: if Interest is MEDIUM and Drive is LOW and Salary is LOW then JobE is LOW
    rule: if Interest is MEDIUM and Drive is LOW and Salary is MEDIUM then JobE is MEDIUM
    rule: if Interest is MEDIUM and Drive is LOW and Salary is HIGH then JobE is MEDIUM
    rule: if Interest is MEDIUM and Drive is MEDIUM and Salary is LOW then JobE is MEDIUM
    rule: if Interest is MEDIUM and Drive is MEDIUM and Salary is MEDIUM then JobE is MEDIUM
    rule: if Interest is MEDIUM and Drive is MEDIUM and Salary is HIGH then JobE is MEDIUM
    rule: if Interest is MEDIUM and Drive is HIGH and Salary is LOW then JobE is MEDIUM
    rule: if Interest is MEDIUM and Drive is HIGH and Salary is MEDIUM then JobE is MEDIUM
    rule: if Interest is MEDIUM and Drive is HIGH and Salary is HIGH then JobE is HIGH
    rule: if Interest is HIGH and Drive is LOW and Salary is LOW then JobE is MEDIUM
    rule: if Interest is HIGH and Drive is LOW and Salary is MEDIUM then JobE is MEDIUM
    rule: if Interest is HIGH and Drive is LOW and Salary is HIGH then JobE is MEDIUM
    rule: if Interest is HIGH and Drive is MEDIUM and Salary is LOW then JobE is MEDIUM
    rule: if Interest is HIGH and Drive is MEDIUM and Salary is MEDIUM then JobE is MEDIUM
    rule: if Interest is HIGH and Drive is MEDIUM and Salary is HIGH then JobE is HIGH
    rule: if Interest is HIGH and Drive is HIGH and Salary is LOW then JobE is MEDIUM
    rule: if Interest is HIGH and Drive is HIGH and Salary is MEDIUM then JobE is HIGH
    rule: if Interest is HIGH and Drive is HIGH and Salary is HIGH then JobE is HIGH

    #1874

    Hi,

    please use QtFuzzyLite so you realise what are the outputs of your system. Play with the Engine in QtFuzzyLite and you will find out the outputs are correct, and that your question is more based on your intuition, which does not apply to the controller that you have designed.

    Cheers.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.