/// <summary> /// Creates mirrored rules; useful if in1 and in2 are of the same type and can be given in any order/can be swapped, ie marks /// </summary> /// <param name="outVar"></param> /// <param name="outTermName"></param> /// <param name="op"></param> /// <param name="in1"></param> /// <param name="in1TermName1"></param> /// <param name="in2"></param> /// <param name="in2TermName"></param> public void AddRule(Linguistic outVar, string outTermName, FuzzyOperator op, Linguistic in1, string in1TermName, Linguistic in2, string in2TermName) { #region check for non-local references if (outVar.Name != OutVar.Name) { throw new KeyNotFoundException("Only the local output variable can be use; rule refers to " + outVar + "; local OutVar.Name = " + OutVar.Name); } if (InVars[in1.Name] == null) { throw new KeyNotFoundException("Only the local input variables can be use; rule refers to " + in1 + "; local InVars: " + InVars.Keys.ToArray().ToString()); } if (InVars[in2.Name] == null) { throw new KeyNotFoundException("Only the local input variables can be use; rule refers to " + in2 + "; local InVars: " + InVars.Keys.ToArray().ToString()); } if (InVars[in1.Name][in1TermName] == null) { throw new KeyNotFoundException("Only existing terms can be use; rule refers to " + in1TermName); } if (InVars[in2.Name][in2TermName] == null) { throw new KeyNotFoundException("Only existing terms can be use; rule refers to " + in2TermName); } #endregion Rules.Add(new FuzzyRule(OutVar, outTermName, InVars[in1.Name], in1TermName, op, InVars[in2.Name], in2TermName)); Rules.Add(new FuzzyRule(OutVar, outTermName, InVars[in2.Name], in2TermName, op, InVars[in1.Name], in1TermName)); }
public FuzzyRule(Linguistic outVar, string outTermName, Linguistic in1, string in1TermName) { this.outVar = outVar; this.inVars = new List <Linguistic>(); this.inVars.Add(in1); Operation = FuzzyOperator.OR; outTerm = outVar.FindTerm(outTermName); inTerms = new List <FuzzyTerm>(); inTerms.Add(in1.FindTerm(in1TermName)); Possibility = 0; }
/* * public JSONObject encodeCompleteJson() * { * JSONObject encoded = this.encodeLinguisticJson(); * encoded.AddField("Rule", Eval.double2Float(this.fuzzyValue)); * return encoded; * } */ public JSONObject encodeLinguisticJson() { JSONObject encoded = new JSONObject(JSONObject.Type.OBJECT); encoded.AddField("Value", this.membershipValue.linguistic); encoded.AddField("Operator", FuzzyOperator.nameOf(this.fOperator)); encoded.AddField("Implication", FuzzyImplication.nameOf(this.implicationM)); encoded.AddField("Rule", this.rule); return(encoded); }
public void setup() { TestJsonRule = @" { ""Value"" : """ + testRuleValue + @""", ""Operator"" : """ + FuzzyOperator.nameOf(TestOperator) + @""", ""Implication"" : """ + FuzzyImplication.nameOf(TestImplication) + @""", ""Rule"" : """ + testActualRule + @""" } "; }
// JSON Encode and Decode // public static LinguisticRule fromJson(string JsonData) { JSONObject LRJSO = new JSONObject(JsonData); LinguisticRule Result = new LinguisticRule( LRJSO.GetField("Value").str, LRJSO.GetField("Rule").str); Result.implicationMethod = FuzzyImplication.TryParse( LRJSO.GetField("Implication").str); Result._operator = FuzzyOperator.TryParse( LRJSO.GetField("Operator").str); return(Result); }
public void T4LinguisticEncode() { testRule = LinguisticRule.fromJson(TestJsonRule); Assert.AreEqual( testRuleValue, testRule.encodeLinguisticJson().GetField("Value").str ); Assert.AreEqual( TestImplication, FuzzyImplication.TryParse( testRule.encodeLinguisticJson(). GetField("Implication").str) ); Assert.AreEqual( FuzzyOperator.nameOf(TestOperator), testRule.encodeLinguisticJson(). GetField("Operator").str ); Assert.AreEqual( testActualRule, testRule.encodeLinguisticJson().GetField("Rule").str ); }