home Forums # Technical Support logical operators grammers , error in numbers of operands Reply To: logical operators grammers , error in numbers of operands

#985
Unknown
Member

hello again
yes of course
thank you
Great help to me

		
					try{
						
						
						
					      Engine engine = new Engine("hearter");
					      InputVariable chestpain = new InputVariable();
					      chestpain.setName("chestpain");
					      chestpain.setRange(0.000, 4.000);
					      chestpain.addTerm(new Triangle("TYPIC", 1.000, 1.000));
					      chestpain.addTerm(new Triangle("ATYPIC", 2.0, 2.000));
					      chestpain.addTerm(new Triangle("NONANGIN", 3.000, 3.000));
					      chestpain.addTerm(new Triangle("ASYMPTOMATIC", 4.000, 4.000));
					      engine.addInputVariable(chestpain);
					      
					     					
					      InputVariable restpress = new InputVariable();
					      restpress.setName("restpress");
					      restpress.setRange(100.000, 200.000);
					      restpress.addTerm(new Triangle("MIN", 100.000, 155.000));
					      restpress.addTerm(new Triangle("MAX", 140.000, 200.000));
					      engine.addInputVariable(restpress);
					      
					      InputVariable serum = new InputVariable();
					      serum.setName("serum");
					      serum.setRange(150.000, 300.000);
					      serum.addTerm(new Triangle("MINLEVEL", 150.000, 250.000));
					      serum.addTerm(new Triangle("MAXLEVEL", 240.000, 300.000));
					      engine.addInputVariable(serum);
					      
					      InputVariable smoke = new InputVariable();
					      smoke.setName("smoke");
					      smoke.setRange(0.000, 100.000);
					      smoke.addTerm(new Triangle("LOWPOSSIBILITY", 0.000, 40.000));
					      smoke.addTerm(new Triangle("HIGHPOSSIBILITY", 35.000, 100.000));
					      engine.addInputVariable(smoke);
					      
					      InputVariable sugar = new InputVariable();
					      sugar.setName("sugar");
					      sugar.setRange(10.000, 200.000);
					      sugar.addTerm(new Triangle("LEVELNO", 10.000, 130.000));
					      sugar.addTerm(new Triangle("LEVELYES", 125.000, 200.000));
					      engine.addInputVariable(sugar);
					      
					      InputVariable maxrate = new InputVariable();
					      maxrate.setName("maxrate");
					      maxrate.setRange(40.000, 90.000);
					      maxrate.addTerm(new Triangle("MINRATE", 40.000, 80.000));
					      maxrate.addTerm(new Triangle("MAXRATE", 65.000, 85.000));
					      engine.addInputVariable(maxrate);
					      
					      InputVariable restrate = new InputVariable();
					      restrate.setName("restrate");
					      restrate.setRange(70.000, 200.000);
					      restrate.addTerm(new Triangle("LOWRATE", 70.000, 150.000));
					      restrate.addTerm(new Triangle("HIGHRATE", 145.000, 200.000));
					      engine.addInputVariable(restrate);
					      

					      OutputVariable angin = new OutputVariable();
					      angin.setName("angin");
					      angin.setRange(0.000, 4.000);
					      angin.setDefaultValue(Double.NaN);
					      angin.addTerm(new Triangle("MILD", 0.000, 2.000));
					      angin.addTerm(new Triangle("MASSIVE", 2.000, 4.000));
					  	  engine.addOutputVariable(angin);
					      
					  	RuleBlock ruleBlock = new RuleBlock();
					  	 ruleBlock.addRule(Rule.parse("if chestpain is TYPIC and restpress is MIN and serum is MINLEVEL and smoke is LOWPOSSIBILITY and sugar is LEVELNO and maxrate is MINRATE and restrate is LOWRATE then angin  is MILD", engine));
					  	 ruleBlock.addRule(Rule.parse("if chestpain is ASYMPTOMATIC and restpress is MIN and serum is MAXLEVEL and smoke is LOWPOSSIBILITY and sugar is LEVELNO and  maxrate is MINRATE and restrate is HIGHRATE then angin is MASSIVE", engine));
					  	 ruleBlock.addRule(Rule.parse("if chestpain is NONANGIN and restpress is MIN and serum is MAXLEVEL and smoke is HIGHPOSSIBILITY and sugar is LEVELNO and  maxrate is MINRATE and restrate is HIGHRATE then angin is MILD", engine));
					   	 ruleBlock.addRule(Rule.parse("if chestpain is ATYPIC and restpress is MIN and serum is MAXLEVEL and smoke is LOWPOSSIBILITY and sugar is LEVELNO and  maxrate is MINRATE and restrate is HIGHRATE then angin is MILD", engine));
					   	 ruleBlock.addRule(Rule.parse("if chestpain is ATYPIC and restpress is MIN and serum is MAXLEVEL and smoke is HIGHPOSSIBILITY and sugar is LEVELNO and  maxrate is MINRATE and restrate is LOWRATE then angin is MILD", engine));
					   	 ruleBlock.addRule(Rule.parse("if chestpain is ASYMPTOMATIC and restpress is MAX and serum is MINLEVEL and smoke is LOWPOSSIBILITY and sugar is LEVELNO and  maxrate is MINRATE and restrate is LOWRATE then angin is MILD", engine));
					   	 ruleBlock.addRule(Rule.parse("if chestpain is ASYMPTOMATIC or restpress is MAX or serum is MAXLEVEL and smoke is LOWPOSSIBILITY or sugar is LEVELNO or  minrate is MINRATE or restrate is HIGHRATE then angin is MASSIVE", engine));
					   	 ruleBlock.addRule(Rule.parse("if chestpain is ASYMPTOMATIC and restpress is MAX and serum is MAXLEVEL and smoke is HIGHPOSSIBILITY and sugar is LEVELNO and  maxrate is MINRATE and restrate is LOWRATE then angin is MILD",engine));
					   	 ruleBlock.addRule(Rule.parse("if chestpain is ATYPIC and restpress is MIN and serum is MAXLEVEL and smoke is HIGHPOSSIBILITY and sugar is LEVELNO and  maxrate is MINRATE and restrate is LOWRATE then angin is MILD",engine));
					   	 ruleBlock.addRule(Rule.parse("if chestpain is NONANGIN and restpress is MIN and serum is MAXLEVEL and smoke is HIGHPOSSIBILITY and sugar is LEVELNO and  maxrate is MINRATE and restrate is LOWRATE then angin is MILD",engine));
					   	 ruleBlock.addRule(Rule.parse("if chestpain is NONANGIN and restpress is MAX and serum is MAXLEVEL and smoke is HIGHPOSSIBILITY and sugar is LEVELYES and  maxrate is MAXRATE and restrate is HIGHRATE then angin is MASSIVE",engine));
					   	
					  
					  	  
					     engine.addRuleBlock(ruleBlock);
					     
					     engine.configure("", "", "AlgebraicProduct", "AlgebraicSum", "Centroid");
					     StringBuilder status = new StringBuilder();
					     if (!engine.isReady(status))
					          throw new RuntimeException("Engine not ready. " +
					                "The following errors were encountered:\n" + status.toString());

					    
					     
					        
					         chestpain.setInputValue(selectedchestpain);
					         restpress.setInputValue(numrestingpress);
					         serum.setInputValue(numcholeserum);
					         smoke.setInputValue(selectedsmoke);
					         sugar.setInputValue(selectedfasting);
					         maxrate.setInputValue(nummaxrate);
					         restrate.setInputValue(numrestrate);
					         engine.process();
					  
					         double result= angin.defuzzify();
					         String resultstr= String.valueOf(result);
					         FuzzyLite.logger().info(String.format("A -> Power.output = %s", angin.defuzzify()));
					         Log.d("output", resultstr);
					     }

					      
////////////////////////////
							
			
						
					
					catch(Exception e)
					{
						e.printStackTrace();
					Log.d("catch error", "error in fuzzy system");
					}