コード例 #1
0
        public AccesibleConditionQuery(QuestionType questionType, string condition, ScenarioDescription scenario)
            : base(QueryType.AccesibleCondition, questionType)
        {
            _queryType = QueryType.AccesibleCondition;
            _condition = condition;
            var logicExp = new SimpleLogicExpression(this._condition);
            _fluentNames = logicExp.GetFluentNames();
            _scenario = scenario;

            ExecQuery = new ExecutableScenarioQuery(QuestionType.Ever, _scenario);
            CondAtTimeQuery = new ConditionAtTimeQuery(QuestionType.Ever, _condition);

            _logger.Info("Creates:\n " + this);
        }
コード例 #2
0
 public static QueryResult ExecuteQuery(Query query, ScenarioDescription scenarioDescription)
 {
     return pageSwitcher.ExecuteQuery(query, scenarioDescription);
 }
コード例 #3
0
        public void SetUp()
        {
            // BASIC WORLD DESCRIPTION
            _worldDescription = new WorldDescription();
            _worldDescription.Descriptions.Add(new Tuple<WorldDescriptionRecordType, WorldDescriptionRecord>(WorldDescriptionRecordType.Initially, new InitialRecord("a || b || c || d")));
            _worldDescription.Descriptions.Add(new Tuple<WorldDescriptionRecordType, WorldDescriptionRecord>(WorldDescriptionRecordType.ActionCausesIf, new ActionCausesIfRecord(this._actionA2, "a && !b", "c")));
            _worldDescription.Descriptions.Add(new Tuple<WorldDescriptionRecordType, WorldDescriptionRecord>(WorldDescriptionRecordType.ActionCausesIf, new ActionCausesIfRecord(this._actionB3, "a || b", "d")));

            // BASIC SCENARIO
            _scenarioDescription = new ScenarioDescription("basic");
            _scenarioDescription.addObservation(new SimpleLogicExpression("a && b && c && d"), 0);
            _scenarioDescription.addACS(this._actionA2, 1);
            _scenarioDescription.addObservation(new SimpleLogicExpression("a && !b && c && d"), 4);

            _reasoning = new Reasoning();

            foreach (var description in _worldDescription.Descriptions.Select(t => t.Item2))
                _reasoning.AddWorldDescriptionRecord(description);
        }
コード例 #4
0
        public void Initialize(List<Fluent> fluents, List<WorldAction> actions, List<WorldDescriptionRecord> statements, int maxTime)
        {
            ActionAdd.SetActions(actions);
            _scenarioDescription = new ScenarioDescription();
            _fluents = fluents;

            InitializeStatements(statements);
            this.ObservationAdd.Fluents = new ObservableCollection<Fluent>(fluents);
            this.ActionAdd.MaxTime = maxTime;
            this.ObservationAdd.MaxTime = maxTime;
        }
コード例 #5
0
 private void AddScenario_Click(object sender, RoutedEventArgs e)
 {
     if (String.IsNullOrEmpty(ScenarioName))
     {
         LabelValidationScenario.Content = "It is necessary to fill scenario name.";
     }
     else
     {
         foreach(ScenarioDescription item in SavedScenarios)
         {
             if(item.Name == ScenarioName)
             {
                 LabelValidationScenario.Content = "Scenario with this name already exists.";
                 return;
             }
         }
         _scenarioDescription.Name = ScenarioName;
         SavedScenarios.Add(_scenarioDescription);
         _scenarioDescription = new ScenarioDescription();
         ScenarioName = "";
         CleanValues();
     }
 }
コード例 #6
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();
        }
コード例 #7
0
 private bool CheckIfLeafIsPossible(Vertex leaf, ScenarioDescription scenarioDescription)
 {
     return leaf.IsPossible && leaf.ValidateActions() && worldDescription.Validate(leaf) && scenarioDescription.CheckIfLeafIsPossible(leaf);
 }
コード例 #8
0
 public QueryResult ExecuteQuery(Query query, ScenarioDescription scenarioDescription)
 {
     return _reasoning.ExecuteQuery(query, scenarioDescription);
 }
コード例 #9
0
 public ExecutableScenarioQuery(QuestionType questionType, ScenarioDescription scenario)
     : base(QueryType.ExecutableScenario, questionType)
 {
     _scenario = scenario;
 }
コード例 #10
0
        private List<State> CreateStatesBasedOnObservations(List<string> fluentNames, ScenarioDescription scenarioDescription, ref int time)
        {
            List<State> states = new List<State>();

            time = scenarioDescription.GetNextObservationTime(0);
            if (time == -1 || time > _TInf)
            {
                return states;
            }

            ScenarioObservationRecord observation = scenarioDescription.GetObservationFromTime(time);
            if (observation == null)
            {
                _logger.Warn("Scenario has no observations!");
                State state = new State();
                state.AddFluents(fluentNames);
                states.Add(state);
            }
            else
            {
                _logicExpression = new SimpleLogicExpression(observation.Expr as SimpleLogicExpression);

                List<Fluent[]> possibleInitialValues = _logicExpression.CalculatePossibleFluents();
                foreach (var valuation in possibleInitialValues)
                {
                    State state = new State();
                    state.AddFluents(fluentNames);
                    foreach (var fluent in valuation)
                    {
                        try
                        {
                            state.Fluents.First(f => f.Name == fluent.Name).Value = fluent.Value;
                        }
                        catch (System.ArgumentNullException)
                        {
                            _logger.Error("Fluent " + fluent.Name + " doesn't exist!");
                        }

                    }
                    states.Add(state);
                }
            }

            return states;
        }