public int Calc_H(World w, GridSearchNode gridNode) { var bcc = new BiconnectedComponents(w, gridNode); if (!bcc.LinearLocationWasVisitedDuringBuild(w.Goal)) { if (gridNode is RsdGridSearchNode) { ((RsdGridSearchNode)gridNode).Reachable = new BitArray(w.LinearSize); //TODO: head location valid? } return(0); //Goal not reachable } var valid = bcc.GetValidPlacesForMaxPath(gridNode.HeadLocation, w.Goal); int validCount = 0; foreach (var linearLocation in valid) { if (linearLocation) { validCount++; } } if (validCount > 0) { validCount--; //Minus 1 because we are counting the head location too } if (gridNode is RsdGridSearchNode) { ((RsdGridSearchNode)gridNode).Reachable = new BitArray(valid); //TODO: head location valid? } return(validCount); //Minus 1 because we are counting the head location too }
public int Calc_H(World w, GridSearchNode gridNode) { var bcc = new BiconnectedComponents(w, gridNode); if (!bcc.LinearLocationWasVisitedDuringBuild(w.Goal)) { if (gridNode is RsdGridSearchNode) { ((RsdGridSearchNode)gridNode).Reachable = new BitArray(w.LinearSize); } return(0); //Goal not reachable } var valid = bcc.GetValidPlacesForMaxPath(gridNode.HeadLocation, w.Goal); //instead of g we will count odd and even separatly int odd = 0; int even = 0; int head = gridNode.HeadLocation.GetLinearLocationRepresentation(w); for (int i = 0; i < valid.Length; i++) { if (valid[i]) { if (i == head) { continue; } if (IsEvenLocation(w, i)) { even++; } else { odd++; } } } if (gridNode is RsdGridSearchNode) { ((RsdGridSearchNode)gridNode).Reachable = new BitArray(valid); //TODO: head location valid? } bool firstStepEven = !IsEvenLocation(w, head); bool goalEven = IsEvenLocation(w, w.Goal.GetLinearLocationRepresentation(w)); return(AlternateStepsHeuristic.CalculateAlternateStepHeuristic(firstStepEven, goalEven, odd, even)); }
public int Calc_H(World w, GridSearchNode gridNode) { var bcc = new BiconnectedComponents(w, gridNode); if (!bcc.LinearLocationWasVisitedDuringBuild(w.Goal)) { if (gridNode is RsdGridSearchNode) { ((RsdGridSearchNode)gridNode).Reachable = new BitArray(w.LinearSize); } return(0); //Goal not reachable } var bct = bcc.GetMaxPathBlockCutTree(gridNode.HeadLocation, w.Goal); //instead of g we will count odd and even separatly int h = 0; for (int i = 0; i + 2 < bct.Count; i += 2) { int head = bct.ElementAt(i)[0]; var firstStepEven = !IsEvenLocation(w, head); var goalEven = IsEvenLocation(w, bct.ElementAt(i + 2)[0]); int odd = 0; int even = 0; var currBlk = bct.ElementAt(i + 1); for (int j = 0; j < currBlk.Length; j++) { if (currBlk[j] == head) { continue; } if (IsEvenLocation(w, currBlk[j])) { even++; } else { odd++; } } h += AlternateStepsHeuristic.CalculateAlternateStepHeuristic(firstStepEven, goalEven, odd, even); } if (gridNode is RsdGridSearchNode) { ((RsdGridSearchNode)gridNode).Reachable = new BitArray(w.LinearSize); for (int i = 0; i + 1 < bct.Count; i += 2) { var currBlk = bct.ElementAt(i + 1); for (int j = 0; j < currBlk.Length; j++) { ((RsdGridSearchNode)gridNode).Reachable[currBlk[j]] = true; } } } return(h); }