Class Network<V, E, Y>

GoDiagram®
v10.0.12
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.Avalonia.dll
Syntax
public class Network<V, E, Y> where V : Network<V, E, Y>.Vertex where E : Network<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 Network there is a subclass of Network<V, E, Y>.Vertex and a subclass of Network<V, E, Y>.Edge:

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

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

Constructors

Network(Y)

This constructs an empty network associated with a given layout.

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

It is commonplace to call AddParts(IEnumerable<Part>, bool, 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 Network<V, E, Y>.Edges in this network.

Declaration
public IReadOnlyCollection<E> Edges { get; }
Property Value
Type Description
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 Network<V, E, Y>.Vertexes and Network<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 Network<V, E, Y>.Vertexes in this network.

Declaration
public IReadOnlyCollection<V> Vertexes { get; }
Property Value
Type Description
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 Network<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 Network<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 Network<V, E, Y>.Edge, makes sure the FromNode and ToNode have corresponding Network<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 Network<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>, bool, Predicate<Part>)

Creates a network of Network<V, E, Y>.Vertexes and Network<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
IEnumerable<Part> parts

A collection of Nodes or Links.

bool toplevelonly

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

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 Network<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 Network<V, E, Y>.Edge.

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

This is overridden in Network subclasses to create instances of subclasses of Network<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 Network<V, E, Y>.Vertex.

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

This is overridden in Network subclasses to create instances of subclasses of Network<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 Network<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 Network<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 Network<V, E, Y>.Vertex corresponding to a Node.

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

DeleteSelfEdges()

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

Declaration
public void DeleteSelfEdges()

DeleteVertex(V)

Removes a Network<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 Network<V, E, Y>.Vertexes and Network<V, E, Y>.Edges that are in this network.

Declaration
public IEnumerable<Part> FindAllParts()
Returns
Type Description
IEnumerable<Part>

A collection of Parts.

Returns the Network<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 Network<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 Network<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 Network<V, E, Y>.Edge in the network.

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

SplitIntoSubNetworks<G>(bool)

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 : Network<V, E, Y>
Parameters
Type Name Description
bool clean

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

Returns
Type Description
IEnumerator<G>

a collection of Network<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.