namespace SpriteCompiler.AI
{
using Queue;
using System;
using System.Linq;
#if False
public class RecursiveBestFirstSearch : BestFirstSearch
where T : IHeuristicSearchNodeWithMemory
where C : ICost, new()
{
public RecursiveBestFirstSearch(ISearchStrategy search, Func> fringe)
: base(search, fringe)
{
}
}
public class RecursiveBestFirstSearchStrategy : AbstractSearchStrategy
where T : IHeuristicSearchNodeWithMemory
where C : ICost, new()
{
private static readonly C Cost = new C();
private ISearchProblem problem;
public RecursiveBestFirstSearchStrategy(INodeExpander expander)
: base(expander)
{
}
public override System.Collections.Generic.IEnumerable Search(ISearchProblem problem, IQueue fringe, S initialState)
{
RBFS(Expander.CreateNode(initialState), Cost.Zero(), Cost.Maximum());
}
private C RBFS(T node, C F_N, C bound)
{
var f_N = problem.Heuristic(node.State);
if (f_N.CompareTo(bound) > 0)
{
return f_N;
}
if (problem.IsGoal(node.State))
{
throw new Exception();
}
var children = Expander.Expand(problem, node);
if (!children.Any())
{
return Cost.Maximum();
}
foreach (var N_i in children)
{
if (f_N.CompareTo(F_N) < 0)
{
N_i.F = F_N.Max(N_i.EstCost);
}
else
{
N_i.F = N_i.EstCost;
}
}
children = children.OrderBy(x => x.F);
/*
RBFS (node: N, value: F(N), bound: B)
IF f(N)>B, RETURN f(N)
IF N is a goal, EXIT algorithm
IF N has no children, RETURN infinity
FOR each child Ni of N,
IF f(N)