Esempio n. 1
0
        public new System.Object Clone()
        {
            var CompositeBase = base.Clone() as Composite;
            var newCntgs      = new List <Tuple <IPlanStep, IPlanStep> >();

            foreach (var cntg in Cntgs)
            {
                newCntgs.Add(cntg);
            }
            var theClone = new CompositeSchedule(CompositeBase, newCntgs);

            return(theClone);
        }
Esempio n. 2
0
        public static List <CompositeSchedule> GroundDecompositionsToCompositeSteps(List <UnityTimelineDecomp> DecompositionSchemata)
        {
            var compositeSteps = new List <CompositeSchedule>();

            foreach (var decompschema in DecompositionSchemata)
            {
                foreach (var gdecomp in decompschema.GroundDecomps)
                {
                    // use the fabulaActionNameMap to reference action var names to substeps
                    //var obseffects = new List<Tuple<CamPlanStep, List<Tuple<double, double>>>>();
                    // keeping track of every action's percentage observance
                    var actionPercentDict = new Dictionary <int, List <Tuple <double, double> > >();

                    // gdecomp.fabulaActionNameMap[action.Name]

                    for (int i = 0; i < gdecomp.discourseSubSteps.Count; i++)
                    {
                        var shot = gdecomp.discourseSubSteps[i];
                        foreach (var actionseg in shot.TargetDetails.ActionSegs)
                        {
                            var actionsubstep = gdecomp.fabulaActionNameMap[actionseg.actionVarName];
                            if (!actionPercentDict.ContainsKey(actionsubstep.ID))
                            {
                                actionPercentDict[actionsubstep.ID] = new List <Tuple <double, double> >();
                            }
                            actionPercentDict[actionsubstep.ID].Add(new Tuple <double, double>(actionseg.startPercent, actionseg.endPercent));
                        }
                    }

                    // Track which intervals of actions are missing.
                    var missingIntervalsInActions = new List <Tuple <IPlanStep, List <Tuple <double, double> > > >();

                    // Track which steps are not observed to start or end
                    List <IPlanStep> StepsObservedToStart    = new List <IPlanStep>();
                    List <IPlanStep> StepsNotObservedToStart = new List <IPlanStep>();
                    List <IPlanStep> StepsNotObservedToEnd   = new List <IPlanStep>();
                    //List<IPlanStep> StepsObservedToEnd = new List<IPlanStep>();

                    double latestTimeAccountedFor;
                    bool   observedEnding;
                    var    observedEffectsList = new List <IPredicate>();
                    for (int i = 0; i < gdecomp.SubSteps.Count; i++)
                    //foreach (var action in gdecomp.SubSteps)
                    {
                        var action = gdecomp.SubSteps[i];
                        // Reset latest time accounted for
                        latestTimeAccountedFor = 0;

                        var missingTimes     = new List <Tuple <double, double> >();
                        var actionTuplesList = actionPercentDict[action.ID];
                        observedEnding = true;
                        for (int j = 0; j < actionTuplesList.Count; j++)
                        {
                            // Access action percent tuple
                            var actionsegTuple = actionTuplesList[j];

                            // Check if not observed to start
                            if (j == 0 && actionsegTuple.First > 0.06)
                            {
                                StepsNotObservedToStart.Add(action);
                            }
                            else if (i == 0 && j == 0 && actionsegTuple.First <= 0.06)
                            {
                                StepsObservedToStart.Add(action);
                                //else
                                //{
                                //    List<IPredicate> actionPreconditions = action.Preconditions.ToList();
                                //    for(int k = i-1; k >= 0; k--)
                                //    {
                                //        var priorAction = gdecomp.SubSteps[k];
                                //        foreach(var eff in priorAction.Effects)
                                //        {
                                //            if (actionPreconditions.Contains(eff))
                                //            {
                                //                // create a d-link
                                //                var dlinkPred = new Predicate("obs", new List<ITerm>() { eff as ITerm }, true);
                                //                var newDLink = new CausalLink<CamPlanStep>(dlinkPred as IPredicate, )
                                //            }
                                //        }
                                //    }
                                //}
                            }

                            // Check if missing interval
                            if (actionsegTuple.First > latestTimeAccountedFor + 0.06)
                            {
                                // then there is missing time.
                                var missingTime = new Tuple <double, double>(latestTimeAccountedFor, actionsegTuple.First);
                                missingTimes.Add(missingTime);
                            }

                            // Check if not observed to end
                            if (j == actionTuplesList.Count - 1 && actionsegTuple.Second < 1 - 0.06)
                            {
                                StepsNotObservedToEnd.Add(action);
                                observedEnding = false;
                            }

                            // Update latest time in action account for.
                            latestTimeAccountedFor = actionsegTuple.Second;
                        }

                        if (observedEnding)
                        {
                            foreach (var eff in action.Effects)
                            {
                                var reversedEff = eff.GetReversed();
                                if (observedEffectsList.Contains(reversedEff))
                                {
                                    observedEffectsList.Remove(reversedEff);
                                }
                                {
                                    observedEffectsList.Add(eff);
                                }
                            }

                            // Add missing times per action to list of tuples
                            missingIntervalsInActions.Add(new Tuple <IPlanStep, List <Tuple <double, double> > >(action, missingTimes));
                        }
                    }

                    /* Preconditions
                     *
                     * foreach action  that is not observed to start, give precondition to observe its start
                     * foreach action that IS observed to start, and is the first step observed
                     */

                    var preconditions = CreatePredicatesWithStepTermsViaName(StepsNotObservedToStart, "obs-starts");
                    foreach (var stepAction in StepsObservedToStart)
                    {
                        foreach (var precon in stepAction.Preconditions)
                        {
                            var obsTerm = new Predicate("obs", new List <ITerm>()
                            {
                                precon as ITerm
                            }, true);
                            preconditions.Add(obsTerm);
                            preconditions.Add(precon);
                        }
                    }

                    /* Effects
                     *
                     * foreach action that is NOT observed to end, give effect that we observed it start
                     * foreach action that IS observed to end, give effect that we observed its effects
                     */

                    var effects = CreatePredicatesWithStepTermsViaName(StepsNotObservedToEnd, "obs-starts");
                    foreach (var observedEffect in observedEffectsList)
                    {
                        // cast predicate as term?
                        var obsTerm = new Predicate("obs", new List <ITerm>()
                        {
                            observedEffect as ITerm
                        }, true);
                        effects.Add(obsTerm);
                        effects.Add(observedEffect);
                    }

                    // Create a composite step
                    var compOp = new Operator(decompschema.name, preconditions, effects);
                    compOp.Height        = 1;
                    compOp.NonEqualities = new List <List <ITerm> >();
                    var comp = new CompositeSchedule(compOp);
                    comp.ApplyDecomposition(gdecomp.Clone() as TimelineDecomposition);

                    // Add new composite step to list and add its string component to displayable gameobject component
                    compositeSteps.Add(comp);
                }
            }
            return(compositeSteps);
        }
 public CompositeSchedulePlanStep(CompositeSchedule comp) : base(comp as Composite)
 {
     Cntgs = comp.Cntgs;
 }