コード例 #1
0
        public void CollectAnswerForEverQueryResultTrue()
        {
            _queryResultContainer = new QueryResultsContainer(QuestionType.Ever);
            _queryResultContainer.AddMany(QueryResult.True);
            _queryResultContainer.AddMany(QueryResult.False);

            QueryResult result = _queryResultContainer.CollectResults();

            Assert.AreEqual(QueryResult.True, result);
        }
コード例 #2
0
        public QueryResult ExecuteQuery(Query query, ScenarioDescription scenarioDescription)
        {
            QueryResultsContainer queryResultsContainer = new QueryResultsContainer(query.questionType);

            //tree initialization
            Tree tree = new Tree(TInf);
            //add first level
            int numberOfImpossibleLeaf = 0;

            tree.AddFirstLevel(worldDescription, scenarioDescription, out numberOfImpossibleLeaf);

            queryResultsContainer.AddMany(QueryResult.False, numberOfImpossibleLeaf);

            if (tree.LastLevel.Count > 0 && CheckIfLeafIsPossible(tree.LastLevel[0], scenarioDescription))
            {
                QueryResult result = query.CheckCondition(tree.LastLevel[0]);
                if (result == QueryResult.True || result == QueryResult.False)
                {
                    queryResultsContainer.AddMany(result);
                }
            }

            //generate next level if query can't answer yet
            while (!queryResultsContainer.CanQuickAnswer() && tree.LastLevel.Count > 0)
            {
                int childsCount = tree.LastLevel.Count;
                for (int i = 0; i < childsCount; ++i)
                {
                    Vertex leaf = tree.LastLevel[i];
                    if (!CheckIfLeafIsPossible(leaf, scenarioDescription))
                    {
                        tree.DeleteChild(i);
                        queryResultsContainer.AddMany(QueryResult.False);
                        if (queryResultsContainer.CanQuickAnswer())
                        {
                            break;
                        }
                    }
                    else
                    {
                        tree.DeleteChild(i);
                        List <Vertex> nextLevel = leaf.GenerateChildsForLeaf(worldDescription, scenarioDescription, TInf);

                        foreach (var child in nextLevel)
                        {
                            if (!CheckIfLeafIsPossible(child, scenarioDescription))
                            {
                                queryResultsContainer.AddMany(QueryResult.False);
                                if (queryResultsContainer.CanQuickAnswer())
                                {
                                    break;
                                }
                            }
                            QueryResult result = query.CheckCondition(child);
                            if (result == QueryResult.True || result == QueryResult.False)
                            {
                                queryResultsContainer.AddMany(result);
                            }
                            else
                            {
                                tree.Add(child);
                            }
                        }
                    }
                }
            }

            return(queryResultsContainer.CollectResults());
        }