public PerformingActionAtTimeQuery(QuestionType questionType, WorldAction worldAction = null, int time = -1)
     : base(QueryType.PerformingActionAtTime, questionType)
 {
     this._worldAction = worldAction;
     this._time = time;
     _logger.Info("Creates:\n " + this);
 }
        public object Clone()
        {
            WorldAction worldAction = new WorldAction();
            worldAction.Id = Id;
            worldAction.Duration = Duration;
            worldAction.StartAt = StartAt;

            return worldAction;
        }
        private IEnumerable <Fluent> GetReleasedFluents(WorldAction worldAction, State state, int time)
        {
            var actionReleaseRecords = Descriptions.Where(t => t.Item1 == WorldDescriptionRecordType.ActionReleasesIf)
                                       .Select(t => t.Item2 as ActionReleasesIfRecord).ToList();

            var releasedFluents = actionReleaseRecords.Where(t => t.IsFulfilled(state, worldAction)).Select(t => t.GetResult(time));

            return(releasedFluents);
        }
        public void IsFulfilledWrongActionDurationTest()
        {
            _ifExpression = "a && b && c && d";
            _actionReleasesIfRecord = new ActionReleasesIfRecord(_worldAction, _fluent, _ifExpression);
            _endedWorldAction = new WorldAction(_idWorldAction, _startTime, 7);

            bool result = _actionReleasesIfRecord.IsFulfilled(_state, _endedWorldAction);
            Assert.IsFalse(result);
        }
예제 #5
0
        public object Clone()
        {
            WorldAction worldAction = new WorldAction();

            worldAction.Id       = Id;
            worldAction.Duration = Duration;
            worldAction.StartAt  = StartAt;

            return(worldAction);
        }
 public bool CheckRecords(State state, WorldAction worldAction, int time)
 {
     foreach (ScenarioObservationRecord obs in observations)
     {
         if (!obs.CheckState(state, time))
         {
             return false;
         }
     }
     return true;
 }
        public void GetNextActionTimeWithOneAction()
        {
            const int Time = 1;
            var worldAction = new WorldAction();
            worldAction.StartAt = Time;
            _vertex.NextActions.Add(worldAction);

            int result = _vertex.GetNextActionTime();

            Assert.AreEqual(Time, result);
        }
        private IEnumerable<State> GetPossibleFutureStates(WorldAction worldAction, State state, int time)
        {
            var possibleFutureStates = new List<State>();

            // Get released fluents
            var releasedFluents = GetReleasedFluents(worldAction, state, time);

            // Get possible state changes from ActionCausesIf records
            var actionCausesRec = Descriptions.Where(t => t.Item1 == WorldDescriptionRecordType.ActionCausesIf)
                            .Select(t => t.Item2 as ActionCausesIfRecord).ToList();
            ActionCausesIfRecord causedStatesX = null;
            try
            {
                causedStatesX = actionCausesRec.Where(t => t.IsFulfilled(state, worldAction)).Aggregate((x, y) => x.Concat(y));
            }
            catch (InvalidOperationException)
            {
                return new List<State>(){state};
            }
            var causedStates = causedStatesX.GetResult();
            var possibleStateChanges = new List<State>(causedStates.Select(t => new State { Fluents = t.ToList() }));

            // Get all future states excluding released fluents changes
            foreach (var stateChange in possibleStateChanges)
            {
                var template = (State)state.Clone();
                template.Fluents.RemoveAll(t => stateChange.Fluents.Any(x => x.Name == t.Name));
                template.Fluents.AddRange(stateChange.Fluents);
                possibleFutureStates.Add(template);
            }

            // Include released fluents
            foreach (var fluent in releasedFluents)
            {
                var statesToAdd = new List<State>();
                foreach (var futureState in possibleFutureStates)
                {
                    var copy = (State)futureState.Clone();
                    var fluentToRelease = copy.Fluents.First(t => t.Name == fluent.Name);
                    fluentToRelease.Value = !fluentToRelease.Value;
                    statesToAdd.Add(copy);
                }
                possibleFutureStates.AddRange(statesToAdd);
            }

            if (possibleFutureStates.Count == 0)
            {
                possibleFutureStates = new List<State>() { state };
            }

            return possibleFutureStates;
        }
        public void GetNextActionTimeWithManyActions()
        {
            const int Time = 1;
            for (int i = Time; i < 5; ++i)
            {
                var worldAction = new WorldAction();
                worldAction.StartAt = i;
                _vertex.NextActions.Add(worldAction);
            }
            int result = _vertex.GetNextActionTime();

            Assert.AreEqual(Time, result);
        }
        private IEnumerable <WorldAction> GetTriggeredActions(WorldAction worldAction, State state, int time)
        {
            var actionInvokesRecords = Descriptions.Where(t => t.Item1 == WorldDescriptionRecordType.ActionInvokesAfterIf)
                                       .Select(t => t.Item2 as ActionInvokesAfterIfRecord).ToList();
            var expressionTriggersRecords = Descriptions.Where(t => t.Item1 == WorldDescriptionRecordType.ExpressionTriggersAction)
                                            .Select(t => t.Item2 as ExpressionTriggersActionRecord).ToList();

            var triggeredActions = actionInvokesRecords.Where(t => t.IsFulfilled(state, worldAction)).Select(t => t.GetResult(time)).ToList();

            triggeredActions.AddRange(expressionTriggersRecords.Where(t => t.IsFulfilled(state)).Select(t => t.GetResult(time)));

            return(triggeredActions);
        }
        public void SetUp()
        {
            _idWorldAction = "idWorldAction";
            _startTime = 3;
            _durationTime = 5;

            _state = new State
            {
                Fluents = new List<Fluent>{
                    new Fluent { Name = "a", Value = true },
                    new Fluent { Name = "b", Value = true },
                    new Fluent { Name = "c", Value = true },
                    new Fluent { Name = "d", Value = true }
                }
            };
            _worldAction = new WorldAction(_idWorldAction, _startTime, _durationTime);
        }
        public override QueryResult CheckCondition(State state, WorldAction worldAction, int actualTime)
        {
            _logger.Info("Checking condition: " + this._condition + "\nwith parameters:\nstate: " + state + "\naction: " + worldAction);

            QueryResult result = this.CheckTime(state, actualTime);

            string logResult = "Method result: " + result;

            if (QueryResult.Undefined == result)
            {
                _logger.Warn(logResult);
            }
            else
            {
                _logger.Info(logResult);
            }

            return result;
        }
        private IEnumerable <State> GetPossibleFutureStates(WorldAction worldAction, State state, int time)
        {
            var possibleFutureStates = new List <State>();

            // Get released fluents
            var releasedFluents = GetReleasedFluents(worldAction, state, time);

            // Get possible state changes from ActionCausesIf records
            var actionCausesRec = Descriptions.Where(t => t.Item1 == WorldDescriptionRecordType.ActionCausesIf)
                                  .Select(t => t.Item2 as ActionCausesIfRecord).ToList();
            ActionCausesIfRecord causedStatesX = null;

            try
            {
                causedStatesX = actionCausesRec.Where(t => t.IsFulfilled(state, worldAction)).Aggregate((x, y) => x.Concat(y));
            }
            catch (InvalidOperationException)
            {
                return(new List <State>()
                {
                    state
                });
            }
            var causedStates         = causedStatesX.GetResult();
            var possibleStateChanges = new List <State>(causedStates.Select(t => new State {
                Fluents = t.ToList()
            }));

            // Get all future states excluding released fluents changes
            foreach (var stateChange in possibleStateChanges)
            {
                var template = (State)state.Clone();
                template.Fluents.RemoveAll(t => stateChange.Fluents.Any(x => x.Name == t.Name));
                template.Fluents.AddRange(stateChange.Fluents);
                possibleFutureStates.Add(template);
            }

            // Include released fluents
            foreach (var fluent in releasedFluents)
            {
                var statesToAdd = new List <State>();
                foreach (var futureState in possibleFutureStates)
                {
                    var copy            = (State)futureState.Clone();
                    var fluentToRelease = copy.Fluents.First(t => t.Name == fluent.Name);
                    fluentToRelease.Value = !fluentToRelease.Value;
                    statesToAdd.Add(copy);
                }
                possibleFutureStates.AddRange(statesToAdd);
            }

            if (possibleFutureStates.Count == 0)
            {
                possibleFutureStates = new List <State>()
                {
                    state
                };
            }

            return(possibleFutureStates);
        }
 public void addACS(WorldAction worldAction, int time)
 {
     ScenarioActionRecord ACS = new ScenarioActionRecord(worldAction, time);
     actions.Add(ACS);
 }
        private IEnumerable<WorldAction> GetTriggeredActions(WorldAction worldAction, State state, int time)
        {
            var actionInvokesRecords = Descriptions.Where(t => t.Item1 == WorldDescriptionRecordType.ActionInvokesAfterIf)
                .Select(t => t.Item2 as ActionInvokesAfterIfRecord).ToList();
            var expressionTriggersRecords = Descriptions.Where(t => t.Item1 == WorldDescriptionRecordType.ExpressionTriggersAction)
                .Select(t => t.Item2 as ExpressionTriggersActionRecord).ToList();

            var triggeredActions = actionInvokesRecords.Where(t => t.IsFulfilled(state, worldAction)).Select(t => t.GetResult(time)).ToList();
            triggeredActions.AddRange(expressionTriggersRecords.Where(t => t.IsFulfilled(state)).Select(t => t.GetResult(time)));

            return triggeredActions;
        }
예제 #16
0
 public abstract QueryResult CheckCondition(State state, WorldAction worldAction, int time);
        private void ButtonAddAction_Click(object sender, RoutedEventArgs e)
        {
            if (TextBoxActionName.Text == "")
            {
                LabelFluentsActionsValidation.Content = "Action name is required.";
                return;
            }
            if (!System.Text.RegularExpressions.Regex.IsMatch(TextBoxActionName.Text, @"[a-zA-Z]+[a-zA-Z0-9\-]*$"))
            {
                LabelFluentsActionsValidation.Content = "Action name should be alphanumeric.";
                return;
            }
            if (!UpDownTime.Value.HasValue)
            {
                LabelFluentsActionsValidation.Content = "Please specify the duration.";
                return;
            }
            int duration = UpDownTime.Value.Value;
            if (!Actions.Contains(Actions.FirstOrDefault(f => (f.Id == TextBoxActionName.Text && f.Duration == duration))))
            {
                var action = new WorldAction { Id = TextBoxActionName.Text, Duration = duration };
                Actions.Add(action);
                TextBoxActionName.Text = "";
                UpDownTime.Value = null;
                LabelFluentsActionsValidation.Content = "";

            }
            else
            {
                LabelFluentsActionsValidation.Content = "Such action already exists.";
            }
        }
        private IEnumerable<Fluent> GetReleasedFluents(WorldAction worldAction, State state, int time)
        {
            var actionReleaseRecords = Descriptions.Where(t => t.Item1 == WorldDescriptionRecordType.ActionReleasesIf)
                                                   .Select(t => t.Item2 as ActionReleasesIfRecord).ToList();

            var releasedFluents = actionReleaseRecords.Where(t => t.IsFulfilled(state, worldAction)).Select(t => t.GetResult(time));
            return releasedFluents;
        }
 public ScenarioActionRecord(WorldAction worldAction, int time)
     : base()
 {
     this.WorldAction = worldAction;
     Time = time;
 }
 public override void Clear()
 {
     UpDownTime.Value = null;
     SelectedAction = null;
 }