public override SearchExitCode Search() { while (_frontier.Any()) { Iterations++; var node = _frontier.Dequeue(); Explored.Push(node.State); if (Problem.GoalTest(node.State)) { Solution = node.Path(); return(SearchExitCode.Success); } var face = node.Expand(Problem); face.ForEach(frontNode => { if (!Explored.Any(s => s.Equals(frontNode.State)) && !_frontier.Any(n => n.State.Equals(frontNode.State))) { _frontier.Enqueue(frontNode); } }); } return(SearchExitCode.Failure); }
public override SearchExitCode Search() { while (_frontier.Any()) { Iterations++; var node = _frontier.First(); _frontier.Remove(node); Explored.Push(node.State); if (Problem.GoalTest(node.State)) { Solution = node.Path(); return(SearchExitCode.Success); } var face = node.Expand(Problem).Select(HeuristicNode <TState, TAction> .From).ToList(); face.ForEach(frontNode => { if (!Explored.Any(s => s.Equals(frontNode.State)) && !_frontier.Any(n => n.State.Equals(frontNode.State))) { AddToFrontier(frontNode); } else { _frontier.FirstOrNone(n => n.State.Equals(frontNode.State) && n.PathCost + _heuristic(n.State.Name, Problem.Goal.Name) > frontNode.PathCost + _heuristic(frontNode.State.Name, Problem.Goal.Name)) .IfNotNull(n => { _frontier.Remove(n); AddToFrontier(frontNode); }); } }); } return(SearchExitCode.Failure); }
public override SearchExitCode Search() { while (_frontier.Any()) { Iterations++; var node = _frontier.First(); _frontier.Remove(node); Explored.Push(node.State); if (Problem.GoalTest(node.State)) { Solution = node.Path(); return(SearchExitCode.Success); } var face = node.Expand(Problem); face.ForEach(frontNode => { if (!Explored.Any(s => s.Equals(frontNode.State)) && !_frontier.Any(n => n.State.Equals(frontNode.State))) { _frontier.Add(frontNode); _frontier.Sort(); } else { _frontier.FirstOrNone(n => n.State.Equals(frontNode.State) && n.PathCost > frontNode.PathCost) .IfNotNull(n => { _frontier.Remove(n); _frontier.Add(frontNode); _frontier.Sort(); }); } }); } return(SearchExitCode.Failure); }