Exemplo n.º 1
0
 private bool success(IAIGraphNode current)
 {
     Solution   = reconstruct_path(current);
     IsComplete = true;
     IsSuccess  = true;
     return(false);
 }
Exemplo n.º 2
0
        public GraphSolver(IEnumerable <T> sources, IEnumerable <T> destinations)
        {
            this.source = new DummySource(sources);
            destination = new HashSet <IAIGraphNode>(destinations.Cast <IAIGraphNode>());


            openSet = new HashSet <IAIGraphNode>()
            {
                source
            };
            closedSet = new HashSet <IAIGraphNode>();

            cameFrom = new Dictionary <IAIGraphNode, IAIGraphNode>();
            gScore   = new Dictionary <IAIGraphNode, float>()
            {
                { source, 0 }
            }
            .WithDefault(k => float.PositiveInfinity);

            fScore = new Dictionary <IAIGraphNode, float>().WithDefault(s => destination.Min(d => heuristic_cost_estimate(s, d)));

            Solution   = null;
            IsComplete = false;
            IsSuccess  = false;
        }
Exemplo n.º 3
0
 private float cost_between(IAIGraphNode current, IAIGraphNode neighbor)
 {
     if (current is T && neighbor is T)
     {
         return(CostBetween((T)current, (T)neighbor));
     }
     return(0);
 }
Exemplo n.º 4
0
 private float heuristic_cost_estimate(IAIGraphNode neighbor, IAIGraphNode d)
 {
     if (neighbor is T && d is T)
     {
         return(HeuristicCostEstimate((T)neighbor, (T)d));
     }
     return(float.PositiveInfinity);
 }
Exemplo n.º 5
0
 private bool filter(IAIGraphNode arg)
 {
     if (arg is T)
     {
         return(FilterPath((T)arg));
     }
     return(true);
 }
Exemplo n.º 6
0
 private IEnumerable <IAIGraphNode> getNeighbors(IAIGraphNode current)
 {
     if (current is T)
     {
         return(GetNeighbors((T)current).OfType <IAIGraphNode>());
     }
     return(current.NextNodes);
 }
Exemplo n.º 7
0
        private IList <T> reconstruct_path(IAIGraphNode current)
        {
            var path = new List <T>();

            if (current is T)
            {
                path.Add((T)current);
            }
            IAIGraphNode from;

            while (cameFrom.TryGetValue(current, out from))
            {
                current = from;
                if (current is T)
                {
                    path.Add((T)current);
                }
            }
            path.Reverse();
            return(path);
        }