Exemple #1
0
        public void AddGoalCompletionTime(int iteration, Constant agent, Predicate key, int value, out Constant backtrackToAgent)
        {
            GoalCompletionAtIteration goalCompletion = new GoalCompletionAtIteration();

            goalCompletion.Iteration = iteration;
            goalCompletion.Agent     = agent;
            goalCompletion.Goal      = key;
            goalCompletion.MinTime   = value;

            //
            backtrackToAgent = null;
            // If this goal overrides an existing completion by another agent, return to this agent at the next iteration..
            var overridenCompletion = GoalsCompletionTime.FindLast(x => x.Goal == key && !x.Invalid);

            if (overridenCompletion != null)
            {
                if (value < overridenCompletion.MinTime)
                {
                    // in this case, the agent improved the previous time.
                    Constant slowerAgent = overridenCompletion.Agent;

                    // Slower agent got beaten by the current agent, let the slower agent to replan again.
                    // This time, hopefully he would let this goal go next time he replans..
                    backtrackToAgent = slowerAgent;
                    GoalsCompletionTime.Add(goalCompletion);
                }
            }
            else
            {
                GoalsCompletionTime.Add(goalCompletion);
            }
        }
Exemple #2
0
        public List <KeyValuePair <Predicate, int> > GetPrevGoalsCompletionTime(Constant agent, Problem problem)
        {
            List <KeyValuePair <Predicate, int> > alreadyCompleted = new List <KeyValuePair <Predicate, int> >();
            List <Predicate> goals = problem.GetGoals();

            foreach (var goal in goals)
            {
                GoalCompletionAtIteration history = GoalsCompletionTime.FindLast(x => x.Goal == goal && x.Agent != agent && !x.Invalid);

                if (history != null)
                {
                    alreadyCompleted.Add(new KeyValuePair <Predicate, int>(history.Goal, history.MinTime));
                }
            }
            return(alreadyCompleted);
        }