private StepResult ExecuteStep(IPlanStep step, string databaseName, out int rowCount) { var result = step.GetResult(_process, databaseName); rowCount = result.Rows.Count; return(result); }
// 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(); }
public void DetectThreats(IPlanStep possibleThreat) { foreach (var clink in causalLinks) { // Let it be for now that a newly inserted step cannot already be in a causal link in the plan (a head or tail). If not true, then check first. if (clink.Head.ID == possibleThreat.ID || clink.Tail.ID == possibleThreat.ID) { continue; } if (!CacheMaps.IsThreat(clink.Predicate, possibleThreat)) { continue; } // new step can possibly threaten if (Orderings.IsPath(clink.Tail as IPlanStep, possibleThreat)) { continue; } if (Orderings.IsPath(possibleThreat, clink.Head as IPlanStep)) { continue; } Flaws.Add(new ThreatenedLinkFlaw(clink, possibleThreat)); } }
public void Repair(OpenCondition oc, IPlanStep repairStep) { // oc = <needStep, needPrecond>. Need to find needStep in plan, because open conditions have been mutated before arrival. var needStep = Find(oc.step); needStep.Fulfill(oc.precondition); orderings.Insert(repairStep, needStep); var clink = new CausalLink <IPlanStep>(oc.precondition as Predicate, repairStep, 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; } // step is a threat to need precondition if (Orderings.IsPath(needStep, step)) { continue; } if (Orderings.IsPath(step, repairStep)) { continue; } Flaws.Add(new ThreatenedLinkFlaw(clink, step)); } }
public void InsertPrimitiveSubstep(IPlanStep newStep, List <IPredicate> init, bool isGoal) { // public bool hasDummyInit = false; //public bool isDummyGoal = false; steps.Add(newStep); orderings.Insert(InitialStep, newStep); orderings.Insert(newStep, GoalStep); // Add new flaws foreach (var pre in newStep.OpenConditions) { var newOC = new OpenCondition(pre, newStep); if (isGoal) { newOC.isDummyGoal = true; } if (init.Contains(pre)) { newOC.hasDummyInit = true; CausalLinks.Add(new CausalLink <IPlanStep>(pre, newStep.InitCndt, newStep)); // newStep.Fulfill(pre); continue; } Flaws.Add(this, newOC); } }
public Composite() : base() { subOrderings = new List <Tuple <IPlanStep, IPlanStep> >(); subLinks = new List <CausalLink <IPlanStep> >(); subSteps = new List <IPlanStep>(); initialStep = new PlanStep(); goalStep = new PlanStep(); }
// avoid bloat for now //public List<Tuple<IPlanStep, IPlanStep>> OrderingRefs; //public List<CausalLink<IPlanStep>> LinkRefs; //public List<Tuple<IPlanStep, IPlanStep>> CntgRefs; public ContextPredicate(Predicate p, IPlanStep actionRef) //, List<Tuple<IPlanStep, IPlanStep>> orderingRefs, List<CausalLink<IPlanStep>> linkRefs, List<Tuple<IPlanStep, IPlanStep>> cntgRefs) : base(p.Name, p.Terms, p.Sign) { ActionRef = actionRef; // OrderingRefs = orderingRefs; // LinkRefs = linkRefs; // CntgRefs = cntgRefs; }
public List <int> GetSubSteps(IPlanStep step) { if (!SubStepMap.ContainsKey(step.ID)) { return(new List <int>()); } return(SubStepMap[step.ID]); }
public static bool IsThreat(IPredicate pred, IPlanStep ps) { if (!ThreatMap.ContainsKey(pred)) { return(false); } return(ThreatMap[pred].Contains(ps.Action.ID)); }
public static bool IsCndt(IPredicate pred, IPlanStep ps) { if (!CausalMap.ContainsKey(pred)) { return(false); } return(CausalMap[pred].Contains(ps.Action.ID)); }
public Decomposition() : base() { subOrderings = new List <Tuple <IPlanStep, IPlanStep> >(); subLinks = new List <CausalLink <IPlanStep> >(); subSteps = new List <IPlanStep>(); initialStep = new PlanStep(); goalStep = new PlanStep(); literals = new List <IPredicate>(); }
public CompositePlanStep(ICompositePlanStep comp, List <IPredicate> openconditions, IPlanStep init, IPlanStep goal, int ID) : base(comp as IPlanStep, openconditions, ID) { compositeAction = comp.Action as IComposite; initialStep = init; goalStep = goal; subSteps = comp.SubSteps; subOrderings = comp.SubOrderings; subLinks = comp.SubLinks; }
public Decomposition(string name, List <ITerm> terms, IOperator init, IOperator dummy, List <IPredicate> Preconditions, List <IPredicate> Effects, int ID) : base(name, terms, new Hashtable(), Preconditions, Effects, ID) { subOrderings = new List <Tuple <IPlanStep, IPlanStep> >(); subLinks = new List <CausalLink <IPlanStep> >(); subSteps = new List <IPlanStep>(); initialStep = new PlanStep(init); goalStep = new PlanStep(dummy); }
public Composite(string name, List <ITerm> terms, IPlanStep init, IPlanStep goal, List <IPredicate> Preconditions, List <IPredicate> Effects, int ID) : base(name, terms, new Hashtable(), Preconditions, Effects, ID) { subOrderings = new List <Tuple <IPlanStep, IPlanStep> >(); subLinks = new List <CausalLink <IPlanStep> >(); subSteps = new List <IPlanStep>(); initialStep = init; goalStep = goal; }
public Composite(IOperator core) : base(core.Name, core.Terms, new Hashtable(), core.Preconditions, core.Effects, core.ID) { subOrderings = new List <Tuple <IPlanStep, IPlanStep> >(); subLinks = new List <CausalLink <IPlanStep> >(); subSteps = new List <IPlanStep>(); initialStep = new PlanStep(new Operator("DummyInit", new List <IPredicate>(), core.Preconditions)); goalStep = new PlanStep(new Operator("DummyGoal", core.Effects, new List <IPredicate>())); Height = core.Height; NonEqualities = core.NonEqualities; }
public Composite(IOperator core, IPlanStep init, IPlanStep goal, List <IPlanStep> substeps, List <Tuple <IPlanStep, IPlanStep> > suborderings, List <CausalLink <IPlanStep> > sublinks) : base(core.Name, core.Terms, new Hashtable(), core.Preconditions, core.Effects, core.ID) { subOrderings = suborderings; subLinks = sublinks; subSteps = substeps; initialStep = init; goalStep = goal; Height = core.Height; }
public Decomposition(IOperator core, List <IPredicate> literals, IPlanStep init, IPlanStep goal, List <IPlanStep> substeps, List <Tuple <IPlanStep, IPlanStep> > suborderings, List <CausalLink <IPlanStep> > sublinks) : base(core.Name, core.Terms, new Hashtable(), core.Preconditions, core.Effects, core.ID) { this.literals = literals; subOrderings = suborderings; subLinks = sublinks; subSteps = substeps; initialStep = init; goalStep = goal; }
public static bool IsThreat(IPredicate pred, IPlanStep ps) { var whichMap = ThreatTupleMap.Get(pred.Sign); if (!whichMap.ContainsKey(pred)) { return(false); } return(whichMap[pred].Contains(ps.Action.ID)); }
public void DetectThreats(IPlanStep possibleThreat) { foreach (var clink in causalLinks) { if (possibleThreat.Height > 0) { var possibleThreatComposite = possibleThreat as ICompositePlanStep; if (possibleThreatComposite.SubSteps.Contains(clink.Head) || possibleThreatComposite.SubSteps.Contains(clink.Tail)) { continue; } var threatGoal = possibleThreatComposite.GoalStep; var threatInit = possibleThreatComposite.InitialStep; if (Orderings.IsPath(clink.Tail as IPlanStep, threatInit)) { continue; } if (Orderings.IsPath(threatGoal, clink.Head as IPlanStep)) { continue; } //if (CacheMaps.IsThreat(clink.Predicate, possibleThreat)) //{ // // no need to decompose if this composite step is the explicit threat. // Flaws.Add(new ThreatenedLinkFlaw(clink, threatGoal)); // return; //} // Now we need to consider all sub-steps since any one of them could interfere. DecomposeThreat(clink, possibleThreatComposite); } else { if (!CacheMaps.IsThreat(clink.Predicate, possibleThreat)) { continue; } if (Orderings.IsPath(clink.Tail as IPlanStep, possibleThreat)) { continue; } if (Orderings.IsPath(possibleThreat, clink.Head as IPlanStep)) { continue; } Flaws.Add(new ThreatenedLinkFlaw(clink, possibleThreat)); } } }
// Used when cloning a plan: <S, O, L>, F public Plan(List <IPlanStep> steps, IState initial, IState goal, IPlanStep initialStep, IPlanStep goalStep, Graph <IPlanStep> orderings, List <CausalLink <IPlanStep> > causalLinks, Flawque flaws) { this.steps = steps; this.causalLinks = causalLinks; this.orderings = orderings; this.flaws = flaws; this.initial = initial; this.goal = goal; this.initialStep = initialStep; this.goalStep = goalStep; }
public Plan(Operator _initial, Operator _goal) { steps = new List <IPlanStep>(); causalLinks = new List <CausalLink <IPlanStep> >(); orderings = new Graph <IPlanStep>(); flaws = new Flawque(); initial = new State(_initial.Effects); goal = new State(_goal.Preconditions); initialStep = new PlanStep(_initial); goalStep = new PlanStep(_goal); }
//public void DetectThreats(IPlanStep possibleThreat) //{ // ICompositePlanStep possibleThreatComposite = new CompositePlanStep(); // if (possibleThreat.Height > 0) // { // possibleThreatComposite = possibleThreat as ICompositePlanStep; // } // foreach (var clink in causalLinks) // { // if (!CacheMaps.IsThreat(clink.Predicate, possibleThreat)) // { // continue; // } // if (possibleThreat.Height > 0) // { // //if (OnDecompPath(clink.Tail, possibleThreat.ID)) // //{ // // var tailRoot = GetDecompRoot(clink.Tail) as CompositePlanStep; // // Orderings.Insert(tailRoot.GoalStep, possibleThreatComposite.GoalStep); // // // just check if causal link between repairstep goal and step goal is threatened // // continue; // // // Console.WriteLine("here"); // //} // //if (clink.Head.Parent != null && clink.Head.Parent.Equals(possibleThreat)) //.SubSteps.Contains(clink.Head) || stepAsComp.SubSteps.Contains(clink.Tail)) // //{ // // continue; // // // replace this with... is Decompositional Link-based path from step to clink.Head or clink.Tail // //} // //if (clink.Tail.Parent != null && clink.Tail.Parent.Equals(possibleThreat)) // //{ // // continue; // //} // //if (threatInit.Equals(clink.Head) || threatInit.Equals(clink.Head) || threatGoal.Equals(clink.Tail) || threatInit.Equals(clink.Tail)) // //{ // // continue; // //} // if (OnDecompPath(clink.Head, possibleThreat.ID)) // { // // must be ordered within // if (Orderings.IsPath(clink.Tail, possibleThreatComposite.GoalStep)) // { // // already tucked into Q's borders // continue; // } // if (!OnDecompPath(clink.Tail, possibleThreat.ID)) // { // // Q --> s -p-> t, not p in eff(Q), not Q --> t // // then, need to tuck t into Q's borders. // var tailRoot = GetDecompRoot(clink.Tail) as CompositePlanStep; // Orderings.Insert(tailRoot.GoalStep, possibleThreatComposite.InitialStep); // } // continue; // } // if (OnDecompPath(clink.Tail, possibleThreat.ID)) // { // continue; // } // if (Orderings.IsPath(clink.Tail, possibleThreatComposite.InitialStep)) // { // continue; // } // if (Orderings.IsPath(possibleThreatComposite.GoalStep, clink.Head)) // { // continue; // } // Flaws.Add(new ThreatenedLinkFlaw(clink, possibleThreat)); // //foreach (var precon in threatGoal.Preconditions) // //{ // // if (precon.Equals(clink.Predicate.GetReversed())) // // { // // // then this composite step is a threat. // // Flaws.Add(new ThreatenedLinkFlaw(clink, possibleThreat)); // // //Flaws.Add(new ThreatenedLinkFlaw(clink, threatGoal)); // // break; // // } // //} // //if (CacheMaps.IsThreat(clink.Predicate, possibleThreat)) // //{ // // // no need to decompose if this composite step is the explicit threat. // // Flaws.Add(new ThreatenedLinkFlaw(clink, threatGoal)); // // return; // //} // // Now we need to consider all sub-steps since any one of them could interfere. // //DecomposeThreat(clink, possibleThreatComposite); // } // else // { // // don't need to check decomp paths, because causal links and threat are all primitive. // //if (OnDecompPath(possibleThreat, clink.Head.Parent.ID)) // //{ // // continue; // //} // //if (OnDecompPath(possibleThreat, clink.Tail.Parent.ID)) // //{ // // continue; // //} // if (Orderings.IsPath(clink.Tail, possibleThreat)) // { // continue; // } // if (Orderings.IsPath(possibleThreat, clink.Head)) // { // continue; // } // Flaws.Add(new ThreatenedLinkFlaw(clink, possibleThreat)); // } // } //} //public IPlanStep GetDecompRoot(IPlanStep ps) //{ // if (ps.Parent == null) // { // return ps; // } // return ps.Parent; //} //public bool OnDecompPath(IPlanStep ps, int target) //{ // if (ps.Parent == null) // { // return false; // } // if (ps.Parent.ID == target) // { // return true; // } // return OnDecompPath(ps.Parent, target); //} //public void UpdateDecompTreeDepth(IPlanStep ps) //{ // if (ps.Parent == null) // { // return; // } // ps.Parent.Depth = ps.Depth - 1; // UpdateDecompTreeDepth(ps.Parent); //} public void Repair(OpenCondition oc, IPlanStep repairStep) { if (repairStep.Height > 0) { RepairWithComposite(oc, repairStep as CompositePlanStep); } else { RepairWithPrimitive(oc, repairStep); } }
public void Insert(IPlanStep newStep) { if (newStep.Height > 0) { InsertDecomp(newStep as ICompositePlanStep); } else { InsertPrimitive(newStep); } }
public CompositePlanStep(IComposite comp, List <IPredicate> openconditions, IPlanStep init, IPlanStep goal, List <IPlanStep> substeps, List <Tuple <IPlanStep, IPlanStep> > suborderings, List <CausalLink <IPlanStep> > clinks, int ID) : base(comp as IOperator, openconditions, ID) { compositeAction = comp; initialStep = init; goalStep = goal; subSteps = substeps; subOrderings = suborderings; subLinks = clinks; }
public CompositePlanStep(ICompositePlanStep comp) : base(comp as IPlanStep) { compositeAction = comp.Action as IComposite; initialStep = new PlanStep(comp.InitialStep); goalStep = new PlanStep(comp.GoalStep); // Do not bother changing the PlanStep skin of these, as this has to happen during insertion subSteps = comp.SubSteps; subLinks = comp.SubLinks; subOrderings = comp.SubOrderings; }
public CompositePlanStep(Composite comp) : base(comp.Clone() as IOperator) { compositeAction = comp.Clone() as IComposite; initialStep = comp.InitialStep.Clone() as IPlanStep; goalStep = comp.GoalStep.Clone() as IPlanStep; // Do not bother changing the PlanStep skin of these, as this has to happen during insertion subSteps = comp.SubSteps.ToList(); subLinks = comp.SubLinks.ToList(); subOrderings = comp.SubOrderings.ToList(); }
public Plan(IState _initial, IState _goal) { steps = new List <IPlanStep>(); causalLinks = new List <CausalLink <IPlanStep> >(); orderings = new Graph <IPlanStep>(); flaws = new Flawque(); initial = _initial; goal = _goal; initialStep = new PlanStep(new Operator("initial", new List <IPredicate>(), initial.Predicates)); goalStep = new PlanStep(new Operator("goal", goal.Predicates, new List <IPredicate>())); }
// Used when cloning a plan: <S, O, L>, F public Plan(List <IPlanStep> steps, IState initial, IState goal, IPlanStep initialStep, IPlanStep goalStep, Graph <IPlanStep> orderings, List <CausalLink <IPlanStep> > causalLinks, Flawque flaws) { this.steps = steps; this.causalLinks = causalLinks; this.orderings = orderings; this.flaws = flaws; this.initial = initial; this.goal = goal; this.initialStep = initialStep; this.goalStep = goalStep; id = System.Threading.Interlocked.Increment(ref Counter).ToString(); }
public Plan(Operator _initial, Operator _goal) { steps = new List <IPlanStep>(); causalLinks = new List <CausalLink <IPlanStep> >(); orderings = new Graph <IPlanStep>(); flaws = new Flawque(); initial = new State(_initial.Effects); goal = new State(_goal.Preconditions); initialStep = new PlanStep(_initial); goalStep = new PlanStep(_goal); id = System.Threading.Interlocked.Increment(ref Counter).ToString(); }
public void Insert(IPlanStep newStep) { steps.Add(newStep); orderings.Insert(InitialStep, newStep); orderings.Insert(newStep, GoalStep); // Add new flaws foreach (var pre in newStep.OpenConditions) { Flaws.Add(this, new OpenCondition(pre, newStep)); } }