home Forums # Technical Support help with errors and advice

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1928
    Unknown
    Member

    I 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();
     
        }
        
    
        
    }
    
    #1931

    Hi,

    The name of the variable in setName is different from the name you are using in the rules. The names cannot have spaces.
    As for defuzzify, the current version returns void. To get the value, you have to do LevelOfCongestion.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.

    #1932
    Unknown
    Member

    Thank you. I had already solved the problem by using qtfuzzylite.

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