Example #1
0
        // used for initialization
        public TimelineDecomposition(IOperator core, List <IPredicate> literals,
                                     List <Tuple <IPlanStep, IPlanStep> > fcntgs, List <Tuple <CamPlanStep, CamPlanStep> > dcntgs,
                                     List <Tuple <string, Tuple <PlanStep, PlanStep> > > fconstraints, List <Tuple <string, Tuple <CamPlanStep, CamPlanStep> > > dconstraints,
                                     List <IPlanStep> substeps, List <CamPlanStep> camSteps,
                                     List <Tuple <IPlanStep, IPlanStep> > suborderings, List <Tuple <CamPlanStep, CamPlanStep> > dOrderings,
                                     List <CausalLink <IPlanStep> > sublinks, List <CausalLink <CamPlanStep> > dLinks,
                                     Dictionary <string, PlanStep> fabulaStepVariableNameDictionary)
            : base(core, literals, substeps, suborderings, sublinks)
        {
            fabCntgs            = fcntgs;
            discCntgs           = dcntgs;
            fabConstraints      = fconstraints;
            discourseSubSteps   = camSteps;
            discConstraints     = dconstraints;
            discOrderings       = dOrderings;
            discLinks           = dLinks;
            fabulaActionNameMap = fabulaStepVariableNameDictionary;

            // to be updated after grounding or adding connectives
            InitialCamAction = discourseSubSteps[0];
            FinalCamAction   = discourseSubSteps[discourseSubSteps.Count - 1];

            // to beupdated after grounding regular actions
            InitialActionSeg = InitialCamAction.TargetDetails.ActionSegs[0];
            FinalActionSeg   = FinalCamAction.TargetDetails.ActionSegs[FinalCamAction.TargetDetails.ActionSegs.Count - 1];

            // to be instantiated after grounding actions
            InitialAction = new PlanStep();
            FinalAction   = new PlanStep();
        }
Example #2
0
 public TimelineDecomposition() : base()
 {
     fabCntgs          = new List <Tuple <IPlanStep, IPlanStep> >();
     discCntgs         = new List <Tuple <CamPlanStep, CamPlanStep> >();
     discourseSubSteps = new List <CamPlanStep>();
     InitialActionSeg  = new ActionSeg();
     FinalActionSeg    = new ActionSeg();
     InitialAction     = new PlanStep();
     FinalAction       = new PlanStep();
     InitialCamAction  = new CamPlanStep();
     FinalCamAction    = new CamPlanStep();
 }
Example #3
0
        public void InsertDecomp(CompositeSchedulePlanStep newStep)
        {
            var IDMap = new Dictionary <int, IPlanStep>();

            // Clone, Add, and Order Initial step
            var dummyInit = new PlanStep(newStep.InitialStep) as IPlanStep;

            dummyInit.InitCndt = newStep.InitialStep.InitCndt;

            dummyInit.Depth = newStep.Depth;
            IDMap[newStep.InitialStep.ID] = dummyInit;
            Steps.Add(dummyInit);
            Orderings.Insert(InitialStep, dummyInit);
            Orderings.Insert(dummyInit, GoalStep);


            // Clone, Add, and order Goal step
            var dummyGoal = new PlanStep(newStep.GoalStep) as IPlanStep;

            dummyGoal.Depth    = newStep.Depth;
            dummyGoal.InitCndt = dummyInit;
            dummyGoal.GoalCndt = newStep.GoalStep.GoalCndt;
            InsertPrimitiveSubstep(dummyGoal, dummyInit.Effects, true);
            IDMap[newStep.GoalStep.ID] = dummyGoal;
            Orderings.Insert(dummyInit, dummyGoal);

            dummyInit.GoalCndt = dummyGoal;

            //this.ID += "([" + dummyInit.ID.ToString() + ',' + dummyGoal.ID.ToString() + "])";


            // needs same operator ID as newStep, in order to still be referenced for primary-effect-based open conditions
            //var newStepCopy = new CompositeSchedulePlanStep(new Operator(newStep.Action.Predicate.Name, newStep.Action.Terms, new Hashtable(), new List<IPredicate>(), new List<IPredicate>(), newStep.Action.ID));
            Steps.Add(newStep);

            //newStepCopy.Height = newStep.Height;
            //newStepCopy.Depth = newStep.Depth;
            var newSubSteps = new List <IPlanStep>();

            newStep.Preconditions = new List <IPredicate>();
            newStep.Effects       = new List <IPredicate>();

            newStep.InitialStep = dummyInit;
            newStep.GoalStep    = dummyGoal;

            DeLinks.Insert(newStep, dummyGoal);
            DeLinks.Insert(newStep, dummyInit);

            //newStepCopy.InitialStep = dummyInit;
            //newStepCopy.GoalStep = dummyGoal;

            var newCamPlanSteps = new List <CamPlanStep>();

            foreach (var substep in newStep.SubSteps)
            {
                // substep is either a IPlanStep or ICompositePlanStep
                if (substep.Height > 0)
                {
                    var compositeSubStep = new CompositeSchedulePlanStep(substep.Clone() as CompositeSchedulePlanStep)
                    {
                        Depth = newStep.Depth + 1
                    };

                    // Avoid the following issue: compositeSubStep's initial and goal step will be reassigned its ID AFTER it is inserted; thus, insert first
                    newSubSteps.Add(compositeSubStep);
                    DeLinks.Insert(newStep, compositeSubStep);
                    Insert(compositeSubStep);

                    Orderings.Insert(compositeSubStep.GoalStep, dummyGoal);
                    Orderings.Insert(dummyInit, compositeSubStep.InitialStep);

                    //this.ID += "(^Oss[" + compositeSubStep.GoalStep.ID.ToString() + ',' + dummyGoal.ID.ToString() + "])";
                    //   this.ID += "(^Oss[" + dummyInit.ID.ToString() + ',' + compositeSubStep.InitialStep.ID.ToString() + "])";

                    IDMap[substep.ID] = compositeSubStep;

                    // The initial step of the sub-step looks to this local-subplan's dummy init as it's init cndt
                    compositeSubStep.InitialStep.InitCndt = dummyInit;
                    // The goal step of the sub-step looks to this local sub-plan's dummy goal step as it's goal candidate
                    compositeSubStep.GoalStep.GoalCndt = dummyGoal;
                }
                else
                {
                    IPlanStep newsubstep;
                    // new substep is either CamPlanStep or PlanStep
                    if (substep is CamPlanStep cps)
                    {
                        newsubstep = new CamPlanStep(cps)
                        {
                            Depth = newStep.Depth + 1
                        };
                        newCamPlanSteps.Add(newsubstep as CamPlanStep);
                    }
                    else
                    {
                        newsubstep = new PlanStep(substep.Clone() as IPlanStep)
                        {
                            Depth = newStep.Depth + 1
                        };
                    }

                    Orderings.Insert(newsubstep, dummyGoal);
                    Orderings.Insert(dummyInit, newsubstep);
                    IDMap[substep.ID] = newsubstep;
                    newSubSteps.Add(newsubstep);
                    newsubstep.InitCndt = dummyInit;
                    newsubstep.GoalCndt = dummyGoal;
                    //newsubstep.Parent = newStep;
                    DeLinks.Insert(newStep, newsubstep);

                    InsertPrimitiveSubstep(newsubstep, dummyInit.Effects, false);

                    // Pre-Mod
                    //if (newsubstep.Depth > Hdepth)
                    //{
                    //    Hdepth = newsubstep.Depth;
                    //}
                }
            }

            newStep.InitialAction = IDMap[newStep.InitialAction.ID];
            if (newStep.InitialAction is CompositeSchedulePlanStep cspsNewStep)
            {
                newStep.InitialCamAction = cspsNewStep.InitialCamAction;
            }
            else
            {
                newStep.InitialCamAction = IDMap[newStep.InitialCamAction.ID] as CamPlanStep;
            }

            newStep.FinalAction = IDMap[newStep.FinalAction.ID];

            if (newStep.FinalAction is CompositeSchedulePlanStep cspsNewStepf)
            {
                newStep.FinalCamAction = cspsNewStepf.FinalCamAction;
            }
            else
            {
                newStep.FinalCamAction = IDMap[newStep.FinalCamAction.ID] as CamPlanStep;
            }

            // update action seg targets
            foreach (var cps in newCamPlanSteps)
            {
                cps.UpdateActionSegs(IDMap);
            }

            //foreach (var precon in newStep.ContextPrecons)
            //{
            //    // these precons MUST be referencing a local sub-step; or else, they reference a precondition or effect of a sub-step.
            //    precon.ActionRef = IDMap[precon.ActionRef.ID];
            //}
            //foreach (var eff in newStep.ContextEffects)
            //{
            //    eff.ActionRef = IDMap[eff.ActionRef.ID];
            //}

            //foreach(var precon in )

            foreach (var tupleOrdering in newStep.SubOrderings)
            {
                // Don't bother adding orderings to dummies
                if (tupleOrdering.First.Equals(newStep.InitialStep))
                {
                    continue;
                }
                if (tupleOrdering.Second.Equals(newStep.GoalStep))
                {
                    continue;
                }

                var head = IDMap[tupleOrdering.First.ID];
                var tail = IDMap[tupleOrdering.Second.ID];
                if (head.Height > 0)
                {
                    // can you pass it back?
                    var temp = head as CompositeSchedulePlanStep;
                    head = temp.GoalStep as IPlanStep;
                }
                if (tail.Height > 0)
                {
                    var temp = tail as CompositeSchedulePlanStep;
                    tail = temp.InitialStep as IPlanStep;
                }
                //this.ID += string.Format("(^Oso[{0},{1}])", head.ID, tail.ID);
                Orderings.Insert(head, tail);
            }

            // in this world, all composite plan steps are composite schedule plan steps.
            var schedulingStepComponent = newStep as CompositeSchedulePlanStep;

            foreach (var cntg in schedulingStepComponent.Cntgs)
            {
                var head = IDMap[cntg.First.ID];
                var tail = IDMap[cntg.Second.ID];
                if (head.Height > 0)
                {
                    // how do we describe a composite as being contiguous with another step?
                    var temp = head as CompositeSchedulePlanStep;
                    //var fas = temp.FinalActionSeg;
                    if (tail is CamPlanStep cps)
                    {
                        // then get final discourse step of temp // This is a HACK - because the last camera substep may be on a grandchild
                        head = temp.FinalCamAction as IPlanStep;
                    }
                    else
                    {
                        // then get the action referenced by the final action segment - already updated actionID and is already in plan.
                        head = temp.FinalAction;
                    }
                }
                if (tail.Height > 0)
                {
                    var temp = tail as CompositeSchedulePlanStep;
                    if (head is CamPlanStep cps)
                    {
                        // then get first discourse step of temp // This is a HACK - because the first camera substep may be on a grandchild
                        tail = temp.InitialCamAction;
                    }
                    else
                    {
                        tail = temp.InitialAction;
                    }
                }
                Cntgs.Insert(head, tail);
                // also add orderings just in case
                Orderings.Insert(head, tail);
                // this.ID += string.Format("(^Osc[{0},{1}])", head.ID, tail.ID);
            }

            foreach (var clink in newStep.SubLinks)
            {
                var head = IDMap[clink.Head.ID];
                var tail = IDMap[clink.Tail.ID];


                if (head.Height > 0)
                {
                    var temp = head as CompositeSchedulePlanStep;
                    head = temp.GoalStep as IPlanStep;
                }
                if (tail.Height > 0)
                {
                    var temp = tail as CompositeSchedulePlanStep;
                    tail = temp.InitialStep as IPlanStep;
                }

                var newclink = new CausalLink <IPlanStep>(clink.Predicate, head, tail);
                CausalLinks.Add(newclink);
                Orderings.Insert(head, tail);
                //this.ID += string.Format("(^Osl[{0},{1}])", head.ID, tail.ID);

                // check if this causal links is threatened by a step in subplan
                foreach (var step in newSubSteps)
                {
                    // Prerequisite criteria 1
                    if (step.ID == head.ID || step.ID == tail.ID)
                    {
                        continue;
                    }

                    // Prerequisite criteria 2
                    if (!CacheMaps.IsThreat(clink.Predicate, step))
                    {
                        continue;
                    }

                    // If the step has height, need to evaluate differently
                    if (step.Height > 0)
                    {
                        var temp = step as ICompositePlanStep;
                        if (Orderings.IsPath(head, temp.InitialStep))
                        {
                            continue;
                        }
                        if (Orderings.IsPath(temp.GoalStep, tail))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        if (Orderings.IsPath(head, step))
                        {
                            continue;
                        }
                        if (Orderings.IsPath(step, tail))
                        {
                            continue;
                        }
                    }

                    Flaws.Add(new ThreatenedLinkFlaw(newclink, step));
                    //if (step.Height > 0)
                    //{
                    //    // Then we need to dig deeper to find the step that threatens
                    //    DecomposeThreat(clink, step as ICompositePlanStep);
                    //}
                    //else
                    //{
                    //    Flaws.Add(new ThreatenedLinkFlaw(newclink, step));
                    //}
                }
            }


            // This is needed because we'll check if these substeps are threatening links
            newStep.SubSteps = newSubSteps;
            //newStepCopy.SubSteps = newSubSteps;
            // inital


            newStep.InitialStep = dummyInit;

            // goal

            newStep.GoalStep = dummyGoal;

            foreach (var pre in newStep.OpenConditions)
            {
                Flaws.Add(this, new OpenCondition(pre, dummyInit as IPlanStep));
            }
        }