Ignore:
Timestamp:
08/04/14 14:58:47 (8 years ago)
Author:
bburlacu
Message:

#2223:

  • Vertex: remove cloning of arcs in the cloning constructor
  • DirectedGraph; Adjust cloning constructor to add arcs to cloned vertices
File:
1 edited

Legend:

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

    r11251 r11263  
    5757      vertices = new HashSet<IVertex>(original.vertices.Select(cloner.Clone));
    5858      arcs = new HashSet<IArc>(original.arcs.Select(cloner.Clone));
     59
     60      // add the arcs to the newly cloned vertices
     61      foreach (var arc in arcs) {
     62        arc.Source.AddArc(arc);
     63        arc.Target.AddArc(arc);
     64      }
    5965    }
    6066
     
    8995
    9096    public virtual void AddVertex(IVertex vertex) {
    91       vertices.Add(vertex);
    92       // register event handlers
    93       vertex.ArcAdded += Vertex_ArcAdded;
    94       vertex.ArcRemoved += Vertex_ArcRemoved;
    95       OnVertedAdded(this, new EventArgs<IVertex>(vertex));
     97      if (!vertices.Contains(vertex) && vertex.Degree > 0)
     98        throw new ArgumentException("New vertices cannot have any arcs.");
     99
     100      if (vertices.Add(vertex)) {
     101        // register event handlers
     102        vertex.ArcAdded += Vertex_ArcAdded;
     103        vertex.ArcRemoved += Vertex_ArcRemoved;
     104        OnVertedAdded(this, new EventArgs<IVertex>(vertex));
     105      }
    96106    }
    97107
Note: See TracChangeset for help on using the changeset viewer.