Пример #1
0
        public void RepairWithComposite(OpenCondition oc, CompositePlanStep repairStep)
        {
            var needStep = Find(oc.step);

            if (!needStep.Name.Equals("DummyGoal") && !needStep.Name.Equals("DummyInit"))
            {
                needStep.Fulfill(oc.precondition);
            }

            orderings.Insert(repairStep.GoalStep as IPlanStep, needStep);
            //this.ID += string.Format("(^Orl[{0},{1}])", repairStep.GoalStep.ID, needStep.ID);

            // Causal Link between repair step's goal condition and need step.
            var clink = new CausalLink <IPlanStep>(oc.precondition, repairStep.GoalStep as IPlanStep, needStep);

            causalLinks.Add(clink);

            foreach (var step in Steps)
            {
                if (step.ID == repairStep.ID || step.ID == needStep.ID)
                {
                    continue;
                }
                if (!CacheMaps.IsThreat(oc.precondition, step))
                {
                    continue;
                }

                if (step.Height > 0)
                {
                    // we need to check that this step's goal step
                    var stepAsComp = step as CompositePlanStep;


                    if (decomplinks.OnDecompPath(clink.Head, step.ID))
                    {
                        // must be ordered within
                        if (Orderings.IsPath(clink.Tail, stepAsComp.GoalStep))
                        {
                            // already tucked into Q's borders
                            continue;
                        }

                        if (!decomplinks.OnDecompPath(clink.Tail, step.ID))
                        {
                            // Special Case is when clink.Tail is goal step. Then we cannot tuck clink.Tail into borders.
                            if (clink.Tail.Equals(goalStep))
                            {
                                // We want to end this plan's existence, so we add a threat that cannot be resolved.
                                Flaws.Add(new ThreatenedLinkFlaw(clink, step));
                                continue;
                            }
                            // Q --> s -p-> t, not p in eff(Q), not Q --> t
                            // then, need to tuck t into Q's borders.

                            var tailRoot = GetStepByID(decomplinks.GetRoot(clink.Tail)) as CompositePlanStep;
                            Orderings.Insert(tailRoot.GoalStep, stepAsComp.InitialStep);
                            //this.ID += string.Format("(^Od[{0},{1}])", tailRoot.GoalStep.ID, stepAsComp.InitialStep.ID);
                        }

                        continue;
                    }

                    if (decomplinks.OnDecompPath(clink.Tail, step.ID))
                    {
                        // step cannot threaten
                        continue;
                    }


                    // step is a threat to need precondition
                    if (Orderings.IsPath(clink.Tail, stepAsComp.InitialStep))
                    {
                        continue;
                    }
                    if (Orderings.IsPath(stepAsComp.GoalStep, repairStep.InitialStep as IPlanStep))
                    {
                        continue;
                    }


                    Flaws.Add(new ThreatenedLinkFlaw(clink, stepAsComp));
                    // Flaws.Add(new ThreatenedLinkFlaw(clink, compInit));
                }

                else
                {
                    // is it possible that step is a sub-step of repair step? Yes it is.
                    if (decomplinks.OnDecompPath(step, repairStep.ID))
                    {
                        // but, there's nothing we can do about it; and all links to repairStep.GoalStep are there to be threatened
                        continue;
                    }

                    // step is a threat to need precondition
                    if (Orderings.IsPath(needStep, step))
                    {
                        continue;
                    }
                    if (Orderings.IsPath(step, repairStep.InitialStep as IPlanStep))
                    {
                        continue;
                    }

                    Flaws.Add(new ThreatenedLinkFlaw(clink, step));
                }
            }
        }
Пример #2
0
        public void RepairWithMerge(IPredicate neededCondition, IPlanStep needStep, CompositeSchedulePlanStep repairStep)
        //public void RepairWithMerge(ContextPredicate neededCondition, ContextPredicate producedCondition, IPlanStep needStep, CompositeSchedulePlanStep repairStep)
        {
            // needStep is initialStep;
            var needStepComposite       = GetStepByID(DeLinks.GetParent(needStep)) as CompositeSchedulePlanStep;
            var subStepTermID           = neededCondition.Terms[0].Constant;
            var stepThatNeedsToBeMerged = GetStepByID(DeLinks.GetSubSteps(needStepComposite).Single(sid => GetStepByID(sid).Action.ID.ToString().Equals(subStepTermID)));
            //var stepThatNeedsToBeMerged = needStepComposite.SubSteps.Where(s => s.Action.ID.ToString().Equals(subStepTermID)).First();
            //var stepThatNeedsToBeMerged = neededCondition.ActionRef;
            var stepThatDoesMerging = GetStepByID(DeLinks.GetSubSteps(repairStep).Single(sid => GetStepByID(sid).Action.ID.ToString().Equals(subStepTermID)));

            //var stepThatDoesMerging = repairStep.SubSteps.Where(s => s.Action.ID.ToString().Equals(subStepTermID)).First();

            // We assume that no timeline decomposition contains the same exact sub-step twice.

            //var stepThatDoesMerging = producedCondition.ActionRef;

            // In case the sub-step has been merged, find the most recent reference
            //var getID = MM.FindRoot(stepThatDoesMerging.ID);
            //if (getID != stepThatDoesMerging.ID)
            //{
            //    stepThatDoesMerging = Steps.Where(s => s.ID == getID).First();
            //}

            //getID = MM.FindRoot(stepThatNeedsToBeMerged.ID);
            //if (getID != stepThatNeedsToBeMerged.ID)
            //{
            //    stepThatNeedsToBeMerged = Steps.Where(s => s.ID == getID).First();
            //}

            // rewrite the produced sub-step
            RewrittenAs(stepThatNeedsToBeMerged, stepThatDoesMerging);
            //MergeSteps(stepThatDoesMerging, stepThatNeedsToBeMerged);

            // get the produced step's decompositional root
            var repairStepRoot = GetStepByID(DeLinks.GetRoot(repairStep)) as CompositePlanStep;

            // removed the consumed rewritten sub-step
            DeLinks.RemoveSubStep(needStepComposite, stepThatNeedsToBeMerged);
            //needStepComposite.SubSteps.Remove(stepThatNeedsToBeMerged);

            // add decomp link to produced step's root
            DeLinks.Insert(needStepComposite, repairStepRoot);
            //repairStepRoot.Parent = needStepComposite;
            //needStepComposite.SubSteps.Add(repairStepRoot);

            // Add orderings to keep repair Step within decompositional borders
            Orderings.Insert(needStepComposite.InitialStep, repairStepRoot.InitialStep);
            //this.ID += string.Format("(^Om[{0},{1}])", needStepComposite.InitialStep.ID, repairStepRoot.InitialStep.ID);
            Orderings.Insert(repairStepRoot.GoalStep, needStepComposite.GoalStep);
            //this.ID += string.Format("(^Om[{0},{1}])", repairStepRoot.GoalStep.ID, needStepComposite.GoalStep.ID);

            Orderings.Insert(needStepComposite.InitialStep, repairStep.InitialStep);
            Orderings.Insert(repairStep.GoalStep, needStepComposite.GoalStep);

            // the needstep camera schedule sub-steps may not be ordered relative to the action being merged.
            foreach (var needCamSubStep in needStepComposite.CamScheduleSubSteps)
            {
                Orderings.Insert(repairStep.GoalStep, needCamSubStep);
                //this.ID += string.Format("(^Ocams[{0},{1}])", needCamSubStep.ID, repairStep.InitialStep.ID);
                //foreach (var repairCamSubStep in repairStep.CamScheduleSubSteps)
                //{
                //    Orderings.Insert(repairCamSubStep, needCamSubStep);
                //    this.ID += string.Format("(^Ocams[{0},{1}])", repairCamSubStep.ID, needCamSubStep.ID);
                //}
            }
        }