コード例 #1
0
        /// <summary>
        /// @param Problem
        /// @return
        /// </summary>
        public override List <IAction> Search(IProblem problem)
        {
            var rand        = new Random();
            var actionIndex = rand.Next(problem.Actions(problem.InitialState()).Count);

            return(new List <IAction> {
                problem.Actions(problem.InitialState())[actionIndex]
            });
        }
コード例 #2
0
        private List <IAction> RecursiveDLS(Node node, IProblem problem, int limit)
        {
            var cutoffOccurred = false;

            if (problem.GoalTest(node.State))
            {
                Console.WriteLine("solution");
                return(Solution(node));
            }
            else if (node.Depth == limit)
            {
                //Console.WriteLine("profondeur limite atteinte");
                return(null);
            }
            else
            {
                //Console.WriteLine("recherche en profondeur");
                foreach (var action in problem.Actions(node.State))
                {
                    var successor = ChildNode(problem, node, action);
                    var result    = RecursiveDLS(successor, problem, limit);
                    if (result == null)
                    {
                        cutoffOccurred = true;
                    }
                    else
                    {
                        return(result);
                    }
                }
            }
            return(null);
        }
コード例 #3
0
ファイル: AStar.cs プロジェクト: Minial/UQAC-IA-TP1
        public override List <Node> Expand(Node node, IProblem problem)
        {
            var liste = new List <Node>();

            foreach (var action in problem.Actions(node.State))
            {
                var child = ChildNode(problem, node, action);
                liste.Add(child);
            }
            return(liste);
        }
コード例 #4
0
        public override List <IAction> Search(IProblem problem)
        {
            var node     = new Node(null, 0, 0, problem.InitialState(), null);
            var frontier = new Queue <Node>();

            frontier.Enqueue(node);
            var explored = new List <IState>();

            if (problem.GoalTest(node.State))
            {
                return(Solution(node));
            }
            do
            {
                if (!frontier.Any())
                {
                    return(null);
                }
                node = frontier.Dequeue();
                if (!explored.Contains(node.State))
                {
                    explored.Add(node.State);
                }
                foreach (var action in problem.Actions(node.State))
                {
                    var child = ChildNode(problem, node, action);
                    if (!explored.Contains(child.State) || !explored.Contains(child.State))
                    {
                        if (problem.GoalTest(child.State))
                        {
                            return(Solution(child));
                        }
                        frontier.Enqueue(child);
                    }
                }
            } while (true);
        }