Exemplo n.º 1
0
        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));
                }
            }
        }
Exemplo n.º 2
0
        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 (step.Height > 0)
                {
                    continue;
                }

                if (plan.Orderings.IsPath(oc.step, step))
                {
                    continue;
                }

                //    if (CacheMaps.IsCndt(oc.precondition, step))
                //        oc.cndts += 1;

                if (CacheMaps.IsThreat(oc.precondition, step))
                {
                    // just need 1 risk to be unsafe
                    oc.risks += 1;
                    break;
                }
            }

            if (oc.risks == 0 && plan.Initial.InState(oc.precondition))
            {
                oc.isInit = true;
                // Using "Work" or Estimated Effort, vs "Cost" or Add Reuse Heuristic Cost
                oc.addReuseHeuristic = 1;
            }

            OpenConditions.Add(oc);
        }
Exemplo n.º 3
0
        public void InsertDecomp(ICompositePlanStep newStep)
        {
            decomps += 1;
            var IDMap = new Dictionary <int, IPlanStep>();

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

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

            //foreach (var oc in newStep.OpenConditions)
            //{
            //    Flaws.Add(this, new OpenCondition(oc, dummyInit));
            //}


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

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

            // Dont need these here because its added when inserted as primitive
            //orderings.Insert(InitialStep, dummyGoal);
            //orderings.Insert(dummyGoal, GoalStep);

            // This code block is used for debugging and may possibly be ommitted.
            // guarantee that newStepCopy cannot be used for re-use by changing ID (by casting as new step)

            var newStepCopy = new PlanStep(new Operator(newStep.Action.Predicate as Predicate, new List <IPredicate>(), new List <IPredicate>()));

            steps.Add(newStepCopy);
            //  orderings.Insert(dummyInit, newStepCopy);
            //  orderings.Insert(newStepCopy, dummyGoal);
            newStepCopy.Height = newStep.Height;
            var newSubSteps = new List <IPlanStep>();

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

                    Orderings.Insert(compositeSubStep.GoalStep, dummyGoal);
                    Orderings.Insert(dummyInit, compositeSubStep.InitialStep);
                    IDMap[substep.ID] = compositeSubStep;
                    compositeSubStep.InitialStep.InitCndt = dummyInit;
                    newSubSteps.Add(compositeSubStep);
                    Insert(compositeSubStep);
                    // Don't bother updating hdepth yet because we will check on recursion
                }
                else
                {
                    var 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;
                    InsertPrimitiveSubstep(newsubstep, dummyInit.Effects, false);

                    if (newsubstep.Depth > Hdepth)
                    {
                        Hdepth = newsubstep.Depth;
                    }
                }
            }

            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 ICompositePlanStep;
                    head = temp.GoalStep as IPlanStep;
                }
                if (tail.Height > 0)
                {
                    var temp = tail as ICompositePlanStep;
                    tail = temp.InitialStep as IPlanStep;
                }
                Orderings.Insert(head, tail);
            }

            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 CompositePlanStep;
                    head = temp.GoalStep as IPlanStep;
                }
                if (tail.Height > 0)
                {
                    var temp = tail as CompositePlanStep;
                    tail = temp.InitialStep as IPlanStep;
                }

                var newclink = new CausalLink <IPlanStep>(clink.Predicate, head, tail);
                if (tail.OpenConditions.Contains(clink.Predicate))
                {
                    tail.OpenConditions.Remove(clink.Predicate);
                }
                CausalLinks.Add(newclink);
                Orderings.Insert(head, tail);

                // 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;
                        }
                    }

                    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;
            newStep.InitialStep = dummyInit;
            newStep.GoalStep    = dummyGoal;

            foreach (var pre in newStep.OpenConditions)
            {
                Flaws.Add(this, new OpenCondition(pre, dummyInit as IPlanStep));
            }
        }
Exemplo n.º 4
0
        public void DetectThreats(IPlanStep possibleThreat)
        {
            CompositePlanStep possibleThreatComposite = new CompositePlanStep();

            if (possibleThreat.Height > 0)
            {
                possibleThreatComposite = possibleThreat as CompositePlanStep;
            }

            foreach (var clink in causalLinks)
            {
                if (!CacheMaps.IsThreat(clink.Predicate, possibleThreat))
                {
                    continue;
                }

                if (possibleThreat.Height > 0)
                {
                    if (decomplinks.OnDecompPath(clink.Head, possibleThreat.ID))
                    {
                        // must be ordered within
                        if (Orderings.IsPath(clink.Tail, possibleThreatComposite.GoalStep))
                        {
                            // already tucked into Q's borders
                            continue;
                        }

                        if (!decomplinks.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 = GetStepByID(decomplinks.GetRoot(clink.Tail)) as CompositePlanStep;
                            Orderings.Insert(tailRoot.GoalStep, possibleThreatComposite.InitialStep);
                            //this.ID += string.Format("(^Od2[{0},{1}])", tailRoot.GoalStep.ID, possibleThreatComposite.InitialStep.ID);
                        }

                        continue;
                    }

                    if (decomplinks.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));
                }
                else
                {
                    // don't need to check decomp paths, because causal links and threat are all primitive.
                    if (Orderings.IsPath(clink.Tail, possibleThreat))
                    {
                        continue;
                    }
                    if (Orderings.IsPath(possibleThreat, clink.Head))
                    {
                        continue;
                    }
                    Flaws.Add(new ThreatenedLinkFlaw(clink, possibleThreat));
                }
            }
        }
Exemplo n.º 5
0
        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));
                }
            }
        }
Exemplo n.º 6
0
        public void InsertDecomp(ICompositePlanStep newStep)
        {
            this.hdepth += newStep.SubSteps.Count;
            decomps     += 1;
            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;

            // Officially add this step to the list of steps (DO NOT INSERT which would insert its flaws)
            steps.Add(newStep);

            // Create new list of substeps
            var newSubSteps = new List <IPlanStep>();

            // Blank out this step's preconditions and effects so that it cannot be used?
            newStep.Preconditions = new List <IPredicate>();
            newStep.Effects       = new List <IPredicate>();

            // Assign new step's dummy initial and goal steps
            newStep.InitialStep = dummyInit;
            newStep.GoalStep    = dummyGoal;

            // Insert decomp links for the dummy initial and goal steps
            decomplinks.Insert(newStep, dummyGoal);
            decomplinks.Insert(newStep, dummyInit);

            // For each substep, assign depth and insert into plan.
            foreach (var substep in newStep.SubSteps)
            {
                if (substep.Height > 0)
                {
                    // Don't just clone, create a new step so that it has a unique ID
                    var compositeSubStep = new CompositePlanStep(substep.Clone() as CompositePlanStep)
                    {
                        Depth = newStep.Depth + 1
                    };

                    newSubSteps.Add(compositeSubStep);
                    decomplinks.Insert(newStep, compositeSubStep);
                    Insert(compositeSubStep);

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

                    IDMap[substep.ID] = compositeSubStep;

                    compositeSubStep.InitialStep.InitCndt = dummyInit;
                    compositeSubStep.GoalStep.GoalCndt    = dummyGoal;
                }
                else
                {
                    var 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;

                    decomplinks.Insert(newStep, newsubstep);

                    InsertPrimitiveSubstep(newsubstep, dummyInit.Effects, false);

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

            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 ICompositePlanStep;
                    head = temp.GoalStep as IPlanStep;
                }
                if (tail.Height > 0)
                {
                    var temp = tail as ICompositePlanStep;
                    tail = temp.InitialStep as IPlanStep;
                }
                Orderings.Insert(head, tail);
            }

            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 CompositePlanStep;
                    head = temp.GoalStep as IPlanStep;
                }
                if (tail.Height > 0)
                {
                    var temp = tail as CompositePlanStep;
                    tail = temp.InitialStep as IPlanStep;
                }

                var newclink = new CausalLink <IPlanStep>(clink.Predicate, head, tail);
                if (tail.OpenConditions.Contains(clink.Predicate))
                {
                    tail.OpenConditions.Remove(clink.Predicate);
                }
                CausalLinks.Add(newclink);
                Orderings.Insert(head, tail);

                // 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));
                }
            }


            // This is needed because we'll check if these substeps are threatening links
            newStep.SubSteps    = newSubSteps;
            newStep.InitialStep = dummyInit;
            newStep.GoalStep    = dummyGoal;

            foreach (var pre in newStep.OpenConditions)
            {
                Flaws.Add(this, new OpenCondition(pre, dummyInit as IPlanStep));
            }
        }
Exemplo n.º 7
0
        // h^r_add(pi) = sum_(oc in plan) 0 if exists a step possibly preceding oc.step and h_add(oc.precondition) otherwise.
        public static int AddReuseHeuristic(IPlan plan)
        {
            Logger.LogThingToType("AddReuse", " ", "HeuristicNew");
            Logger.LogThingToType("AddReuse", " ", "HeuristicOld");

            var tuplemapping = new TupleMap <IPredicate, List <IPlanStep> >();
            // var posmapping = new Dictionary<IPredicate, List<int>>();
            //var negmapping = new Dictionary<IPredicate, List<int>>();
            var effList = new List <IPredicate>();
            int sumo    = 0;

            if (plan.Flaws.OpenConditions.Count > plan.Steps.Count)
            {
                var beforePreamble = Logger.Log();
                foreach (var existingStep in plan.Steps)
                {
                    if (existingStep.Height > 0)
                    {
                        continue;
                    }

                    foreach (var eff in existingStep.Effects)
                    {
                        effList.Add(eff);
                        if (!tuplemapping.Get(eff.Sign).ContainsKey(eff))
                        {
                            tuplemapping.Get(eff.Sign)[eff] = new List <IPlanStep>()
                            {
                                existingStep
                            };
                        }
                        else
                        {
                            tuplemapping.Get(eff.Sign)[eff].Add(existingStep);
                        }
                    }
                }

                Logger.LogTimeToType("collectStepsPreamble", Logger.Log() - beforePreamble, "HeuristicNew");

                foreach (var oc in plan.Flaws.OpenConditions)
                {
                    var beforeEachOc = Logger.Log();
                    var existsA      = false;
                    if (effList.Contains(oc.precondition))
                    {
                        foreach (var action in tuplemapping.Get(oc.precondition.Sign)[oc.precondition])
                        {
                            if (plan.Orderings.IsPath(oc.step, action))
                            {
                                continue;
                            }

                            existsA = true;
                            break;
                        }
                    }
                    if (!existsA)
                    {
                        // we should always have the conditions in the visitedPreds dictionary if we processed correctly
                        if (visitedPreds.Get(oc.precondition.Sign).ContainsKey(oc.precondition))
                        {
                            sumo += visitedPreds.Get(oc.precondition.Sign)[oc.precondition];
                            continue;
                        }
                        // Fail gracefully
                        sumo += 100000;
                        //throw new System.Exception("visitedPreds does not contain " + oc.precondition.ToString());
                    }
                    Logger.LogTimeToType("EachOC", Logger.Log() - beforeEachOc, "HeuristicNew");
                }

                return(sumo);
            }


            // we are just taking the sum of the visitedPreds values of the open conditions, unless there is a step that establishes the condition already in plan (reuse).

            foreach (var oc in plan.Flaws.OpenConditions)
            {
                var wayBefore = Logger.Log();
                // Does there exist a step in the plan that can establish this needed precondition?
                var existsA = false;
                foreach (var existingStep in plan.Steps)
                {
                    if (existingStep.Height > 0)
                    {
                        continue;
                    }

                    var before = Logger.Log();
                    if (CacheMaps.IsCndt(oc.precondition, existingStep))
                    {
                        existsA = true;
                        break;
                    }
                    Logger.LogTimeToType("IsCndt", Logger.Log() - before, "HeuristicOld");

                    if (plan.Orderings.IsPath(oc.step, existingStep))
                    {
                        continue;
                    }
                }

                // append heuristic for open condition
                if (!existsA)
                {
                    // we should always have the conditions in the visitedPreds dictionary if we processed correctly
                    if (visitedPreds.Get(oc.precondition.Sign).ContainsKey(oc.precondition))
                    {
                        sumo += visitedPreds.Get(oc.precondition.Sign)[oc.precondition];
                        continue;
                    }
                    sumo += 100000;
                    //throw new System.Exception("visitedPreds does not contain " + oc.precondition.ToString());
                }

                Logger.LogTimeToType("EachOC", Logger.Log() - wayBefore, "HeuristicOld");
            }
            return(sumo);
        }