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 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 Add(IPlan plan, OpenCondition oc) { // Don't add an open condition if it's already in the Flawque. if (OpenConditions.Contains(oc)) { return; } // Predicates are labeled as static before planning if (GroundActionFactory.Statics.Contains(oc.precondition)) { oc.isStatic = true; oc.addReuseHeuristic = 0; OpenConditions.Add(oc); return; } // Use this value to keep track of amount of work. if (HeuristicMethods.visitedPreds.Get(oc.precondition.Sign).ContainsKey(oc.precondition)) { oc.addReuseHeuristic = HeuristicMethods.visitedPreds.Get(oc.precondition.Sign)[oc.precondition]; } // Calculate risks and cndts foreach (var step in plan.Steps) { if (step.ID == oc.step.ID) { continue; } if (plan.Orderings.IsPath(oc.step, step)) { continue; } if (CacheMaps.IsThreat(oc.precondition, step)) { oc.risks += 1; } } if (oc.risks == 0 && plan.Initial.InState(oc.precondition)) { oc.isInit = true; oc.addReuseHeuristic = 1; } OpenConditions.Add(oc); }
public void Add(IPlan plan, OpenCondition oc) { // Don't add an open condition if it's already in the Flawque. if (OpenConditions.Contains(oc)) { return; } // Predicates are labeled as static before planning if (GroundActionFactory.Statics.Contains(oc.precondition)) { oc.isStatic = true; OpenConditions.Add(oc); return; } // Calculate risks and cndts foreach (var step in plan.Steps) { if (step.ID == oc.step.ID) { continue; } if (plan.Orderings.IsPath(oc.step, step)) { continue; } if (CacheMaps.IsCndt(oc.precondition, step)) { oc.cndts += 1; } if (CacheMaps.IsThreat(oc.precondition, step)) { oc.risks += 1; } } if (oc.risks == 0 && plan.Initial.InState(oc.precondition)) { oc.isInit = true; } OpenConditions.Add(oc); }
public void RepairWithPrimitive(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); //// we are fulfilling open conditions because open conditions can be used to add flaws. if (!needStep.Name.Equals("DummyGoal") && !needStep.Name.Equals("DummyInit")) { 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.Height > 0) { continue; } 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 RepairWithComposite(OpenCondition oc, CompositePlanStep repairStep) { // oc = <needStep, needPrecond>. Need to find needStep in plan, because open conditions have been mutated before arrival. var needStep = Find(oc.step); if (!needStep.Name.Equals("DummyGoal") && !needStep.Name.Equals("DummyInit")) { needStep.Fulfill(oc.precondition); } orderings.Insert(repairStep.GoalStep as IPlanStep, needStep); 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 CompositePlanStep; if (stepAsComp.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 } var compGoal = stepAsComp.GoalStep; var compInit = stepAsComp.InitialStep; if (clink.Head.ID == compInit.ID || clink.Tail.ID == compInit.ID || clink.Head.ID == compGoal.ID || clink.Tail.ID == compGoal.ID) { continue; } // step is a threat to need precondition if (Orderings.IsPath(needStep, compInit)) { continue; } if (Orderings.IsPath(compGoal, repairStep.InitialStep as IPlanStep)) { continue; } Flaws.Add(new ThreatenedLinkFlaw(clink, stepAsComp)); // Flaws.Add(new ThreatenedLinkFlaw(clink, compInit)); } else { // 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)); } } }
public void RepairWithComposite(OpenCondition oc, CompositePlanStep repairStep) { var needStep = Find(oc.step); if (!needStep.Name.Equals("DummyGoal") && !needStep.Name.Equals("DummyInit")) { needStep.Fulfill(oc.precondition); } orderings.Insert(repairStep.GoalStep as IPlanStep, needStep); //this.ID += string.Format("(^Orl[{0},{1}])", repairStep.GoalStep.ID, needStep.ID); // Causal Link between repair step's goal condition and need step. var clink = new CausalLink <IPlanStep>(oc.precondition, 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 CompositePlanStep; if (decomplinks.OnDecompPath(clink.Head, step.ID)) { // must be ordered within if (Orderings.IsPath(clink.Tail, stepAsComp.GoalStep)) { // already tucked into Q's borders continue; } if (!decomplinks.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(decomplinks.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 (decomplinks.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 (decomplinks.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)); } } }