Here are the examples of the csharp api System.Predicate.Invoke(TEdge) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
19
Source : TopologicalSorter.cs
with MIT License
from DataObjects-NET
with MIT License
from DataObjects-NET
public static TopologicalSortResult<TNode, TEdge> Sort<TNode, TEdge>(Graph<TNode, TEdge> graph, Predicate<TEdge> edgeBreaker = null)
where TNode: Node
where TEdge: Edge
{
ArgumentValidator.EnsureArgumentNotNull(graph, "graph");
var result = new TopologicalSortResult<TNode, TEdge>();
HashSet<TNode> sortedNodes;
OrderedSet<TNode> unsortedNodes;
Queue<TEdge> breakableEdges;
if (edgeBreaker!=null) {
sortedNodes = null;
unsortedNodes = new OrderedSet<TNode>(graph.Nodes);
breakableEdges = new Queue<TEdge>(graph.Edges);
}
else {
sortedNodes = new HashSet<TNode>();
unsortedNodes = null;
breakableEdges = null;
}
var nodesWithoutIncomingEdges = new Queue<TNode>(graph.Nodes.Where(n => !n.HasIncomingEdges));
restart:
// Sorting
while (nodesWithoutIncomingEdges.Count!=0) {
var node = nodesWithoutIncomingEdges.Dequeue();
if (unsortedNodes!=null) // Break edges
unsortedNodes.Remove(node);
else
sortedNodes.Add(node);
result.SortedNodes.Add(node);
if (!node.HasOutgoingEdges)
continue;
foreach (var edge in node.OutgoingEdges) {
edge.Target.IncomingEdges.Remove(edge);
edge.IsAttached = false; // actually, Detach(), because we perform node.OutgoingEdges.Clear() further
var target = (TNode) edge.Target;
if (!target.HasIncomingEdges)
nodesWithoutIncomingEdges.Enqueue(target);
}
node.OutgoingEdges.Clear();
}
if (unsortedNodes!=null) { // Break edges
if (unsortedNodes.Count != 0) {
// Trying to break edges (collection is always empty when breakEdges==false)
while (breakableEdges.Count != 0) {
var edge = breakableEdges.Dequeue();
if (!edge.IsAttached || !edgeBreaker(edge))
continue;
result.BrokenEdges.Add(edge);
edge.Detach();
var target = (TNode) edge.Target;
if (!target.HasIncomingEdges) {
nodesWithoutIncomingEdges.Enqueue(target);
goto restart;
}
}
result.LoopNodes.AddRange(unsortedNodes);
}
}
else {
if (sortedNodes.Count != graph.Nodes.Count)
result.LoopNodes.AddRange(graph.Nodes.Where(node => !sortedNodes.Contains(node)));
}
return result;
}
19
Source : GraphHideHelpers.cs
with MIT License
from KeRNeLith
with MIT License
from KeRNeLith
public void UnhideEdgesIf(Predicate<TEdge> predicate)
{
if (predicate is null)
throw new ArgumentNullException(nameof(predicate));
UnhideEdges(_hiddenEdges.Where(edge => predicate(edge)));
}
19
Source : GraphHideHelpers.cs
with MIT License
from KeRNeLith
with MIT License
from KeRNeLith
public void HideEdgesIf(Predicate<TEdge> predicate, string tag)
{
if (predicate is null)
throw new ArgumentNullException(nameof(predicate));
if (tag is null)
throw new ArgumentNullException(nameof(tag));
HideEdges(_graph.Edges.Where(edge => predicate(edge)), tag);
}