How to reverse a directed edge in NodeXL .NET library?

Sep 28, 2011 at 4:57 AM

I am implementing an algorithm that requires me to repeatedly reverse the direction of edges over several iterations. Currently, the only way I know is to delete the edge and create a new one. For example:


Graph g = ...;
foreach (IEdge e in AnEdgeIterable)
    G.Edges.Add(e.FrontVertex, e.BackVertex, true);

Is there a better way to do this? In particular, this method causes Edge metadata (added with SetValue) to be lost. Is there any automatic way to copy one Edge metadata to another Edge? Right now I am forced to explicitly declare all the metadata keys to be copied, which introduces a potential problem if the set of metadata were to change.

Sep 28, 2011 at 3:34 PM

Would a simple IEdge.SwapVertices() method suffice?  This would just swap the vertices and leave everything else in place, including the edge's metadata.

-- Tony

Sep 29, 2011 at 2:10 AM

Yes, for my purposes that would be perfect. Does such a method exist already? It is not on the list suggested by IntelliSense.

In general though, it would be useful to have a way of at least getting a list of what keys are associated with an IMetadataProvider. 

Sep 29, 2011 at 3:58 AM

No, but I've added it to the feature request list.  In the meantime, you could use .NET Reflection to break into the Microsoft.NodeXL.Core.Edge class and swap the protected fields that store the vertices.  The relevant fields look like this:

    //  Protected fields

    /// First vertex.  If m_bIsDirected is true, this is the edge's back
    /// vertex.  Can't be null.

    protected IVertex m_oVertex1;

    /// Second vertex.  If m_bIsDirected is true, this is the edge's front
    /// vertex.  Can't be null.

    protected IVertex m_oVertex2;

-- Tony

Sep 29, 2011 at 4:00 AM

By the way, a help file is included in the NodeXL Class Libraries, so you don't have to rely entirely on IntelliSense.  It's called NodeXLApi.chm.

-- Tony