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));
                }
            }
        }
Exemple #2
0
        public void RepairWithComposite(OpenCondition oc, CompositeSchedulePlanStep repairStep)
        {
            var needStep = Find(oc.step);

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


            // need to merge all steps that are being connected by this predicate:
            if (oc.precondition.Name.Equals("obs-starts"))
            //if (oc.precondition is ContextPredicate cxtp)
            {
                this.ID += "s";
                //var repairEff = repairStep.Effects.Where(e => cxtp.Equals(oc.precondition)).First() ;
                RepairWithMerge(oc.precondition, needStep, repairStep);
                var otherflawsFromSameNeedStep = this.flaws.OpenConditions.Where(openC => openC.step.ID == oc.step.ID).ToList();
                foreach (var otherFlaw in otherflawsFromSameNeedStep)
                {
                    if (CacheMaps.IsCndt(otherFlaw.precondition, repairStep))
                    {
                        // Remove this flaw, because it would have been satisfied by this repair step. SHOULD produce new plan for each decision.
                        this.flaws.OpenConditions.Remove(otherFlaw);
                    }
                }
                return;
            }
            //if (oc.precondition.Name.Equals("obs-starts"))
            //{
            //    Console.WriteLine("obs-starts");

            //}

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

            var clink = new CausalLink <IPlanStep>(oc.precondition as Predicate, 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 CompositeSchedulePlanStep;


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

                        if (!DeLinks.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(DeLinks.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 (DeLinks.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 (DeLinks.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));
                }
            }
        }