Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/05/15 13:55:04 (10 years ago)
Author:
bburlacu
Message:

#2223: Moved Data member to the generic versions of Vertex and Arc (restricted to be an IDeepCloneable). Fixed AddVertices method and added complementary AddArcs and RemoveArcs methods.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core/3.3/Collections/DirectedGraph/DirectedGraph.cs

    r11444 r11912  
    102102        vertex.ArcAdded += Vertex_ArcAdded;
    103103        vertex.ArcRemoved += Vertex_ArcRemoved;
    104         OnVertedAdded(this, new EventArgs<IVertex>(vertex));
     104        OnVertexAdded(this, new EventArgs<IVertex>(vertex));
    105105      }
    106106    }
    107107
    108108    public virtual void AddVertices(IEnumerable<IVertex> vertexList) {
    109       var hash = new HashSet<IVertex>(vertexList);
    110       var arcList = vertexList.SelectMany(v => v.InArcs.Concat(v.OutArcs));
    111       if (arcList.Any(x => !hash.Contains(x.Source) || !hash.Contains(x.Target)))
    112         throw new ArgumentException("Vertex arcs are connected to vertices not in the graph.");
    113       // if everything is in order, add the vertices to the directed graph
    114       foreach (var v in vertexList)
    115         vertices.Add(v);
    116       foreach (var a in arcList)
    117         arcs.Add(a);
     109      foreach (var v in vertexList) { AddVertex(v); }
    118110    }
    119111
    120112    public virtual void RemoveVertices(IEnumerable<IVertex> vertexList) {
    121       foreach (var v in vertexList)
    122         RemoveVertex(v);
     113      foreach (var v in vertexList) { RemoveVertex(v); }
    123114    }
    124115
     
    156147    }
    157148
     149    public virtual void AddArcs(IEnumerable<IArc> arcList) {
     150      foreach (var a in arcList) { AddArc(a); }
     151    }
     152
    158153    public virtual void RemoveArc(IArc arc) {
    159154      arcs.Remove(arc);
     
    164159    }
    165160
     161    public virtual void RemoveArcs(IEnumerable<IArc> arcList) {
     162      foreach (var a in arcList) { RemoveArc(a); }
     163    }
     164
    166165    protected virtual void Vertex_ArcAdded(object sender, EventArgs<IArc> args) {
    167166      // the ArcAdded event is fired by a vertex when an arc from/to another vertex is added to its list of connections
     
    178177    // events
    179178    public event EventHandler<EventArgs<IVertex>> VertexAdded;
    180     protected virtual void OnVertedAdded(object sender, EventArgs<IVertex> args) {
     179    protected virtual void OnVertexAdded(object sender, EventArgs<IVertex> args) {
    181180      var added = VertexAdded;
    182181      if (added != null)
Note: See TracChangeset for help on using the changeset viewer.