/// <summary>
        /// Получает ответ на логический запрос.
        /// </summary>
        /// <param name="query">Логический запрос.</param>
        /// <returns>
        /// Возвращает результат логического запроса.
        /// </returns>
        protected override ILogicalResult Solve(ILogicalQuery query)
        {
            knBase.ClearWorkMemory();
            this.cachedQuery = query;
            cachedResult.Clear();
            IEnumerable <IKnowledgeBaseAction> init = query.GetPreQueryActions();

            foreach (var item in init)
            {
                item.Execute(knBase);
            }
            List <IData> queriedData = query.GetQueriedItems().ToList();
            List <IData> res         = new List <IData>();

            foreach (var target in queriedData)
            {
                if (target.Value == null)
                {
                    foreach (var possibleTarget in GetPossibleTargets(target))
                    {
                        if (GetResultRec(possibleTarget))
                        {
                            //возможная цель реализована
                            res.Add(possibleTarget);
                            break;
                        }
                    }
                }
                else
                {
                    if (GetResultRec(target))
                    {
                        res.Add(target);
                    }
                }
            }
            ILogicalResult result = new ResultingFactSet(res);

            cachedResult.Add(result);
            return(result);
        }
예제 #2
0
        /// <summary>
        /// Получает ответ на логический запрос.
        /// </summary>
        /// <param name="query">Логический запрос.</param>
        /// <returns>
        /// Возвращает результат логического запроса.
        /// </returns>
        protected override ILogicalResult Solve(ILogicalQuery query)
        {
            knBase.ClearWorkMemory();
            this.cachedQuery = query;
            cachedResult.Clear();
            IEnumerable <IKnowledgeBaseAction> init = query.GetPreQueryActions();

            foreach (var item in init)
            {
                item.Execute(knBase);
            }
            List <IData>             queriedData = query.GetQueriedItems().ToList();
            List <ILogicalStatement> ready       = new List <ILogicalStatement>();

            ready = knBase.ActiveSet.ToList();
            while (ready.Count > 0 && queriedData.Count((a) => { return(a.Value == null); }) > 0)
            {
                ILogicalStatement st = ChooseOne(ready);
                ready.Remove(st);
                st.Execute(knBase);
                if (knBase.StateChanged)
                {
                    ready = knBase.ActiveSet.ToList();
                }
                foreach (IData data in knBase.CurrentData)
                {
                    foreach (IData qData in queriedData)
                    {
                        if (qData.Value == null && qData.Name == data.Name)
                        {
                            qData.Value = data.Value;
                        }
                    }
                }
            }
            ILogicalResult result = new ResultingFactSet(queriedData);

            cachedResult.Add(result);
            return(result);
        }