예제 #1
0
        public HashSet <RuleNode> MinPremise()
        {
            RuleNode parent      = this;
            int      minWayInd   = -1;
            int      minWayCount = int.MaxValue;

            for (int i = 0; i < parent.OrPremiseCount; i++)
            {
                bool isPermiseProved = parent.IsPremiseProved(i);
                int  curPremiseCount = parent.PremiseCount(i);
                if (isPermiseProved && minWayCount > curPremiseCount)
                {
                    minWayCount = curPremiseCount;
                    minWayInd   = i;
                }
            }
            var res = minWayInd == -1? new HashSet <RuleNode>():
                      new HashSet <RuleNode>(parent.Premise(minWayInd));

            return(res);
        }//end of MinPremise()
예제 #2
0
        public static HashSet <RuleNode> FindEvidenceBase(
            HashSet <int> needProve, List <Rule> rulesList, List <string> factsList)
        {
            HashSet <RuleNode> ruleNodeProvedList = new HashSet <RuleNode>();
            RuleNode           root = new RuleNode(new Fact(-1), null);

            root.AddOrPremise(needProve, idsProvedFact);
            PriorityQueue <QueueElem> queue = new PriorityQueue <QueueElem>();

            queue.PriorityAdd(new QueueElem(root, 0), root.PremiseCount(0));
            bool isRootProved = false;

            #region algorithm
            while (queue.IsNotEmphty && !isRootProved)
            {
                QueueElem curQueueElem = queue.Dequeue();
                RuleNode  curNode      = curQueueElem.node;
                #region OrPremise for curNode
                List <RuleNode> orPremise = curNode.Premise(curQueueElem.orPeremiseInd);
                if (!curNode.Fact.IsProved)
                {
                    foreach (RuleNode ruleNode in orPremise)
                    {
                        if (!ruleNode.Fact.IsProved)
                        {
                            int  indPremise = 0;
                            bool isList     = true;
                            foreach (Rule rule in rulesList)
                            {
                                if (rule.idConclusion == ruleNode.Fact.Id)
                                {
                                    isList = false;
                                    ruleNode.AddOrPremise(rule.idsPremise, idsProvedFact);
                                    int premiseCount = ruleNode.PremiseCount(indPremise);
                                    if (premiseCount != 0)
                                    {
                                        if (!idsProvedFact.Contains(ruleNode.Fact.Id))
                                        {
                                            queue.PriorityAdd(new QueueElem(ruleNode, indPremise), premiseCount);
                                        }
                                    }
                                    else
                                    {
                                        isRootProved = UpTruePropagation(ruleNode, ruleNodeProvedList);
                                    }
                                    indPremise++;
                                }
                            }
                            if (isList)
                            {
                                isRootProved = UpTruePropagation(ruleNode, ruleNodeProvedList);
                            }
                        }
                    }
                }
                #endregion
            }
            #endregion
            var evidenceBase     = FindEvidenceBase(ruleNodeProvedList);
            var hashSetFactsList = new HashSet <RuleNode>(ruleNodeProvedList);
            return(hashSetFactsList);
        }