示例#1
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);
        }
示例#2
0
        private bool CheckNearestObservations(ScenarioDescription scenarioDescription, int nextTime)
        {
            int actualTime = Time;

            while (actualTime <= nextTime)
            {
                int nextObservationTime = scenarioDescription.GetNextObservationTime(actualTime);
                if (nextObservationTime == -1)
                {
                    return(true);
                }
                if (!CheckNearestObservation(scenarioDescription, actualTime, nextObservationTime, nextTime))
                {
                    return(false);
                }

                actualTime = nextObservationTime + 1;
            }

            return(true);
        }