Exemplo n.º 1
0
 protected AbstractNode(AbstractState state, AbstractState target, AbstractNode Parent, AbstractAction action)
 {
     this.State = state;
     this.Target = target;
     this.Parent = Parent;
     this.Action = action;
 }
Exemplo n.º 2
0
        public RouteFindingNode(AbstractNode parent, AbstractAction action, RouteFindingState state, RouteFindingState target)
            : base(state, target, parent, action)
        {
            if (this.Parent != null && this.Action != null)
                this.PathCost = this.Parent.PathCost + action.Cost;

            this.EstimatedTotalPathCost = this.PathCost + Math.Sqrt(Math.Pow(state.X - target.X, 2) + Math.Pow(state.Y - target.Y, 2));
        }
Exemplo n.º 3
0
        public IEnumerable<AbstractAction> ActionsForNode(AbstractNode node)
        {
            var relevantRules = this.Rules.ToList();

            var parent = node.Parent;
            //Må kun bruge regel fra KB én gang pr. søge-gren
            /*
                        if (relevantRules.Contains(inferenceNode.Action))
                        {
                            //Console.WriteLine("removeing "+String.Join("  ", inferenceNode.Action.Clause.Select(l => (l.Proposition ? "" : "_") + l.Name + ",").ToList()));
                            relevantRules.Remove(inferenceNode.Action);
                        }

                        while (parent != null)
                        {

                            if (relevantRules.Contains(parent.Action))
                                relevantRules.Remove(parent.Action);

                            parent = parent.Parent; //lol, hvor meta
                        }
                        */
            parent = node.Parent;
            while (parent != null)
            {
                relevantRules.Add(parent.State as InferenceState);
                parent = parent.Parent;
            }
            //Ovenstående er et forsøg på at anvende anscestor rigtigt.

            var actions = new List<AbstractAction>();
            //foreach (var state in Rules)
            foreach (var state in relevantRules)
            {
                foreach (var literal in state.Clause)
                {
                    foreach (var innerLiterat in ((InferenceState)node.State).Clause)
                    {
                        if (innerLiterat.Name.Equals(literal.Name) && innerLiterat.Proposition != literal.Proposition)
                        {
                            actions.Add(new InferenceAction(state, node.Target as InferenceState));
                        }
                    }
                }
            }

            return actions;
        }
Exemplo n.º 4
0
        public static SearchResult Search(AbstractNode initialNode, IKnowledgeBase kb)
        {
            var frontier = new PriorityQueue<AbstractNode>();
            var explored = new List<AbstractState>();
            var statesSearched = 0; //Bliver kun brugt af os af ren interesse
            var end = initialNode.Target;
            frontier.Add(initialNode);
            explored.Add(initialNode.State);

            while (frontier.Count > 0)
            {
                // Chooses the lowest-cost node in the frontier
                var currentNode = frontier.Pop();
                statesSearched++;
                if (currentNode.State.Equals(end))
                    return new SearchResult(currentNode, statesSearched, true);

                var actions = kb.ActionsForNode(currentNode);
            //Explore /expand the current node
                foreach (var action in actions)
                {
                    var child = kb.Resolve(currentNode, action, end);
                    //System.Console.WriteLine("Frontier.Count: " + frontier.Count);

                    if (!explored.Contains(child.State) && !frontier.Contains(child))
                    {
                        explored.Add(child.State);
                        frontier.Add(child);

                    }
                    else if(true)
                    {
                        for (int i = 0; i < frontier.Count; i++)
                        {
                            var frontierNode = frontier[i];
                            if (frontierNode.State.Equals(child.State) && frontierNode.PathCost > child.PathCost)
                            {
                                frontier[i] = child;
                                break;
                            }
                        }
                    }
                }
            }

            return new SearchResult(null, statesSearched, false);
        }
Exemplo n.º 5
0
 public InferenceNode(AbstractNode parent, AbstractState target, AbstractState state, AbstractAction action)
     : base(state, target, parent, action)
 {
     this.PathCost = this.Parent.PathCost + 1;
     this.EstimatedTotalPathCost = this.State.Clause.Count;
 }
 public AbstractNode Resolve(AbstractNode parent, AbstractAction action, AbstractState targetState)
 {
     return new RouteFindingNode(parent, action, action.EndState as RouteFindingState, targetState as RouteFindingState);
 }
 public IEnumerable<AbstractAction> ActionsForNode(AbstractNode node)
 {
     return this.Actions.Where(a => a.StartState.Equals(node.State)).ToList();
 }
Exemplo n.º 8
0
 public AbstractNode Resolve(AbstractNode parent, AbstractAction action, AbstractState targetState)
 {
     return this.ApplyResolution(parent as InferenceNode, action);
 }