Class NetworkValidation
- Namespace
- SpatialNET.Network
- Assembly
- SpatialNET.Network.dll
Checks SpatialNET.Network.NetworkRules on an SpatialNET.Network.IGraph`2 (ADR 0052). The methods stream: they read their input in blocks, ask the graph for the nodes and the edges of a block in one batch each, and yield the violations of the block before they read the next one. Pass the elements sorted by shard, so that the neighbours of a block come from the shards that are already in the cache.
public static class NetworkValidationInheritance
Inherited Members
Remarks
An edge rule is checked at each chosen end on its own. The edge itself never counts, parallel edges count one by one, a loop counts once, and the switching state does not matter: a disabled edge counts like any other.
A loop has two ends that are the same node; an edge rule checks both, in the order of the ends.
Thread-safe as far as the graph is: a check has no shared state.
Methods
Validate<TNodeId, TEdgeId>(IGraph<TNodeId, TEdgeId>, IEnumerable<TNodeId>, IEnumerable<NetworkRule>, CancellationToken)
Checks the node rules for the given nodes and the edge rules for every edge at them, each edge once. It remembers the nodes and edges it has checked, so it is meant for a bounded area such as one local network; over the whole network use SpatialNET.Network.NetworkValidation.ValidateNodes``2(SpatialNET.Network.IGraph{``0,``1},System.Collections.Generic.IEnumerable{``0},System.Collections.Generic.IEnumerable{SpatialNET.Network.NetworkRule},System.Threading.CancellationToken) and SpatialNET.Network.NetworkValidation.ValidateEdges``2(SpatialNET.Network.IGraph{``0,``1},System.Collections.Generic.IEnumerable{SpatialNET.Network.GraphEdge{``0,``1}},System.Collections.Generic.IEnumerable{SpatialNET.Network.NetworkRule},System.Threading.CancellationToken).
public static IEnumerable<RuleViolation<TNodeId, TEdgeId>> Validate<TNodeId, TEdgeId>(this IGraph<TNodeId, TEdgeId> graph, IEnumerable<TNodeId> nodes, IEnumerable<NetworkRule> rules, CancellationToken cancellationToken = default) where TNodeId : notnull, IEquatable<TNodeId> where TEdgeId : notnull, IEquatable<TEdgeId>Parameters
graphIGraph<TNodeId, TEdgeId>-
The network.
nodesIEnumerable<TNodeId>-
The ids of the nodes of the area; a node given twice is checked once. Edges of the nodes may lead to nodes outside the area, which count as context and are not checked.
rulesIEnumerable<NetworkRule>-
The rules. Ids must be unique.
cancellationTokenCancellationToken-
Stops the check between two blocks.
Returns
- IEnumerable<RuleViolation<TNodeId, TEdgeId>>
-
The violations in the order of the nodes: for each node its node rules, then the edge rules of the edges first met at it.
Type Parameters
TNodeIdTEdgeId
Exceptions
- ArgumentNullException
-
An argument or a rule is
null. - ArgumentException
-
Two rules have the same id.
- InvalidGraphException
-
While enumerating: a given node or the node at an end of an edge is not in the graph.
- OperationCanceledException
-
While enumerating: the token was cancelled.
ValidateEdges<TNodeId, TEdgeId>(IGraph<TNodeId, TEdgeId>, IEnumerable<GraphEdge<TNodeId, TEdgeId>>, IEnumerable<NetworkRule>, CancellationToken)
Checks the edge rules of rules for each given edge record. It keeps no set of checked edges, so
an edge given twice is checked twice.
public static IEnumerable<RuleViolation<TNodeId, TEdgeId>> ValidateEdges<TNodeId, TEdgeId>(this IGraph<TNodeId, TEdgeId> graph, IEnumerable<GraphEdge<TNodeId, TEdgeId>> edges, IEnumerable<NetworkRule> rules, CancellationToken cancellationToken = default) where TNodeId : notnull, IEquatable<TNodeId> where TEdgeId : notnull, IEquatable<TEdgeId>Parameters
graphIGraph<TNodeId, TEdgeId>-
The network.
edgesIEnumerable<GraphEdge<TNodeId, TEdgeId>>-
The edges to check as the host read them, ideally sorted by shard.
rulesIEnumerable<NetworkRule>-
The rules; the node rules are ignored. Ids must be unique.
cancellationTokenCancellationToken-
Stops the check between two blocks.
Returns
- IEnumerable<RuleViolation<TNodeId, TEdgeId>>
-
The violations in the order of the input, for one edge in the order of the rules, at
FrombeforeTo.
Type Parameters
TNodeIdTEdgeId
Exceptions
- ArgumentNullException
-
An argument or a rule is
null. - ArgumentException
-
Two rules have the same id.
- InvalidGraphException
-
While enumerating: the graph does not return the node at an end of an edge.
- OperationCanceledException
-
While enumerating: the token was cancelled.
ValidateNodes<TNodeId, TEdgeId>(IGraph<TNodeId, TEdgeId>, IEnumerable<TNodeId>, IEnumerable<NetworkRule>, CancellationToken)
Checks the node rules of rules for each given node. Meant for streams over the whole network; it
keeps no set of checked nodes, so a node given twice is checked twice.
public static IEnumerable<RuleViolation<TNodeId, TEdgeId>> ValidateNodes<TNodeId, TEdgeId>(this IGraph<TNodeId, TEdgeId> graph, IEnumerable<TNodeId> nodes, IEnumerable<NetworkRule> rules, CancellationToken cancellationToken = default) where TNodeId : notnull, IEquatable<TNodeId> where TEdgeId : notnull, IEquatable<TEdgeId>Parameters
graphIGraph<TNodeId, TEdgeId>-
The network.
nodesIEnumerable<TNodeId>-
The ids of the nodes to check, ideally sorted by shard.
rulesIEnumerable<NetworkRule>-
The rules; the edge rules are ignored. Ids must be unique.
cancellationTokenCancellationToken-
Stops the check between two blocks.
Returns
- IEnumerable<RuleViolation<TNodeId, TEdgeId>>
-
The violations in the order of the input, for one node in the order of the rules.
Type Parameters
TNodeIdTEdgeId
Exceptions
- ArgumentNullException
-
An argument or a rule is
null. - ArgumentException
-
Two rules have the same id.
- InvalidGraphException
-
While enumerating: a given node is not in the graph.
- OperationCanceledException
-
While enumerating: the token was cancelled.