/// <summary> /// int is the symbol /// </summary> public List <int> Requirements() { List <int> requirements = new List <int>(); if (IsAref()) { requirements.AddRange(_ARef.Requirements()); } else { requirements.Add(_A); } if (!Single) { if (IsBref()) { requirements.AddRange(_BRef.Requirements()); } else { requirements.Add(_B); } } return(requirements); }
/// <summary> /// Check if (PropostionNo) is true in this world state /// -1 is goal check /// </summary> public bool?IsTrue(int PropositionNo) { int[] needed_ags; if (PropositionNo == -1) { needed_ags = _Goal.Requirements().ToArray(); } else { needed_ags = _KnowledgeBase.Requirements(PropositionNo); } bool?[] grab_ags = new bool?[needed_ags.Length]; for (int i = 0; i < needed_ags.Length; i++) { grab_ags[i] = Arguments[needed_ags[i]]; } if (PropositionNo == -1) { return(_Goal.IsTrue(grab_ags)); } else { return(_KnowledgeBase.IsTrue(PropositionNo, grab_ags)); } }
//......IsTrue............................................................ public bool?IsTrue(bool?[] Arguements) { bool?left, right = false; int leftSize = 1; if (IsAref()) { leftSize = _ARef.Requirements().Count; bool?[] leftarr = new bool?[leftSize]; Array.Copy(Arguements, 0, leftarr, 0, leftarr.Length); left = _ARef.IsTrue(leftarr); } else { left = Arguements[0]; } if (!Single) { bool?[] rightarr = new bool?[Arguements.Length - leftSize]; Array.Copy(Arguements, leftSize, rightarr, 0, rightarr.Length); if (IsBref()) { right = _BRef.IsTrue(rightarr); } else { right = rightarr[0]; } } // NOT if (ANotted) { left = !left; } if (Single) { return(left); } if (BNotted) { right = !right; } // Other Operations switch (Operation) { case Operations.NotSet: throw new System.NotSupportedException(); case Operations.Negation: // NOT throw new System.NotSupportedException(); case Operations.Conjunction: // AND return(left & right); case Operations.Disjunction: // OR return(left | right); case Operations.Implication: // True when either A value = 0 or B value = 1, thus false when neither occur if ((left == true) && (right == false)) { return(false); } else if ((!left | right) == true) { return(true); } else { return(null); } case Operations.Biconditional: // True only when A value is equal to B value if ((left == null) || (right == null)) { return(null); } else if (left == right) { return(true); } else { return(false); } default: throw new System.ArgumentException("Something went wrong ...... oh noes"); } }