-2

log cat I need to use fuzzylite in my app. For example input is service with poor good and excellent levels. Output is tip with low,medium,high levels . Here is the code. I got " unfortunately fuzzy has stopped error" . I am new to fuzzylite . Help me solve this issue

public class MainActivity extends Activity {

    EditText inputEditText;
    TextView output;
    Double ser;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        inputEditText = (EditText) findViewById(R.id.service);

        output = (TextView) findViewById(R.id.textView1);

        ser = Double.parseDouble(inputEditText.getText().toString());
        fuzzy();
    }

    public void fuzzy(){

        Engine engine = new Engine();
        engine.setName("simple-dimmer");

        InputVariable service= new InputVariable();
        service.setName("service");
        service.setRange(0.000, 1.000);
        service.addTerm(new Triangle("poor", 0.000, 0.250, 0.500));
        service.addTerm(new Triangle("good", 0.250, 0.500, 0.750));
        service.addTerm(new Triangle("excellent", 0.500, 0.750, 1.000));
        engine.addInputVariable(service);

        OutputVariable tip = new OutputVariable();
        tip.setName("Power");
        tip.setRange(0.000, 1.000);
        tip.setDefaultValue(Double.NaN);
        tip.addTerm(new Triangle("LOW", 0.000, 0.250, 0.500));
        tip.addTerm(new Triangle("MEDIUM", 0.250, 0.500, 0.750));
        tip.addTerm(new Triangle("HIGH", 0.500, 0.750, 1.000));
        engine.addOutputVariable(tip);

        RuleBlock ruleBlock = new RuleBlock();
        ruleBlock.addRule(Rule.parse("if service is poor then tip is HIGH", engine));
        ruleBlock.addRule(Rule.parse("if service is good then tip is MEDIUM", engine));
        ruleBlock.addRule(Rule.parse("if service is excellent then tip is LOW", engine));
        engine.addRuleBlock(ruleBlock);

        engine.configure("", "", "Minimum", "Maximum", "Centroid");
        engine.setInputValue("service",ser);
        engine.process();
        output.setText(String.format("0.3f", engine.getOutputValue("Output")));
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
}
luna
  • 41
  • 1
  • 1
  • 5
  • You may want to read this post and then edit your question to to include the logcat. http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – OneCricketeer Mar 27 '16 at 18:00
  • thanks for your reply. i have added the log cat – luna Mar 27 '16 at 18:08

2 Answers2

0

If you check the log carefully, you will realise that your problem is the following line:

ser = Double.parseDouble(inputEditText.getText().toString());

where inputEditText.getText() returns an empty string, and therefore raises a FormatException.

-1
RuleBlock ruleBlock = new RuleBlock();
ruleBlock.addRule(Rule.parse("if service is poor then Power is HIGH", engine));
ruleBlock.addRule(Rule.parse("if service is good then Power is MEDIUM", engine));
ruleBlock.addRule(Rule.parse("if service is excellent then Power is LOW", engine));
engine.addRuleBlock(ruleBlock);


tip should changed to Power



output.setText(String.format("0.3f", engine.getOutputValue("Output")));
should changed to
output.setText(String.format("0.3f", engine.getOutputValue("Power")));
Vikrant Kashyap
  • 6,398
  • 3
  • 32
  • 52