Esempio n. 1
0
    public virtual void AddArc(IArc arc)
    {
        if (arc == null)
        {
            throw new ArgumentNullException();
        }
        if (_arcs == null || _adjacencyList == null)
        {
            throw new NullReferenceException();
        }

        foreach (IArc element in _arcs)
        {
            if (element.Equals(arc))
            {
                return;
            }
        }
        IArc  newArc = arc.Clone();
        INode begin  = newArc.Begin;
        INode end    = newArc.End;

        AddNode(begin);
        AddNode(end);

        _arcs.Add(newArc);
        _adjacencyList[end].Add(newArc);
        _adjacencyList[begin].Add(newArc);
    }
Esempio n. 2
0
 /// <summary>
 /// Group of methods and operator overloads that add some (0-...) arcs to the graph,
 /// AddArc(IArc arc) only is basic method
 /// </summary>
 /// <param name="arc"></param>
 public virtual void AddArc(IArc arc)
 {
     if (arc == null)
     {
         throw new ArgumentNullException();
     }
     if (_insideGraph == null)
     {
         throw new NullReferenceException();
     }
     _insideGraph.AddArc(arc.Clone());
 }
Esempio n. 3
0
    public override void AddArc(IArc arc)
    {
        if (arc == null)
        {
            throw new ArgumentNullException();
        }
        if (_arcs == null || _adjacencyList == null)
        {
            throw new NullReferenceException();
        }

        foreach (IArc element in _arcs)
        {
            if (element.Equals(arc))
            {
                return;
            }
        }
        IArc newArc = arc.Clone();

        _arcs.Add(newArc);
        INode begin = newArc.Begin;
        INode end   = newArc.End;

        base.AddNode(begin);
        base.AddNode(end);
        _adjacencyList[end].Add(newArc);
        _adjacencyList[begin].Add(newArc);
        if (!_components.ContainsKey(begin))
        {
            if (!_components.ContainsKey(end))
            {
                _components[end] = _components[begin] = ++_maxComponent;
            }
            else
            {
                _components[begin] = _components[end];
            }
        }
        else
        {
            if (!_components.ContainsKey(end))
            {
                _components[end] = _components[begin];
            }
            else
            {
                BFS(begin, Math.Min(_components[begin], _components[end]));
            }
        }
    }