// h_add(q) = 0 if holds initially, min a in GA, and infinite otherwise public static int AddHeuristic(IState initial, IPredicate condition, HashSet <IPredicate> ignorableConditions) { if (initial.InState(condition)) { return(0); } // if we have a value for this, return it. // if (visitedPreds.ContainsKey(condition)) // { // return visitedPreds[condition]; // } int minSoFar = 1000; // Then this is a static condition that can never be true... we should avoid this plan. if (!CacheMaps.CausalTupleMap.Get(condition.Sign).ContainsKey(condition)) { return(minSoFar); } // find the gorund action that minimizes the heuristic estimate foreach (var groundAction in CacheMaps.GetCndts(condition)) { if (groundAction.Height > 0) { continue; } int thisVal; // if (visitedOps.ContainsKey(groundAction)) // { // // thisVal = visitedOps[groundAction]; // } // else // { thisVal = AddHeuristic(initial, groundAction, ignorableConditions); // } if (thisVal < minSoFar) { minSoFar = thisVal; } } //visitedPreds[condition] = minSoFar; return(minSoFar); }
// h_add(q) = 0 if holds initially, min a in GA, and infinite otherwise public static int AddHeuristic(IState initial, IPredicate condition) { if (initial.InState(condition)) { return(0); } // if we have a value for this, return it. if (visitedPreds.ContainsKey(condition)) { return(visitedPreds[condition]); } int minSoFar = 1000; // Then this is a static condition that can never be true... we should avoid this plan. if (!CacheMaps.CausalMap.ContainsKey(condition)) { return(minSoFar); } // find the gorund action that minimizes the heuristic estimate foreach (var groundAction in CacheMaps.GetCndts(condition)) { int thisVal; if (visitedOps.ContainsKey(groundAction)) { thisVal = visitedOps[groundAction]; } else { thisVal = AddHeuristic(initial, groundAction); } if (thisVal < minSoFar) { minSoFar = thisVal; } } visitedPreds[condition] = minSoFar; return(minSoFar); }
public static int AddHeuristic(IPredicate precondition) { if (visitedPreds.Get(precondition.Sign)[precondition] == 0) { return(0); } var bestSoFar = 1000; foreach (var cndt in CacheMaps.GetCndts(precondition)) { if (cndt.Height > 0) { continue; } var sumo = cndt.Preconditions.Sum(pre => visitedPreds.Get(pre.Sign)[pre]); if (sumo < bestSoFar) { bestSoFar = sumo; } } return(bestSoFar); }