/// <summary> /// Computes the distances to the goals for the specified pattern. /// </summary> /// <param name="pattern">Pattern (i.e. variables of the pattern) to process.</param> private PatternValuesDistances ComputePatternDistances(int[] pattern) { IHeap <double, ISimpleConditions> fringe = new LeftistHeap <ISimpleConditions>(); InsertPatternConditions(fringe, (Conditions)Problem.GoalConditions, 0, pattern); PatternValuesDistances patternValuesDistances = new PatternValuesDistances(); while (fringe.GetSize() > 0) { double distance = fringe.GetMinKey(); ISimpleConditions conditions = fringe.RemoveMin(); int[] patternValues = conditions.GetAssignedValues(); Debug.Assert(pattern.Length == conditions.GetSize()); Debug.Assert(pattern.Length == patternValues.Length); if (patternValuesDistances.ContainsKey(patternValues)) { // already processed with a lower cost continue; } patternValuesDistances.Add(patternValues, distance); foreach (var predecessor in Problem.GetPredecessors(conditions)) { IConditions predecessorConditions = (IConditions)predecessor.GetPredecessorConditions(); IOperator predecessorOperator = (IOperator)predecessor.GetAppliedOperator(); foreach (var predecessorSimpleConditions in predecessorConditions.GetSimpleConditions()) { double cost = distance + predecessorOperator.GetCost(); InsertPatternConditions(fringe, predecessorSimpleConditions, cost, pattern); } } } return(patternValuesDistances); }