GoDiagram is currently in beta -- See here for details, or contact us if you have questions or feedback.

Class GenericNetwork<V, E, Y>

GoDiagram
v10.0.0-beta6
by Northwoods Software®

This provides an abstract view of a diagram as a network (graph) of vertexes and directed edges. The network contains vertexes and edges corresponding to Nodes and Links.

Namespace: Northwoods.Go.Layouts
Assembly: Northwoods.GoDiagram.WinForms.dll
Syntax
public class GenericNetwork<V, E, Y>
    where V : GenericNetwork<V, E, Y>.Vertex where E : GenericNetwork<V, E, Y>.Edge where Y : Layout
Type Parameters
Name Description
V
E
Y
Remarks

This class provides a framework for manipulating the state of nodes and links without modifying the structure of the diagram. Having a separate representation also permits adding or removing vertexes or edges from the network so that the graph that is laid out is not isomorphic to the diagram's graph.

For each kind of layout that uses a GenericNetwork there is a subclass of GenericNetwork<V, E, Y>.Vertex and a subclass of GenericNetwork<V, E, Y>.Edge:

  • : and
  • : and
  • : and
  • : and

Modifying a GenericNetwork<V, E, Y> or a GenericNetwork<V, E, Y>.Vertex or an GenericNetwork<V, E, Y>.Edge does not invalidate the Layout or raise any changed events.

Constructors

GenericNetwork(Y)

This constructs an empty network associated with a given layout.

Declaration
public GenericNetwork(Y layout)
Parameters
Type Name Description
Y layout
Remarks

It is commonplace to call AddParts(IEnumerable<Part>, Boolean, Predicate<Part>) to build up the network to have the same structure as a Diagram's or Group's nodes and links.

Properties

Edges

Gets a collection of all of the GenericNetwork<V, E, Y>.Edges in this network.

Declaration
public IReadOnlyCollection<E> Edges { get; }
Property Value
Type Description
System.Collections.Generic.IReadOnlyCollection<E>
Remarks

Do not modify this collection directly. Instead, call AddEdge(E), DeleteEdge(E), AddLink(Link), or DeleteLink(Link).

Layout

Gets the Layout that uses this network of GenericNetwork<V, E, Y>.Vertexes and GenericNetwork<V, E, Y>.Edges.

Declaration
public Y Layout { get; set; }
Property Value
Type Description
Y
Remarks

The default value is null. It is set automatically for you when setting Network.

Vertexes

Gets a collection of all of the GenericNetwork<V, E, Y>.Vertexes in this network.

Declaration
public IReadOnlyCollection<V> Vertexes { get; }
Property Value
Type Description
System.Collections.Generic.IReadOnlyCollection<V>
Remarks

Do not modify this collection directly. Instead, call AddVertex(V), DeleteVertex(V), AddNode(Node), or DeleteNode(Node).

Methods

AddEdge(E)

Adds an GenericNetwork<V, E, Y>.Edge to the network.

Declaration
public void AddEdge(E edge)
Parameters
Type Name Description
E edge
Remarks

Although this method is provided for completeness, LinkVertexes(V, V, Link) provides a more efficient manner of linking vertexes already in the network.

This convenience method makes sure there is an GenericNetwork<V, E, Y>.Edge in this network corresponding to a Link.

Declaration
public E AddLink(Link link)
Parameters
Type Name Description
Link link
Returns
Type Description
E

an edge in this network.

If FindEdge(Link) returns null, this method creates a new GenericNetwork<V, E, Y>.Edge, makes sure the FromNode and ToNode have corresponding GenericNetwork<V, E, Y>.Vertexes in the network, and adds the edge itself to the network.

AddNode(Node)

This convenience method makes sure there is a GenericNetwork<V, E, Y>.Vertex in this network corresponding to a Node.

Declaration
public V AddNode(Node node)
Parameters
Type Name Description
Node node
Returns
Type Description
V

a vertex in this network.

AddParts(IEnumerable<Part>, Boolean, Predicate<Part>)

Creates a network of GenericNetwork<V, E, Y>.Vertexes and GenericNetwork<V, E, Y>.Edges corresponding to the given Nodes and Links.

Declaration
public void AddParts(IEnumerable<Part> parts, bool toplevelonly = false, Predicate<Part> pred = null)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<Part> parts

A collection of Nodes or Links.

System.Boolean toplevelonly

whether to skip Parts in the given collection that are contained by Groups; default is false

System.Predicate<Part> pred

optional predicate to apply to each Part -- if it returns false do not include Vertex or Edge in the network; default ignores link label nodes or links connecting with them

Remarks

This is usually more convenient than repeatedly calling AddNode(Node) and AddLink(Link). This method ignores all instances of Parts that are not Nodes or Links. This will recurse through Groups that have no Layout.

AddVertex(V)

Adds a GenericNetwork<V, E, Y>.Vertex to the network.

Declaration
public void AddVertex(V vertex)
Parameters
Type Name Description
V vertex

CreateEdge()

Allocate a new instance of GenericNetwork<V, E, Y>.Edge.

Declaration
public virtual E CreateEdge()
Returns
Type Description
E
Remarks

This is overridden in GenericNetwork subclasses to create instances of subclasses of GenericNetwork<V, E, Y>.Edge. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

CreateVertex()

Allocate a new instance of GenericNetwork<V, E, Y>.Vertex.

Declaration
public virtual V CreateVertex()
Returns
Type Description
V
Remarks

This is overridden in GenericNetwork subclasses to create instances of subclasses of GenericNetwork<V, E, Y>.Vertex. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

DeleteArtificialVertexes()

Deletes all vertexes and edges that have no Part associated with them.

Declaration
public virtual void DeleteArtificialVertexes()

DeleteEdge(E)

Removes an GenericNetwork<V, E, Y>.Edge from the network.

Declaration
public void DeleteEdge(E edge)
Parameters
Type Name Description
E edge

This convenience method deletes from this network any GenericNetwork<V, E, Y>.Edge corresponding to a Link.

Declaration
public void DeleteLink(Link link)
Parameters
Type Name Description
Link link

DeleteNode(Node)

This convenience method deletes any GenericNetwork<V, E, Y>.Vertex corresponding to a Node.

Declaration
public void DeleteNode(Node node)
Parameters
Type Name Description
Node node

DeleteSelfEdges()

Deletes all GenericNetwork<V, E, Y>.Edges whose "to vertex" and "from vertex" are the same vertex.

Declaration
public void DeleteSelfEdges()

DeleteVertex(V)

Removes a GenericNetwork<V, E, Y>.Vertex from the network.

Declaration
public void DeleteVertex(V vertex)
Parameters
Type Name Description
V vertex
Remarks

This function also deletes all edges to or from the vertex.

FindAllParts()

Retrieve all of the Nodes and Links from the GenericNetwork<V, E, Y>.Vertexes and GenericNetwork<V, E, Y>.Edges that are in this network.

Declaration
public IEnumerable<Part> FindAllParts()
Returns
Type Description
System.Collections.Generic.IEnumerable<Part>

A collection of Parts.

Returns the GenericNetwork<V, E, Y>.Edge that was constructed for the Link.

Declaration
public E FindEdge(Link link)
Parameters
Type Name Description
Link link
Returns
Type Description
E

an edge in this network, or null if no such edge exists.

FindVertex(Node)

Returns the GenericNetwork<V, E, Y>.Vertex that was constructed for the Node.

Declaration
public V FindVertex(Node node)
Parameters
Type Name Description
Node node
Returns
Type Description
V

a vertex in this network, or null if no such vertex exists.

Links two vertexes already in the network and returns the created GenericNetwork<V, E, Y>.Edge.

Declaration
public E LinkVertexes(V fromVertex, V toVertex, Link link)
Parameters
Type Name Description
V fromVertex
V toVertex
Link link
Returns
Type Description
E

an edge in this network, or null if both vertexes don't exist.

ReverseEdge(E)

Reverses the direction of a GenericNetwork<V, E, Y>.Edge in the network.

Declaration
public void ReverseEdge(E edge)
Parameters
Type Name Description
E edge

SplitIntoSubNetworks<G>(Boolean)

Modify this network by splitting it up into separate subnetworks, each of which has all of its vertexes connected to each other, but not to any vertexes in any other subnetworks.

Declaration
public IEnumerator<G> SplitIntoSubNetworks<G>(bool clean = true)
    where G : GenericNetwork<V, E, Y>
Parameters
Type Name Description
System.Boolean clean

whether to delete artificial vertexes and edges, disconnected edges, and reflexive edges; default is true

Returns
Type Description
System.Collections.Generic.IEnumerator<G>

a collection of GenericNetwork<V, E, Y>s, sorted in order of decreasing vertex count.

Type Parameters
Name Description
G
Remarks

This method will first delete from this network all artificial vertexes and all edges that do not connect two different vertexes. Afterwards, this original network may be empty or may contain all of the singleton vertexes, each of which had no edges connecting it to any other vertexes.