コード例 #1
0
ファイル: Constraints.cs プロジェクト: drwiner/BoltFreezer
 public bool Check()
 {
     if (!CacheMaps.IsCndt(thisConstraint.Predicate, thisConstraint.Head))
     {
         return(false);
     }
     return(true);
 }
コード例 #2
0
        public void Reuse(IPlan plan, OpenCondition oc)
        {
            // if repaired by initial state
            if (plan.Initial.InState(oc.precondition))
            {
                var planClone = plan.Clone() as IPlan;
                planClone.Repair(oc, planClone.InitialStep);
                Insert(planClone);
            }

            foreach (var step in plan.Steps)
            {
                if (oc.step.ID == step.ID)
                {
                    continue;
                }

                if (step.Height > 0)
                {
                    continue;
                }

                if (step == oc.step.InitCndt && oc.hasDummyInit)
                {
                    var planClone = plan.Clone() as IPlan;
                    planClone.Repair(oc, step);
                    Insert(planClone);
                    continue;
                }

                //if (step.Effects.Contains(oc.precondition))
                //{
                //    Console.Write("here");
                //}

                if (CacheMaps.IsCndt(oc.precondition, step))
                {
                    // before adding a repair, check if there is a path.
                    if (plan.Orderings.IsPath(oc.step, step))
                    {
                        continue;
                    }

                    var planClone = plan.Clone() as IPlan;
                    planClone.Repair(oc, step);
                    Insert(planClone);
                }
            }
        }
コード例 #3
0
ファイル: Constraints.cs プロジェクト: drwiner/BoltFreezer
        public List <IPlan> Process(IPlan planToBuildOn)
        {
            var newPlans = new List <IPlan>();

            foreach (var precon in thisConstraint.Second.Preconditions)
            {
                if (CacheMaps.IsCndt(precon, thisConstraint.First))
                {
                    var planClone = planToBuildOn.Clone() as IPlan;
                    planClone.CausalLinks.Add(new CausalLink <IPlanStep>(precon, thisConstraint.First, thisConstraint.Second));
                    newPlans.Add(planClone);
                }
            }
            return(newPlans);
        }
コード例 #4
0
        public void Reuse(IPlan plan, OpenCondition oc)
        {
            // If repaired by initial state
            if (plan.Initial.InState(oc.precondition))
            {
                var planClone = plan.Clone() as IPlan;
                planClone.Repair(oc, planClone.InitialStep);
                Insert(planClone);
            }

            // For each existing step, check if it is a candidate for repair
            foreach (var step in plan.Steps)
            {
                if (oc.step.ID == step.ID)
                {
                    continue;
                }

                if (CacheMaps.IsCndt(oc.precondition, step))
                {
                    // Before adding a repair, check if there is a path.
                    if (plan.Orderings.IsPath(oc.step, step))
                    {
                        continue;
                    }

                    // Create child plan-space node
                    var planClone = plan.Clone() as IPlan;

                    // Make repair, check if new causal link is threatened
                    planClone.Repair(oc, step);

                    // Insert plan as child on search frontier
                    Insert(planClone);
                }
            }
        }
コード例 #5
0
ファイル: PlannerScheduler.cs プロジェクト: drwiner/GDPOPS
        public new void Reuse(IPlan plan, OpenCondition oc)
        {
            // if repaired by initial state
            if (plan.Initial.InState(oc.precondition))
            {
                var planClone = plan.Clone() as IPlan;
                planClone.Repair(oc, planClone.InitialStep);
                planClone.ID += "ri";
                Insert(planClone);
            }

            foreach (var step in plan.Steps)
            {
                if (oc.step.ID == step.ID)
                {
                    continue;
                }

                if (step.Height > 0)
                {
                    if (CacheMaps.IsCndt(oc.precondition, step))
                    {
                        var stepAsComposite = step as CompositeSchedulePlanStep;

                        if (stepAsComposite.SubSteps.Contains(oc.step))
                        {
                            continue;
                        }
                        // before adding a repair, check if there is a path.
                        if (plan.Orderings.IsPath(oc.step, stepAsComposite.GoalStep))
                        {
                            continue;
                        }

                        if (plan.Orderings.IsPath(oc.step, stepAsComposite.InitialStep))
                        {
                            continue;
                        }

                        var planClone = plan.Clone() as IPlan;
                        //if (planClone.ID.Equals("1335a"))
                        //{
                        //    Console.WriteLine("Here");
                        //}
                        // need to modify stepAsComposite, so going to rereference on cloned plan.
                        var stepAsCompositeClone = planClone.Steps.First(s => s.ID == stepAsComposite.ID) as CompositeSchedulePlanStep;
                        planClone.Repair(oc, stepAsCompositeClone);
                        planClone.ID += "r";
                        Insert(planClone);
                    }
                    continue;
                }
                else
                {
                    if (step == oc.step.InitCndt && oc.hasDummyInit)
                    {
                        var planClone = plan.Clone() as IPlan;
                        planClone.Repair(oc, step);
                        planClone.ID += "r_";
                        Insert(planClone);
                        continue;
                    }

                    if (CacheMaps.IsCndt(oc.precondition, step))
                    {
                        // before adding a repair, check if there is a path.
                        if (plan.Orderings.IsPath(oc.step, step))
                        {
                            continue;
                        }

                        var planClone = plan.Clone() as IPlan;
                        planClone.Repair(oc, step);
                        planClone.ID += "r";
                        Insert(planClone);
                    }
                }
            }
        }
コード例 #6
0
ファイル: PlanSchedule.cs プロジェクト: drwiner/GDPOPS
        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));
                }
            }
        }
コード例 #7
0
        public void Reuse(IPlan plan, OpenCondition oc)
        {
            // if repaired by initial state
            if (plan.Initial.InState(oc.precondition))
            {
                var planClone = plan.Clone() as IPlan;
                planClone.Repair(oc, planClone.InitialStep);
                planClone.ID += "ri";
                Insert(planClone);
            }

            foreach (var step in plan.Steps)
            {
                if (oc.step.ID == step.ID)
                {
                    continue;
                }

                if (step.Height > 0)
                {
                    if (CacheMaps.IsCndt(oc.precondition, step))
                    {
                        var stepAsComposite = step as CompositePlanStep;



                        if (stepAsComposite.SubSteps.Contains(oc.step) || stepAsComposite.GoalStep.ID == oc.step.ID)
                        {
                            continue;
                        }
                        // before adding a repair, check if there is a path.
                        if (plan.Orderings.IsPath(oc.step, stepAsComposite.GoalStep))
                        {
                            continue;
                        }

                        if (plan.Orderings.IsPath(oc.step, stepAsComposite.InitialStep))
                        {
                            continue;
                        }


                        var planClone            = plan.Clone() as IPlan;
                        var stepAsCompositeClone = planClone.Steps.First(s => s.ID == stepAsComposite.ID) as CompositePlanStep;

                        planClone.Repair(oc, stepAsCompositeClone);
                        planClone.ID += "rc";
                        Insert(planClone);
                    }
                    continue;
                }
                else
                {
                    if (step == oc.step.InitCndt && oc.hasDummyInit)
                    {
                        var planClone = plan.Clone() as IPlan;
                        planClone.Repair(oc, step);
                        planClone.ID += "r_";
                        Insert(planClone);
                        continue;
                    }

                    if (CacheMaps.IsCndt(oc.precondition, step))
                    {
                        // before adding a repair, check if there is a path.
                        if (plan.Orderings.IsPath(oc.step, step))
                        {
                            continue;
                        }

                        var planClone = plan.Clone() as IPlan;
                        planClone.Repair(oc, step);
                        planClone.ID += "rp";
                        Insert(planClone);
                    }
                }
            }
        }