public void RepairThreat(IPlan plan, ThreatenedLinkFlaw tclf)
        {
            var cl     = tclf.causallink;
            var threat = tclf.threatener;

            if (threat is CompositePlanStep cps)
            {
                if (!plan.Orderings.IsPath(cps.InitialStep, cl.Tail))
                {
                    var promote = plan.Clone() as IPlan;
                    promote.ID += "pc";
                    if (cl.Tail.Name.Equals("DummyInit"))
                    {
                        promote.Orderings.Insert(cl.Tail.GoalCndt, cps.InitialStep);
                    }
                    promote.Orderings.Insert(cl.Tail, cps.InitialStep);
                    Insert(promote);
                }
                if (!plan.Orderings.IsPath(cl.Head, cps.GoalStep))
                {
                    var demote = plan.Clone() as IPlan;
                    demote.ID += "dc";
                    if (cl.Head.Name.Equals("DummyGoal"))
                    {
                        demote.Orderings.Insert(cps.GoalStep, cl.Head.InitCndt);
                    }
                    demote.Orderings.Insert(cps.GoalStep, cl.Head);
                    Insert(demote);
                }
            }
            else
            {
                // Promote
                if (!plan.Orderings.IsPath(threat, cl.Tail))
                {
                    var promote = plan.Clone() as IPlan;
                    promote.ID += "p";
                    if (cl.Tail.Name.Equals("DummyInit"))
                    {
                        promote.Orderings.Insert(cl.Tail.GoalCndt, threat);
                    }
                    promote.Orderings.Insert(cl.Tail, threat);
                    Insert(promote);
                }

                // Demote
                if (!plan.Orderings.IsPath(cl.Head, threat))
                {
                    var demote = plan.Clone() as IPlan;
                    demote.ID += "d";
                    if (cl.Head.Name.Equals("DummyGoal"))
                    {
                        demote.Orderings.Insert(threat, cl.Head.InitCndt);
                    }
                    demote.Orderings.Insert(threat, cl.Head);
                    Insert(demote);
                }
            }
        }
        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);
                }
            }
        }
        public async Task <ActionResult> ClonePlan(Guid id)
        {
            //let's clone the plan and redirect user to that cloned plan url
            var clonedPlan    = _plan.Clone(id);
            var baseUri       = Request.Url.GetLeftPart(UriPartial.Authority);
            var clonedPlanUrl = baseUri + "/dashboard/plans/" + clonedPlan.Id + "/builder?viewMode=kiosk&view=Collection";

            return(View("~/Views/Redirect/ClonePlan.cshtml", null, clonedPlanUrl));
        }
Exemple #4
0
        public List <IPlan> Process(IPlan planToBuildOn)
        {
            var newPlan = planToBuildOn.Clone() as IPlan;

            newPlan.CausalLinks.Add(thisConstraint);
            return(new List <IPlan>()
            {
                newPlan
            });
        }
 public void AddStep(IPlan plan)
 {
     foreach (var cndt in GetActions(plan.CurrentState as State))
     {
         var planClone = plan.Clone() as IPlan;
         var newStep   = new PlanStep(cndt.Clone() as IOperator);
         planClone.Insert(newStep);
         Insert(planClone);
     }
 }
        public void AddStep(IPlan plan, OpenCondition oc)
        {
            foreach (var cndt in CacheMaps.GetCndts(oc.precondition))
            {
                if (cndt == null)
                {
                    continue;
                }

                var planClone = plan.Clone() as IPlan;

                planClone.ID += "a";

                IPlanStep newStep;
                if (cndt.Height > 0)
                {
                    //continue;
                    var compCndt = cndt as Composite;
                    newStep = new CompositePlanStep(compCndt.Clone() as Composite)
                    {
                        Depth = oc.step.Depth
                    };
                    //planClone.Hdepth += compCndt.SubSteps.Count; // this is done now in beginning of Insert Decomp
                }
                else
                {
                    newStep = new PlanStep(cndt.Clone() as IOperator)
                    {
                        Depth = oc.step.Depth
                    };
                }

                // For debugging
                //planClone.ID += "(" + GroundActionFactory.GroundActions.IndexOf(newStep.Action) + ")";

                planClone.Insert(newStep);
                planClone.Repair(oc, newStep);

                if (oc.isDummyGoal)
                {
                    if (newStep.Height > 0)
                    {
                        var compNewStep = newStep as CompositePlanStep;
                        planClone.Orderings.Insert(oc.step.InitCndt, compNewStep.InitialStep);
                    }
                    else
                    {
                        planClone.Orderings.Insert(oc.step.InitCndt, newStep);
                    }
                }

                planClone.DetectThreats(newStep);
                Insert(planClone);
            }
        }
Exemple #7
0
 public PlanDO Clone(Guid planId)
 {
     if (_securityServices.AuthorizeActivity(PermissionType.ReadObject, planId, nameof(PlanNodeDO)))
     {
         return(_target.Clone(planId));
     }
     else
     {
         throw new HttpException(403, "You are not authorized to perform this activity!");
     }
 }
        public void RepairThreat(IPlan plan, ThreatenedLinkFlaw tclf)
        {
            var cl     = tclf.causallink;
            var threat = tclf.threatener;

            // Promote
            if (!plan.Orderings.IsPath(threat, cl.Tail))
            {
                var promote = plan.Clone() as IPlan;
                promote.Orderings.Insert(cl.Tail, threat);
                Insert(promote);
            }

            // Demote
            if (!plan.Orderings.IsPath(cl.Head, threat))
            {
                var demote = plan.Clone() as IPlan;
                demote.Orderings.Insert(threat, cl.Head);
                Insert(demote);
            }
        }
        public void AddStep(IPlan plan, OpenCondition oc)
        {
            foreach (var cndt in CacheMaps.GetCndts(oc.precondition))
            {
                if (cndt == null)
                {
                    continue;
                }

                var       planClone = plan.Clone() as IPlan;
                IPlanStep newStep;
                if (cndt.Height > 0)
                {
                    //continue;
                    var compCndt = cndt as IComposite;
                    newStep = new CompositePlanStep(compCndt.Clone() as IComposite)
                    {
                        Depth = oc.step.Depth
                    };
                }
                else
                {
                    newStep = new PlanStep(cndt.Clone() as IOperator)
                    {
                        Depth = oc.step.Depth
                    };
                }
                //newStep.Height = cndt.Height;

                planClone.Insert(newStep);
                planClone.Repair(oc, newStep);


                // check if inserting new Step (with orderings given by Repair) add cndts/risks to existing open conditions, affecting their status in the heap
                //planClone.Flaws.UpdateFlaws(planClone, newStep);

                if (oc.isDummyGoal)
                {
                    if (newStep.Height > 0)
                    {
                        var compNewStep = newStep as ICompositePlanStep;
                        planClone.Orderings.Insert(oc.step.InitCndt, compNewStep.InitialStep);
                    }
                    else
                    {
                        planClone.Orderings.Insert(oc.step.InitCndt, newStep);
                    }
                }
                planClone.DetectThreats(newStep);
                Insert(planClone);
            }
        }
        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);
                }
            }
        }
Exemple #11
0
        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);
        }
        public void AddStep(IPlan plan, OpenCondition oc)
        {
            foreach (var cndt in CacheMaps.GetCndts(oc.precondition))
            {
                var planClone = plan.Clone() as IPlan;
                var newStep   = new PlanStep(cndt.Clone() as IOperator);

                planClone.Insert(newStep);
                planClone.Repair(oc, newStep);

                // Check if inserting new Step (with orderings given by Repair) add cndts/risks to existing open conditions, affecting their status in the heap
                //planClone.Flaws.UpdateFlaws(planClone, newStep);

                // Detect if this new step threatens existing causal links
                planClone.DetectThreats(newStep);

                Insert(planClone);
            }
        }
        public IPlan Run(IPlan initPlan, ISearch SearchMethod, ISelection SelectMethod, float cutoff)
        {
            var directory = Parser.GetTopDirectory() + "/Results/";

            System.IO.Directory.CreateDirectory(directory);
            var POP = new PlannerScheduler(initPlan.Clone() as IPlan, SelectMethod, SearchMethod)
            {
                directory     = directory,
                problemNumber = 0
            };

            Debug.Log("Running plan-search");
            var Solutions = POP.Solve(1, cutoff);

            if (Solutions != null)
            {
                return(Solutions[0]);
            }
            Debug.Log(string.Format("explored: {0}, expanded: {1}", POP.Open, POP.Expanded));
            return(null);
        }
Exemple #14
0
        public void Reuse(IPlan plan, OpenCondition oc)
        {
            // If repaired by initial state


            var  index = plan.Steps.IndexOf(oc.step);
            bool found = false;

            for (int ind = index; ind >= 0; ind--)
            {
                if (plan.Steps[ind].Effects.Contains(oc.precondition))
                {
                    // Create child plan-space node
                    var planClone = plan.Clone() as IPlan;

                    // Make repair, check if new causal link is threatened
                    planClone.Repair(oc, plan.Steps[ind]);

                    // Insert plan as child on search frontier
                    Insert(planClone);
                    found = true;
                    break;
                }
            }
            if (!found)
            {
                var planClone = plan.Clone() as IPlan;
                planClone.Repair(oc, planClone.InitialStep);
                Insert(planClone);
                //if (plan.Initial.InState(oc.precondition))
                //{
                //    var planClone = plan.Clone() as IPlan;
                //    planClone.Repair(oc, planClone.InitialStep);
                //    Insert(planClone);

                //}
                //else
                //{
                //    throw new System.Exception();
                //}
            }

            //// 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 (step.Effects.Contains(oc.precondition)){

            //        // 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);
            //    }
            //}
        }
Exemple #15
0
        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);
                    }
                }
            }
        }
Exemple #16
0
        public new void AddStep(IPlan plan, OpenCondition oc)
        {
            long before = 0;
            var  watch  = System.Diagnostics.Stopwatch.StartNew();

            foreach (var cndt in CacheMaps.GetCndts(oc.precondition))
            {
                if (cndt == null)
                {
                    continue;
                }
                if (cndt.Height == 0)
                {
                    continue;
                }

                before = watch.ElapsedMilliseconds;


                var       planClone = plan.Clone() as PlanSchedule;
                IPlanStep newStep;
                if (cndt.Height > 0)
                {
                    //continue;
                    var compCndt = cndt as CompositeSchedule;
                    newStep = new CompositeSchedulePlanStep(compCndt.Clone() as IComposite, compCndt.Cntgs)
                    {
                        Depth = oc.step.Depth
                    };
                }
                else
                {
                    // only add composite steps...
                    //continue;
                    newStep = new PlanStep(cndt.Clone() as IOperator)
                    {
                        Depth = oc.step.Depth
                    };
                }
                LogTime("CloneCndt", watch.ElapsedMilliseconds - before);



                before = watch.ElapsedMilliseconds;
                planClone.Insert(newStep);
                LogTime("InsertDecomp", watch.ElapsedMilliseconds - before);

                //newStep.Height = cndt.Height;


                // planClone.Insert(newStep);


                before = watch.ElapsedMilliseconds;
                planClone.Repair(oc, newStep);
                LogTime("RepairDecomp", watch.ElapsedMilliseconds - before);

                // check if inserting new Step (with orderings given by Repair) add cndts/risks to existing open conditions, affecting their status in the heap
                //planClone.Flaws.UpdateFlaws(planClone, newStep);

                if (oc.isDummyGoal)
                {
                    if (newStep.Height > 0)
                    {
                        var compNewStep = newStep as CompositeSchedulePlanStep;
                        planClone.Orderings.Insert(oc.step.InitCndt, compNewStep.InitialStep);
                    }
                    else
                    {
                        planClone.Orderings.Insert(oc.step.InitCndt, newStep);
                    }
                }


                before = watch.ElapsedMilliseconds;
                planClone.DetectThreats(newStep);
                LogTime("DetectThreats", watch.ElapsedMilliseconds - before);

                before = watch.ElapsedMilliseconds;
                Insert(planClone);
                LogTime("InsertPlan", watch.ElapsedMilliseconds - before);
            }
        }
        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);
                    }
                }
            }
        }
Exemple #18
0
        public new void AddStep(IPlan plan, OpenCondition oc)
        {
            long before = 0;
            // check oc step depth.

            var watch = System.Diagnostics.Stopwatch.StartNew();

            foreach (var cndt in CacheMaps.GetCndts(oc.precondition))
            {
                if (cndt == null)
                {
                    continue;
                }
                if (cndt.Height == 0)
                {
                    continue;
                }

                before = watch.ElapsedMilliseconds;


                var planClone = plan.Clone() as PlanSchedule;
                //if (planClone.ID.Equals("1335"))
                //{
                //    Console.WriteLine("Here");
                //}

                planClone.ID += "a";
                IPlanStep newStep;
                if (cndt.Height > 0)
                {
                    //continue;
                    var compCndt = cndt as CompositeSchedule;
                    newStep = new CompositeSchedulePlanStep(compCndt.Clone() as CompositeSchedule)
                    {
                        Depth = oc.step.Depth
                    };
                }
                else
                {
                    // only add composite steps...
                    //continue;
                    newStep = new PlanStep(cndt.Clone() as IOperator)
                    {
                        Depth = oc.step.Depth
                    };
                }
                planClone.ID += "(" + GroundActionFactory.GroundActions.IndexOf(newStep.Action) + ")";
                LogTime("CloneCndt", watch.ElapsedMilliseconds - before);



                before = watch.ElapsedMilliseconds;
                planClone.Insert(newStep);
                LogTime("InsertDecomp", watch.ElapsedMilliseconds - before);

                //newStep.Height = cndt.Height;


                // planClone.Insert(newStep);


                before = watch.ElapsedMilliseconds;
                planClone.Repair(oc, newStep);
                LogTime("RepairDecomp", watch.ElapsedMilliseconds - before);

                // check if inserting new Step (with orderings given by Repair) add cndts/risks to existing open conditions, affecting their status in the heap
                //planClone.Flaws.UpdateFlaws(planClone, newStep);

                if (oc.isDummyGoal)
                {
                    if (newStep.Height > 0)
                    {
                        var compNewStep = newStep as CompositeSchedulePlanStep;
                        planClone.Orderings.Insert(oc.step.InitCndt, compNewStep.InitialStep);
                        //planClone.ID +=  string.Format("(^Oa[{0},{1}])", oc.step.InitCndt.ID, compNewStep.InitialStep.ID);
                    }
                    else
                    {
                        planClone.Orderings.Insert(oc.step.InitCndt, newStep);
                        //planClone.ID += string.Format("(^Oa[{0},{1}])", oc.step.InitCndt.ID, newStep.ID);
                    }
                }


                before = watch.ElapsedMilliseconds;
                planClone.DetectThreats(newStep);
                LogTime("DetectThreats", watch.ElapsedMilliseconds - before);

                before = watch.ElapsedMilliseconds;
                Insert(planClone);
                LogTime("InsertPlan", watch.ElapsedMilliseconds - before);
            }
        }
Exemple #19
0
        public new void RepairThreat(IPlan plan, ThreatenedLinkFlaw tclf)
        {
            var cl     = tclf.causallink;
            var threat = tclf.threatener;

            if (threat is CompositeSchedulePlanStep cps)
            {
                if (!plan.Orderings.IsPath(cps.InitialStep, cl.Tail))
                {
                    var promote = plan.Clone() as IPlan;
                    promote.ID += "p";

                    if (cl.Tail.Name.Equals("DummyInit"))
                    {
                        promote.Orderings.Insert(cl.Tail.GoalCndt, cps.InitialStep);
                    }

                    promote.Orderings.Insert(cl.Tail, cps.InitialStep);
                    // because no guaranteed ordering between head and tail
                    promote.Orderings.Insert(cl.Head, cps.InitialStep);
                    //promote.ID += string.Format("(^Opc[{0},{1}])", cl.Tail.ID, cps.InitialStep.ID);

                    Insert(promote);
                }
                if (!plan.Orderings.IsPath(cl.Head, cps.GoalStep))
                {
                    var demote = plan.Clone() as IPlan;
                    demote.ID += "d";

                    if (cl.Head.Name.Equals("DummyGoal"))
                    {
                        demote.Orderings.Insert(cps.GoalStep, cl.Head.InitCndt);
                    }
                    demote.Orderings.Insert(cps.GoalStep, cl.Head);
                    // because no guaranteed ordering between head and tail
                    demote.Orderings.Insert(cps.GoalStep, cl.Tail);
                    //demote.ID += string.Format("(^Odc[{0},{1}])", cps.GoalStep.ID, cl.Head.ID);

                    Insert(demote);
                }
            }
            else
            {
                // Promote
                if (!plan.Orderings.IsPath(threat, cl.Tail))
                {
                    var promote = plan.Clone() as IPlan;
                    promote.ID += "p";

                    if (cl.Tail.Name.Equals("DummyInit"))
                    {
                        promote.Orderings.Insert(cl.Tail.GoalCndt, threat);
                    }
                    promote.Orderings.Insert(cl.Tail, threat);
                    //promote.ID += string.Format("(^Op[{0},{1}])", cl.Tail.ID, threat.ID);
                    Insert(promote);
                }

                // Demote
                if (!plan.Orderings.IsPath(cl.Head, threat))
                {
                    var demote = plan.Clone() as IPlan;
                    demote.ID += "d";
                    if (cl.Head.Name.Equals("DummyGoal"))
                    {
                        demote.Orderings.Insert(threat, cl.Head.InitCndt);
                    }
                    demote.Orderings.Insert(threat, cl.Head);
                    //demote.Orderings.Insert(threat, cl.Tail);
                    //demote.ID += string.Format("(^Odp[{0},{1}])", threat.ID, cl.Head);
                    Insert(demote);
                }
            }
        }