home › Forums › # Technical Support › how to use rule block with and conjunction , i am getting syntax error
Tagged: fuzzy-logic
- This topic has 1 reply, 2 voices, and was last updated 7 years, 6 months ago by
Juan Rada-Vilela (admin).
-
AuthorPosts
-
March 25, 2016 at 00:51 #2106
Unknown
Memberpackage fuzzy;
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.TNorm;
import com.fuzzylite.norm.s.AlgebraicSum;
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 Logic {
public static void main(String[] args){
Engine engine = new Engine();
engine.setName(“traffic-control”);InputVariable arrival = new InputVariable();
arrival.setName(“Arrival”);
arrival.setRange(0.000, 45.000);
arrival.addTerm(new Triangle(“VERY-SHORT”, 0.000, 7.500,15.000));
arrival.addTerm(new Triangle(“SHORT”, 7.500, 15.000,22.500));
arrival.addTerm(new Triangle(“MEDIUM”, 15.000, 22.500,30.000));
arrival.addTerm(new Triangle(“LARGE”, 22.500, 30.000,37.500));
arrival.addTerm(new Triangle(“VERY-LARGE”, 30.000, 37.500, 45.000));
engine.addInputVariable(arrival);InputVariable queue = new InputVariable();
queue.setName(“Queue”);
queue.setRange(0.000, 18.000);
queue.addTerm(new Triangle(“VERY-SHORT”, 0.000, 3.000,6.000));
queue.addTerm(new Triangle(“SHORT”, 3.000, 6.000 ,9.000));
queue.addTerm(new Triangle(“MEDIUM”, 6.000, 9.000 , 12.000));
queue.addTerm(new Triangle(“LARGE”, 9.000, 12.000 ,15.000));
queue.addTerm(new Triangle(“VERY-LARGE”, 12.000, 15.000 ,18.000));
engine.addInputVariable(queue);OutputVariable extension = new OutputVariable();
extension.setName(“Extension”);
extension.setRange(0.000, 50.000);
extension.setDefaultValue(Double.NaN);
extension.addTerm(new Triangle(“ZERO”, 0.000, 10.000,20.000));
extension.addTerm(new Triangle(“SHORT”, 10.000, 20.000 ,30.000));
extension.addTerm(new Triangle(“MEDIUM”, 20.000, 30.000 ,40.000));
extension.addTerm(new Triangle(“LARGE”, 30.000, 40.000 ,50.000));
engine.addOutputVariable(extension);RuleBlock ruleBlock = new RuleBlock();
ruleBlock.addRule(Rule.parse(“if Queue is VERY-SHORT and Arrival is VERY-SHORT then Extension is ZERO”, engine));
ruleBlock.addRule(Rule.parse(“if Queue is SHORT and Arrival is VERY-SHORT then Extension is ZERO”, engine));
ruleBlock.addRule(Rule.parse(“if Queue is MEDIUM and Arrival is VERY-SHORT then Extension is ZERO”, engine));
ruleBlock.addRule(Rule.parse(“if Queue is LARGE and Arrival is VERY-SHORT then Extension is ZERO”, engine));
ruleBlock.addRule(Rule.parse(“if Queue is VERY-LARGE and Arrival is VERY-SHORT then Extension is ZERO”, engine));ruleBlock.addRule(Rule.parse(“if Queue is VERY-SHORT and Arrival is SHORT then Extension is SHORT”, engine));
ruleBlock.addRule(Rule.parse(“if Queue is SHORT and Arrival is SHORT then Extension is SHORT”, engine));
ruleBlock.addRule(Rule.parse(“if Queue is MEDIUM and Arrival is SHORT then Extension is SHORT”, engine));
ruleBlock.addRule(Rule.parse(“if Queue is LARGE and Arrival is SHORT then Extension is ZERO”, engine));
ruleBlock.addRule(Rule.parse(“if Queue is VERY-LARGE and Arrival is SHORT then Extension is ZERO”, engine));ruleBlock.addRule(Rule.parse(“if Queue is VERY-SHORT and Arrival is MEDIUM then Extension is MEDIUM”, engine));
ruleBlock.addRule(Rule.parse(“if Queue is SHORT and Arrival is MEDIUM then Extension is MEDIUM”, engine));
ruleBlock.addRule(Rule.parse(“if Queue is MEDIUM and Arrival is MEDIUM then Extension is MEDIUM”, engine));
ruleBlock.addRule(Rule.parse(“if Queue is LARGE and Arrival is MEDIUM then Extension is SHORT”, engine));
ruleBlock.addRule(Rule.parse(“if Queue is VERY-LARGE and Arrival is MEDIUM then Extension is SHORT”, engine));ruleBlock.addRule(Rule.parse(“if Queue is VERY-SHORT and Arrival is LARGE then Extension is LARGE”, engine));
ruleBlock.addRule(Rule.parse(“if Queue is SHORT and Arrival is LARGE then Extension is MEDIUM”, engine));
ruleBlock.addRule(Rule.parse(“if Queue is MEDIUM and Arrival is LARGE then Extension is MEDIUM”, engine));
ruleBlock.addRule(Rule.parse(“if Queue is LARGE and Arrival is LARGE then Extension is MEDIUM”, engine));
ruleBlock.addRule(Rule.parse(“if Queue is VERY-LARGE and Arrival is LARGE then Extension is SHORT”, engine));ruleBlock.addRule(Rule.parse(“if Queue is VERY-SHORT and Arrival is VERY-LARGE then Extension is LARGE”, engine));
ruleBlock.addRule(Rule.parse(“if Queue is SHORT and Arrival is VERY-LARGE then Extension is LARGE”, engine));
ruleBlock.addRule(Rule.parse(“if Queue is MEDIUM and Arrival is VERY-LARGE then Extension is MEDIUM”, engine));
ruleBlock.addRule(Rule.parse(“if Queue is LARGE and Arrival is VERY-LARGE then Extension is MEDIUM”, engine));
ruleBlock.addRule(Rule.parse(“if Queue is VERY-LARGE and Arrival is VERY-LARGE then Extension is SHORT”, engine));engine.addRuleBlock(ruleBlock);
engine.configure(“Minimum”,””,”Minimum”,”Maximum”,”Centroid”);
StringBuilder status = new StringBuilder();
if (!engine.isReady(status)) {
throw new RuntimeException(“Engine not ready. ”
+ “The following errors were encountered:\n” + status.toString());
}for (int i = 0; i < 50; ++i) {
double arrival_length = arrival.getMinimum() + i * (arrival.range() / 50);
double queue_length = queue.getMinimum() + i * (queue.range() / 50);
arrival.setInputValue(arrival_length);
queue.setInputValue(queue_length);
engine.process();
FuzzyLite.logger().info(String.format(
“Arrival_length.input = %s Queue_length.input = %s -> Power.output = %s”,
Op.str(arrival_length),Op.str(queue_length), Op.str(extension.getOutputValue())));
}
}}
March 25, 2016 at 07:09 #2107Juan Rada-Vilela (admin)
KeymasterHi,
thank you for your post.
First, you cannot use hyphens as name of linguistic terms. Instead of VERY-SHORT, please change it to VERY_SHORT, and same with the other terms.
Second, if you are using the Maven repository, there is a bug in that version. Please use the latest jfuzzylite version, which can be downloaded from fuzzylite.com/downloads or from github.com/fuzzylite/jfuzzylite/releases
Let me know if it helps.
Cheers.
-
AuthorPosts
- You must be logged in to reply to this topic.