Esempio n. 1
0
        public IEnumerable <T> Expand(ISearchProblem <A, S, C> problem, T node)
        {
            var successors = problem.Successors(node.State);

            // Debug
            #if VERBOSE_DEBUG
            Console.WriteLine(String.Format("There are {0} successors for {1}", successors.Count(), node));
            Console.WriteLine(String.Format("This node has a current path cost of {0}", node.PathCost));
            #endif

            foreach (var successor in successors)
            {
                var action = successor.Item1;
                var state  = successor.Item2;
                var next   = CreateNode(node, state);

                next.Action    = action;
                next.StepCost  = problem.StepCost(node.State, action, state);
                next.Heuristic = problem.Heuristic(state);

                #if VERBOSE_DEBUG
                System.Diagnostics.Trace.WriteLine("   Action = " + next.Action + ", g(n') = " + next.PathCost + ", h(n') = " + next.Heuristic);
                #endif

                yield return(next);
            }
        }
Esempio n. 2
0
 public static Node <TState, TAction> ChildNode <TState, TAction>(
     ISearchProblem <TState, TAction> problem,
     Node <TState, TAction> parent,
     TAction action)
 {
     return(new Node <TState, TAction>(
                problem.Result(parent.State, action),
                parent,
                action,
                parent.PathCost + problem.StepCost(parent.State, action)));
 }
Esempio n. 3
0
        public static IEnumerable <Node <S, A> > GetSuccessors <S, A>(Node <S, A> node, ISearchProblem <S, A> problem)
            where A : class
        {
            var successors = new List <Node <S, A> >();

            foreach (var action in problem.Actions(node.State))
            {
                S successorState = problem.Result(node.State, action);

                double stepCost = problem.StepCost(node.State, action, successorState);
                successors.Add(CreateNode(successorState, node, action, stepCost));
            }

            return(successors);
        }