Beispiel #1
0
        public override IShortestPathResult Process(uint @from, uint to)
        {
            _result = new BfsConcurrentResult(from, to);

            INode <T, TEdgeCustom> nodeFrom = Graph[from];

            nodeFrom.Distance = 0;

            _table.Initialise = () => _table.Produce(nodeFrom);

            _table.Producing = node =>
            {
                if (node.Key != _result.ToNode)
                {
                    node.EachChild((in Edge <T, TEdgeCustom> e) =>
                    {
                        _table.Consume(new MapReduceJob(node.Key, e.Node.Key, node.Distance, e.Cost));
                    });
                }
Beispiel #2
0
        public override IShortestPathResult Process(uint @from, uint to)
        {
            _result = new BfsConcurrentResult(from, to);

            INode <T, TEdgeCustom> nodeFrom = Graph[from];

            nodeFrom.Distance = 0;

            _table.Initialise = () => _table.Produce(nodeFrom);

            _table.Producing = node =>
            {
                if (node.Key != _result.ToNode)
                {
                    for (int i = 0; i < node.Children.Count; i++)
                    {
                        Edge <T, TEdgeCustom> e = node.Children[i];
                        _table.Consume(new MapReduceJob(node.Key, e.Node.Key, node.Distance, e.Cost));
                    }
                }
            };

            _table.Consuming = job =>
            {
                if (Reduce(job.From, Graph[job.To], job.Distance))
                {
                    _table.Produce(Graph[job.To]);
                }
            };

            _table.Work();

            _result.Distance = Graph[to].Distance;

            return(_result);
        }