本文整理汇总了C#中AdjacencyGraph.RemoveEdge方法的典型用法代码示例。如果您正苦于以下问题:C# AdjacencyGraph.RemoveEdge方法的具体用法?C# AdjacencyGraph.RemoveEdge怎么用?C# AdjacencyGraph.RemoveEdge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AdjacencyGraph
的用法示例。
在下文中一共展示了AdjacencyGraph.RemoveEdge方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: BuildDependencyGraph
public static AdjacencyGraph<PropertyInfo, STaggedEdge<PropertyInfo, string>> BuildDependencyGraph(IEnumerable<Type> viewModelTypes)
{
var graph = new AdjacencyGraph<PropertyInfo, STaggedEdge<PropertyInfo, string>>();
foreach (var dependencyGraphWithinViewModel in viewModelTypes.Select(BuildDependencyGraph))
{
dependencyGraphWithinViewModel.Vertices.ForEach(v => graph.AddVertex(v));
dependencyGraphWithinViewModel.Edges.ForEach(e => graph.AddEdge(e));
}
while (graph.Edges.Any(e => !String.IsNullOrEmpty(e.Tag)))
{
var edge = graph.Edges.First(e => !String.IsNullOrEmpty(e.Tag));
var index = edge.Tag.IndexOf(".");
var path = index < 0 ? edge.Tag : edge.Tag.Substring(0, index);
var rest = index < 0 ? null : edge.Tag.Substring(index + 1);
var propertyType = edge.Source.PropertyType;
if (GetCollectionType(propertyType) != null) propertyType = GetCollectionType(propertyType);
if (path != "*")
{
var property = ViewModelConventions.GetViewModelProperties(propertyType).FirstOrDefault(p => p.Name == path);
if (property != null)
{
graph.AddEdge(new STaggedEdge<PropertyInfo, string>(property, edge.Target, rest));
}
else
{
ViewModelConventions.Log.Warn(String.Format("Could not resolve '{0}' on '{1}'.", path, propertyType));
}
}
else
{
var properties = ViewModelConventions.GetViewModelProperties(propertyType).ToList();
properties.ForEach(p => graph.AddEdge(new STaggedEdge<PropertyInfo, string>(p, edge.Target, rest)));
}
graph.RemoveEdge(edge);
}
var edges = graph.Edges.ToArray();
graph.RemoveVertexIf(v => !edges.Any(e => e.Source == v || e.Target == v));
return graph;
}
示例3: 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();
}