Beispiel #1
0
        /// <summary>Build all possible assignment and calculate</summary>
        /// <param name="expr">Proposition to calculate</param>
        /// <param name="dict">Assignment list</param>
        private void GetTrueAssignmentListCore(Proposition expr, Dictionary <string, bool> dict)
        {
            if (expr.GetAtomList().Count == dict.Count)
            {
                bool value; string result;
                calcEng.TryEvaluate(out value, out result, expr, dict);
                if (value)
                {
                    trueList.Add(dict.DeepCopy());
                }
            }
            else
            {
                string target = expr.GetAtomList().Except(dict.Keys.ToList()).First();
                Dictionary <string, bool> dict1 = dict.DeepCopy(), dict2 = dict.DeepCopy();
                dict1.Add(target, false);
                dict2.Add(target, true);

                GetTrueAssignmentListCore(expr, dict1);
                GetTrueAssignmentListCore(expr, dict2);
            }
        }
Beispiel #2
0
        /// <summary>Evaluate proposition with given data</summary>
        /// <param name="value">Result of evaluation</param>
        /// <param name="error">Error Message</param>
        /// <param name="expr">Proposition to evaluate</param>
        /// <param name="data">Assignment table</param>
        /// <returns>True if successed evaluate</returns>
        public bool TryEvaluate(out bool value, out string error, Proposition expr, Dictionary <string, bool> data)
        {
            value = false; error = "";
            if (expr == null || !expr.IsVaild())
            {
                error = InvalidPropositionException.REASON_INVAILD;
                return(false);
            }

            List <string> atomList = expr.GetAtomList();
            List <string> keyList  = data.Keys.ToList();

            if (atomList.Intersect(keyList).Count() != atomList.Count)
            {
                error = "모든 atom에 대해 적절한 대입값이 없습니다.";
                return(false);
            }

            evalData = data;
            value    = Evaluate(expr);
            return(true);
        }