Beispiel #1
0
        private void Explore(int start)
        {
            _color.SetValue(start, RED);

            var queue = new Queue <int>();

            queue.Enqueue(start);
            while (queue.Any())
            {
                var current       = queue.Dequeue();
                var neighborColor = GetNeighborColor(current);
                foreach (var neighbor in _graph.NeighborIndexes(current)
                         .Where(i => i != current))
                {
                    if (_color.Visited(neighbor))
                    {
                        //Check Visited neighbor is the correct color
                        if (_color.GetValue(neighbor) != neighborColor)
                        {
                            throw new NonBipartiteException();
                        }

                        continue;
                    }

                    queue.Enqueue(neighbor);
                    _color.SetValue(neighbor, neighborColor);
                }
            }
        }
Beispiel #2
0
 protected virtual void Explore(int v, int connectedComponent)
 {
     _component.SetValue(v, connectedComponent);
     foreach (var w in _graph.NeighborIndexes(v))
     {
         if (!_component.Visited(w))
         {
             Explore(w, connectedComponent);
         }
     }
 }
Beispiel #3
0
        protected virtual void Explore(int v, HashSet <int> ancestory)
        {
            if (ancestory.Contains(v))
            {
                throw new GraphCycleException();
            }

            ancestory.Add(v);
            foreach (var w in _g.NeighborIndexes(v))
            {
                Explore(w, ancestory);
            }
            ancestory.Remove(v);
        }
        private void Explore(int start)
        {
            _distance.SetValue(start, 0);

            var queue = new Queue <int>();

            queue.Enqueue(start);
            while (queue.Any())
            {
                var current = queue.Dequeue();
                foreach (var neighbor in _graph.NeighborIndexes(current).Where(i => i != current))
                {
                    if (_distance.Visited(neighbor))
                    {
                        continue;
                    }

                    queue.Enqueue(neighbor);
                    _distance.SetValue(neighbor, _distance.GetValue(current) + 1);
                    _visitedFrom.SetValue(neighbor, current);
                }
            }
        }