home › Forums › # Technical Support › help with errors and advice
- This topic has 2 replies, 2 voices, and was last updated 8 years ago by
Unknown.
-
AuthorPosts
-
September 1, 2015 at 21:55 #1928
Unknown
MemberI am very new to jfuzzy logic. I get an error of this sort when i run my code
Exception in thread “main” java.lang.RuntimeException: [syntax error] expected variable or logical operator, but found <Vehicledensity>
I am also not sure how to get my result back as
double result= LevelOfCongestion.defuzzify();
says in cant convert void to double.Also, can i use the word “Gaussian” instead of “Triangle”.
Is it also correct to have done this
engine.configure(“”, “”, “Minimum”, “Maximum”, “Centroid”);
I developed this first using matlab (GUI) then “copied” the structure of the fis into java. below is my complete code.
package com.liphoto.congestion.levelOfService; import com.fuzzylite.*; import com.fuzzylite.rule.Rule; import com.fuzzylite.rule.RuleBlock; import com.fuzzylite.term.Gaussian; import com.fuzzylite.variable.InputVariable; import com.fuzzylite.variable.OutputVariable; public class levelOfService { private double LOC; private String VehicleDensity; private String ModalSpeed; public void GetLevelOfService(double selectedVehicleDensity, double selectedModalSpeed) { System.out.println("in service"); Engine engine = new Engine(); engine.setName("Congestion Defuzzify"); InputVariable Vehicledensity = new InputVariable(); Vehicledensity.setName("vehicle Density"); Vehicledensity.setRange(0, 10); Vehicledensity.addTerm(new Gaussian("VeryLow",1.062,-2.77e-17)); Vehicledensity.addTerm(new Gaussian("Low",1.062,2.5)); Vehicledensity.addTerm(new Gaussian("Average",1.062,5)); Vehicledensity.addTerm(new Gaussian("High",1.062,7.5)); Vehicledensity.addTerm(new Gaussian("VeryHigh",1.062,10)); engine.addInputVariable(Vehicledensity); InputVariable Modalspeed = new InputVariable(); Modalspeed.setName("Modal Speed"); Modalspeed.setRange(0, 100); Modalspeed.addTerm(new Gaussian("Low",1062,-2.22e-16)); Modalspeed.addTerm(new Gaussian("MidLow",1062,25)); Modalspeed.addTerm(new Gaussian("Average",1062,50)); Modalspeed.addTerm(new Gaussian("MidHigh",1062,75)); Modalspeed.addTerm(new Gaussian("High",1062,100)); engine.addInputVariable(Modalspeed); OutputVariable LevelOfCongestion = new OutputVariable(); LevelOfCongestion.setName("LevelOfCongestion"); LevelOfCongestion.setRange(0, 60); LevelOfCongestion.setDefaultValue(Double.NaN); LevelOfCongestion.addTerm(new Gaussian("A",5.096, 2.081e-16)); LevelOfCongestion.addTerm(new Gaussian("B",5.096, 12)); LevelOfCongestion.addTerm(new Gaussian("C",5.096, 24)); LevelOfCongestion.addTerm(new Gaussian("D",5.096, 36)); LevelOfCongestion.addTerm(new Gaussian("E",5.096, 48)); LevelOfCongestion.addTerm(new Gaussian("F",5.096, 60)); engine.addOutputVariable(LevelOfCongestion); RuleBlock ruleblock = new RuleBlock(); ruleblock.addRule(Rule.parse("if (Vehicledensity is VeryLow) and (Modalspeed is High) then LevelOfCongestion is A", engine)); ruleblock.addRule(Rule.parse("if Vehicledensity is Low and Modalspeed is High then LevelOfCongestion is B", engine)); ruleblock.addRule(Rule.parse("if Vehicledensity is Average and Modalspeed is Average then LevelOfCongestion is C", engine)); ruleblock.addRule(Rule.parse("if Vehicledensity is Average and Modalspeed is Average then LevelOfCongestion is D", engine)); ruleblock.addRule(Rule.parse("if Vehicledensity is High and Modalspeed is Average then LevelOfCongestion is E", engine)); ruleblock.addRule(Rule.parse("if Vehicledensity is VeryHigh and Modalspeed is Average then LevelOfCongestion is G", engine)); engine.addRuleBlock(ruleblock); engine.configure("", "", "Minimum", "Maximum", "Centroid"); StringBuilder status = new StringBuilder(); if(!engine.isReady(status)) { throw new RuntimeException("Engine not ready."+"the following errors we met:\n" + status.toString()); } Vehicledensity.setInputValue(selectedVehicleDensity); Modalspeed.setInputValue(selectedModalSpeed); double result= LevelOfCongestion.defuzzify(); engine.process(); } }
September 8, 2015 at 19:25 #1931Juan Rada-Vilela (admin)
KeymasterHi,
The name of the variable in
setName
is different from the name you are using in the rules. The names cannot have spaces.
As fordefuzzify
, the current version returnsvoid
. To get the value, you have to doLevelOfCongestion.getOutputValue()
after the engine has been processed.Gaussian and Triangle are different linguistic terms. Please check QtFuzzyLite and observe the differences between the different linguistic terms.
Cheers,
Juan.
September 8, 2015 at 19:59 #1932Unknown
MemberThank you. I had already solved the problem by using qtfuzzylite.
-
AuthorPosts
- You must be logged in to reply to this topic.