Example #1
0
        public bool ValidateActions()
        {
            bool result = true;

            SortActionsByStartTime(NextActions);

            for (int i = 0; i < NextActions.Count; ++i)
            {
                WorldAction nextAction = NextActions[i];

                if (nextAction.GetEndTime() != nextAction.StartAt + nextAction.Duration)
                {
                    result = false;
                    break;
                }

                if (ActualWorldAction != null && nextAction.StartAt < ActualWorldAction.GetEndTime())
                {
                    result = false;
                    break;
                }

                if (i < NextActions.Count - 1)
                {
                    if (NextActions[i + 1].StartAt.HasValue && NextActions[i + 1].StartAt < nextAction.GetEndTime())
                    {
                        result = false;
                        break;
                    }
                }
            }
            return(result);
        }
Example #2
0
        private int GetNextTimestamp(ScenarioDescription scenarioDescription, int TInf)
        {
            int actualActionEndTime = int.MaxValue;

            if (ActualWorldAction != null)
            {
                actualActionEndTime = ActualWorldAction.GetEndTime() < 0 ? int.MaxValue : ActualWorldAction.GetEndTime();
            }
            int nextActionStartTime = GetNextActionTime() < 0 ? int.MaxValue : GetNextActionTime();

            int nextTimeForAction = Time == 0 ? 0 :  Time + 1;
            int nextActionTime    = scenarioDescription.GetNextActionTime(nextTimeForAction);

            nextActionTime = nextActionTime < 0 ? int.MaxValue : nextActionTime;

            int min = Math.Min(nextActionTime, Math.Min(actualActionEndTime, nextActionStartTime));

            return(min > TInf ? TInf : min);
        }
Example #3
0
        public List <Vertex> CreateChildsBasedOnImplications(List <Implication> implications, World.WorldAction nextActionFromScenario, int nextTime)
        {
            List <Vertex> childs = new List <Vertex>();

            if (ActualWorldAction != null)
            {
                if (ActualWorldAction.GetEndTime() < nextTime)
                {
                    return(GetImpossibleChilds());
                }

                if (ActualWorldAction.GetEndTime() == nextTime)
                {
                    ActualWorldAction = null;
                }
            }

            WorldAction leafAction = ActualWorldAction;

            if (NextActions.Count > 0)
            {
                SortActionsByStartTime(NextActions);
                if (NextActions[0].StartAt < nextTime)
                {
                    leafAction = NextActions[0];
                }
            }

            foreach (var implication in implications)
            {
                Vertex child = new Vertex(this);
                child.Root        = this;
                child.ActualState = implication.FutureState;

                WorldAction actualAction = nextActionFromScenario;
                if (actualAction != null)
                {
                    actualAction.StartAt = nextTime;
                }

                if (implication.TriggeredActions.Count > 0)
                {
                    WorldAction triggeredAction = implication.TriggeredActions[0];
                    foreach (var action in implication.TriggeredActions)
                    {
                        if (triggeredAction.StartAt > action.StartAt)
                        {
                            triggeredAction = (WorldAction)action.Clone();
                        }
                    }

                    if (nextActionFromScenario == null)
                    {
                        if (triggeredAction != null)
                        {
                            actualAction = triggeredAction;
                        }
                    }
                    else
                    {
                        if (triggeredAction != null && nextActionFromScenario.StartAt == triggeredAction.StartAt)
                        {
                            this.IsPossible = false;
                            return(childs);
                        }
                    }
                }
                child.ActualWorldAction = actualAction;

                child.NextActions = new List <WorldAction>();
                child.NextActions.AddRange(implication.TriggeredActions);

                child.Time       = nextTime;
                child.IsPossible = child.ValidateActions();

                childs.Add(child);
            }
            return(childs);
        }