本文整理汇总了C#中AdjacencyGraph.RemoveVertex方法的典型用法代码示例。如果您正苦于以下问题:C# AdjacencyGraph.RemoveVertex方法的具体用法?C# AdjacencyGraph.RemoveVertex怎么用?C# AdjacencyGraph.RemoveVertex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AdjacencyGraph
的用法示例。
在下文中一共展示了AdjacencyGraph.RemoveVertex方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetOrderedListOfDependencies
public static IEnumerable<string> GetOrderedListOfDependencies(AdjacencyGraph<string, Edge<string>> graph)
{
var vertices = graph.Vertices.ToList();
var orderedList = new List<string>();
while (vertices.Count > 0)
{
var vertexToRemove = new List<string>();
var edgesToRemove = new List<Edge<string>>();
foreach (var vertex in vertices)
{
var outEdges = graph.OutEdges(vertex).ToList();
if (outEdges.Count == 0)
{
orderedList.Add(vertex);
string vertex1 = vertex;
edgesToRemove.AddRange(graph.Edges.Where(edge => edge.Target == vertex1));
vertexToRemove.Add(vertex);
}
}
if (vertexToRemove.Count == 0)
throw new InvalidOperationException("Graph has circular dependencies");
edgesToRemove.ForEach(edge => graph.RemoveEdge(edge));
vertexToRemove.ForEach(vertex =>
{
graph.RemoveVertex(vertex);
vertices.Remove(vertex);
});
}
return orderedList;
}
示例2: FindDecisionPattern
/// <summary>
/// Znajduje wszystkie paterny dec
/// </summary>
/// <param name="g"></param>
/// <returns></returns>
public AdjacencyGraph<Node, Edge<Node>> FindDecisionPattern(AdjacencyGraph<Node, Edge<Node>> g)
{
List<Node> decisionNodes = g.Vertices.Where(x => x.Type == NodeType.DecisionNode).ToList();
foreach (var decisionNode in decisionNodes)
{
var outEdges = g.OutEdges(decisionNode);
var left = outEdges.ElementAt(0).Target;
var right = outEdges.ElementAt(1).Target;
var upperEdge = g.Edges.Where(x => x.Target == decisionNode).ToList().FirstOrDefault();
if (g.OutEdges(left).Count() == 1 && g.OutEdges(right).Count() == 1 && (
g.OutEdges(left).ElementAt(0).Target == g.OutEdges(right).ElementAt(0).Target)
|| g.OutEdges(left).ElementAt(0).Target == right
|| g.OutEdges(right).ElementAt(0).Target == left
|| left.Type==NodeType.ActivityFinalNode
|| right.Type==NodeType.ActivityFinalNode)
{
string name = "dec(" + decisionNode.Name + ", " + left.Name + ", " + right.Name + ")";
var decisionPattern = new Node(name, NodeType.DecisionPattern);
g.AddVertex(decisionPattern);
var nextNode = g.OutEdges(right).ElementAt(0).Target;
if(nextNode == left || nextNode==right)
nextNode = g.OutEdges(left).ElementAt(0).Target;
g.AddEdge(new Edge<Node>(upperEdge.Source, decisionPattern));
g.AddEdge(new Edge<Node>(decisionPattern, nextNode));
g.RemoveVertex(decisionNode);
g.RemoveVertex(left);
g.RemoveVertex(right);
}
}
return g;
}
示例3: MakeLoopPattern
/// <summary>
/// Tworzy noda typu loop
/// </summary>
/// <param name="g"></param>
/// <param name="decisionNode"></param>
/// <param name="d"></param>
/// <param name="e"></param>
/// <param name="previousNode"></param>
/// <param name="nextNode"></param>
/// <returns></returns>
private AdjacencyGraph<Node, Edge<Node>> MakeLoopPattern(AdjacencyGraph<Node, Edge<Node>> g, Node decisionNode,
Node d, Node e, Node previousNode, Node nextNode)
{
string name = "loop(" + d.Name + "," + decisionNode.Name + "," + e.Name + ")";
var loopPattern = new Node(name, NodeType.LoopPattern);
g.AddVertex(loopPattern);
g.AddEdge(new Edge<Node>(previousNode, loopPattern));
g.AddEdge(new Edge<Node>(loopPattern, nextNode));
g.RemoveVertex(d);
g.RemoveVertex(e);
g.RemoveVertex(decisionNode);
return g;
}
示例4: FindSeqPattern
/// <summary>
/// Znajduje wszystkie paterny seq
/// </summary>
/// <param name="g"></param>
/// <returns></returns>
public AdjacencyGraph<Node, Edge<Node>> FindSeqPattern(AdjacencyGraph<Node, Edge<Node>> g)
{
var chuj = true;
while (chuj)
{
List<Edge<Node>> followingEdges = GetEdgesForSeq(g);
if (followingEdges.Count == 0)
{
chuj = false;
continue;
}
var followingEdge = followingEdges.FirstOrDefault();
//utworzenie nowego seq patternu
string name = "seq(" + followingEdge.Source.Name + "," + followingEdge.Target.Name + ")";
var seqPattern = new Node(name, NodeType.SeqPattern);
//znalezienie poprzedniego i nastepnego polaczenia polaczenia
var upperEdge = g.Edges.Where(x => x.Target == followingEdge.Source).ToList().FirstOrDefault();
var lowerEdge = g.OutEdges(followingEdge.Target).ElementAt(0);
//dodanie noda i polaczen
g.AddVertex(seqPattern);
g.AddEdge(new Edge<Node>(upperEdge.Source, seqPattern));
g.AddEdge(new Edge<Node>(seqPattern, lowerEdge.Target));
//usuniecie starych nodow
g.RemoveVertex(followingEdge.Source);
g.RemoveVertex(followingEdge.Target);
}
return g;
}
示例5: FindParPattern
/// <summary>
/// Znajduje wszystkie paterny par
/// </summary>
/// <param name="g"></param>
/// <returns></returns>
public AdjacencyGraph<Node, Edge<Node>> FindParPattern(AdjacencyGraph<Node, Edge<Node>> g)
{
List<Node> forkNodes = g.Vertices.Where(x => x.Type == NodeType.ForkNode).ToList();
foreach (var forkNode in forkNodes)
{
var forkEdges = g.Edges.Where(x => x.Source == forkNode).ToList();
var leftEdge = forkEdges[0];
var rightEdge = forkEdges[1];
var forkInEdge = g.Edges.Where(x => x.Target == forkNode).ToList().FirstOrDefault();
var leftOutNode = g.OutEdges(leftEdge.Target).ElementAt(0).Target;
var rightOutNode = g.OutEdges(rightEdge.Target).ElementAt(0).Target;
var startParNode = forkInEdge.Source;
var startParNodeInEdge = g.Edges.Where(x => x.Target == startParNode).ToList().FirstOrDefault();
if (leftOutNode == rightOutNode && leftOutNode.Type == NodeType.JoinNode)
{
string name = "par(" + forkInEdge.Source.Name + "," + leftEdge.Target.Name + "," +
rightEdge.Target.Name + ")";
var parPattern = new Node(name, NodeType.ParPattern);
//dodaje pattern
g.AddVertex(parPattern);
g.AddEdge(new Edge<Node>(startParNodeInEdge.Source, parPattern));
g.AddEdge(new Edge<Node>(parPattern, g.OutEdges(rightOutNode).ElementAt(0).Target));
//usuwa fork,join,a,b
g.RemoveVertex(leftEdge.Target);
g.RemoveVertex(rightEdge.Target);
g.RemoveVertex(forkNode);
g.RemoveVertex(rightOutNode);
g.RemoveVertex(startParNode);
}
}
return g;
}
示例6: MinimalCutFind
public void MinimalCutFind(AdjacencyGraph<int, Edge<int>> graph)
{
if (graph == null)
throw new ArgumentNullException("graph");
List<int> results = new List<int>();
for (int i = 1; i <= (graph.VertexCount * graph.VertexCount); i++)
{
while (graph.VertexCount > 2)
{
// get the vertext to delete
int x = _random.Next(0, graph.VertexCount);
int vertexToDelete = graph.Vertices.ElementAt(x);
// get the target vertex to merge to
IEnumerable<Edge<int>> e = new List<Edge<int>>();
graph.TryGetOutEdges(vertexToDelete, out e);
int r = _random.Next(0, e.Count());
int vertexToMergeTo = e.ElementAt(r).Target;
// list of edges which need to be merged based on the vertex to delete
IEnumerable<Edge<int>> edgesToMerge = new List<Edge<int>>();
graph.TryGetOutEdges(vertexToDelete, out edgesToMerge);
// temp lists to store the edges to add and remove.
List<Edge<int>> edgesToRemove = new List<Edge<int>>();
List<Edge<int>> edgesToAdd = new List<Edge<int>>();
// for each edge, create a new edge linked to the target vertex. If the target is the same remove.
foreach (Edge<int> edge in edgesToMerge)
{
if (vertexToMergeTo == edge.Target)
{
edgesToRemove.Add(edge);
}
else
{
Edge<int> newEdge = new Edge<int>(vertexToMergeTo, edge.Target);
edgesToAdd.Add(newEdge);
Edge<int> newEdgeB = new Edge<int>(edge.Target, vertexToMergeTo);
edgesToAdd.Add(newEdgeB);
edgesToRemove.Add(edge);
Edge<int> newEdgeD = null;
graph.TryGetEdge(edge.Target, edge.Source, out newEdgeD);
edgesToRemove.Add(newEdgeD);
}
}
// remove old vertexes
foreach (Edge<int> edge in edgesToRemove)
{
graph.RemoveEdge(edge);
}
// remove old vertexes
foreach (Edge<int> edge in edgesToAdd)
{
graph.AddEdge(edge);
}
graph.RemoveVertex(vertexToDelete);
}
}
IEnumerable<Edge<int>> edges1 = new List<Edge<int>>();
IEnumerable<Edge<int>> edges2 = new List<Edge<int>>();
graph.TryGetOutEdges(graph.Vertices.ElementAt(0), out edges1);
graph.TryGetOutEdges(graph.Vertices.ElementAt(1), out edges2);
results.Add(edges1.Count());
Console.Write(results.Min());
Console.ReadLine();
}