本文整理汇总了C#中AdjacencyGraph.ContainsVertex方法的典型用法代码示例。如果您正苦于以下问题:C# AdjacencyGraph.ContainsVertex方法的具体用法?C# AdjacencyGraph.ContainsVertex怎么用?C# AdjacencyGraph.ContainsVertex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AdjacencyGraph
的用法示例。
在下文中一共展示了AdjacencyGraph.ContainsVertex方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: createGraphWizDotFile
//DC this version was using the old QuickGraph MarkedEdge
public static void createGraphWizDotFile(AdjacencyGraph<String, TaggedEdge<String, String>> gGraphWizToPopulate,
TreeNode tnTreeNode, bool bOrder, bool bFilterName, bool bFilterClass,
int iFilterClassLevel)
{
if (bFilterClass)
tnTreeNode.Text = FilteredSignature.filterName(tnTreeNode.Text, false, false, true, 0, true, true,
iFilterClassLevel);
TaggedEdge<String, string> meTemp;
if (gGraphWizToPopulate.ContainsVertex(tnTreeNode.Text))
{
}
else
gGraphWizToPopulate.AddVertex(tnTreeNode.Text);
foreach (TreeNode tnChild in tnTreeNode.Nodes)
{
if (bFilterClass)
tnChild.Text = FilteredSignature.filterName(tnChild.Text, false, false, true, 0, true, true,
iFilterClassLevel);
createGraphWizDotFile(gGraphWizToPopulate, tnChild, bOrder, bFilterName, bFilterClass, iFilterClassLevel);
if (bOrder)
{
if (false == gGraphWizToPopulate.TryGetEdge(tnTreeNode.Text, tnChild.Text, out meTemp))
gGraphWizToPopulate.AddEdge(new TaggedEdge<String, string>(tnTreeNode.Text, tnChild.Text,
"marker"));
}
else if (false == gGraphWizToPopulate.TryGetEdge(tnChild.Text, tnTreeNode.Text, out meTemp))
gGraphWizToPopulate.AddEdge(new TaggedEdge<String, string>(tnChild.Text, tnTreeNode.Text, "marker"));
//gGraphToPopulate.AddEdge(tnTreeNode.Text, tnChild.Text);
// gGraphToPopulate.AddEdge(Analysis_CallFlow.display.filterName(tnChild.Text, false, false, false), Analysis_CallFlow.display.filterName(tnTreeNode.Text, false, false, false));
//else
}
}
示例2: ReconstructGraph
/// <summary>
/// Hopefully some of the stuff above will become slightly more clear in this part of the code. But now we need to
/// replace some of the edges in the graph with the corresponding edges based on the users selections for the source
/// and destination.
/// </summary>
/// <param name="sourceLines">The Two Lines Making Up What Was The Line Closest To The Source</param>
/// <param name="destinationLine">The Two Lines Making Up What Was The Line Cloest To The Destination </param>
/// <param name="sourcePoint">Where The User Wants The Source.</param>
/// <param name="destinationPoint">Where The User Wants The Destination</param>
/// <param name="useCondensedFlag"></param>
/// <returns>True When It Works, False When It Doesnt.</returns>
public bool ReconstructGraph(ILineString[] sourceLines, ILineString[] destinationLine, Coordinate sourcePoint, Coordinate destinationPoint,bool useCondensedFlag)
{
_graph = new AdjacencyGraph<Coordinate, Edge<Coordinate>>(false);
_edgeCost = new Dictionary<Edge<Coordinate>, double>();
//_lookup = new Dictionary<uint, Coordinate>();
var index = (uint)_theLineStrings.Count;
_theLineStrings.Add(index, sourceLines[0]);
index++;
_theLineStrings.Add(index, sourceLines[1]);
index++;
_theLineStrings.Add(index, destinationLine[0]);
index++;
_theLineStrings.Add(index, destinationLine[1]);
if (useCondensedFlag)
{
foreach (var pp in _listOfEndPoints)
{
if ((pp.First.Equals(sourceLines[0].StartPoint.Coordinate)) && (pp.Last.Equals(sourceLines[1].EndPoint.Coordinate)))
{
// We Are Replacting This Line With The Source Line
if (!_graph.ContainsVertex(pp.First))
_graph.AddVertex(pp.First);
if (!_graph.ContainsVertex(pp.Last))
_graph.AddVertex(pp.Last);
if (!_graph.ContainsVertex(sourceLines[0].EndPoint.Coordinate))
_graph.AddVertex(sourceLines[0].EndPoint.Coordinate);
if (!_graph.ContainsVertex(sourceLines[1].StartPoint.Coordinate))
_graph.AddVertex(sourceLines[1].StartPoint.Coordinate);
var e1 = new Edge<Coordinate>(pp.First, sourceLines[0].EndPoint.Coordinate);
var e2 = new Edge<Coordinate>(sourceLines[1].StartPoint.Coordinate, pp.Last);
var e1R = new Edge<Coordinate>(sourceLines[0].EndPoint.Coordinate, pp.First);
var e2R = new Edge<Coordinate>(pp.Last, sourceLines[1].StartPoint.Coordinate);
_graph.AddEdge(e1);
_graph.AddEdge(e2);
_graph.AddEdge(e1R);
_graph.AddEdge(e2R);
_edgeCost.Add(e1, sourceLines[0].Length);
_edgeCost.Add(e2, sourceLines[1].Length);
_edgeCost.Add(e1R, sourceLines[0].Length);
_edgeCost.Add(e2R, sourceLines[1].Length);
}
else if ((pp.First.Equals(destinationLine[0].StartPoint.Coordinate)) &&
(pp.Last.Equals(destinationLine[1].EndPoint.Coordinate)))
{
// We Are Replacing This Line With The Destination Line
if (!_graph.ContainsVertex(pp.First))
_graph.AddVertex(pp.First);
if (!_graph.ContainsVertex(pp.Last))
_graph.AddVertex(pp.Last);
if (!_graph.ContainsVertex(destinationLine[0].EndPoint.Coordinate))
_graph.AddVertex(destinationLine[0].EndPoint.Coordinate);
if (!_graph.ContainsVertex(destinationLine[1].StartPoint.Coordinate))
_graph.AddVertex(destinationLine[1].StartPoint.Coordinate);
var e1 = new Edge<Coordinate>(pp.First, destinationLine[0].EndPoint.Coordinate);
var e2 = new Edge<Coordinate>(destinationLine[1].StartPoint.Coordinate, pp.Last);
var e1R = new Edge<Coordinate>(destinationLine[0].EndPoint.Coordinate, pp.First);
var e2R = new Edge<Coordinate>(pp.Last, destinationLine[1].StartPoint.Coordinate);
_graph.AddEdge(e1);
_graph.AddEdge(e2);
_graph.AddEdge(e1R);
_graph.AddEdge(e2R);
_edgeCost.Add(e1, destinationLine[0].Length);
_edgeCost.Add(e2, destinationLine[1].Length);
_edgeCost.Add(e1R, destinationLine[0].Length);
_edgeCost.Add(e2R, destinationLine[1].Length);
}
else
{
// We Are Carrying On As Normal.
if (!_graph.ContainsVertex(pp.First))
_graph.AddVertex(pp.First);
if (!_graph.ContainsVertex(pp.Last))
_graph.AddVertex(pp.Last);
//.........这里部分代码省略.........
示例3: BuildGraphAndSearchShortestPathUsingGeometryUnion
public void BuildGraphAndSearchShortestPathUsingGeometryUnion()
{
IGeometry edges = a.Union(b).Union(c).Union(d).Union(e);
Assert.IsNotNull(edges);
Assert.IsTrue(edges.GetType() == typeof(MultiLineString));
Assert.Greater(edges.NumGeometries, 0);
foreach (IGeometry edge in ((GeometryCollection) edges).Geometries)
{
Assert.IsNotNull(edge);
Assert.IsTrue(edge.GetType() == typeof(LineString));
Debug.WriteLine(edge);
}
// Build graph
IDictionary<IEdge<IGeometry>, double> consts = new Dictionary<IEdge<IGeometry>, double>(edges.NumGeometries);
AdjacencyGraph<IGeometry, IEdge<IGeometry>> graph = new AdjacencyGraph<IGeometry, IEdge<IGeometry>>(true);
foreach (ILineString str in ((GeometryCollection) edges).Geometries)
{
// Add vertex 1
IGeometry vertex1 = str.StartPoint;
Assert.IsNotNull(vertex1);
if (!graph.ContainsVertex(vertex1))
{
Debug.WriteLine(String.Format("Adding vertex {0} to the list", vertex1));
graph.AddVertex(vertex1);
}
else Debug.WriteLine(String.Format("Vertex {0} already present", vertex1));
// Add vertex 2
IGeometry vertex2 = str.EndPoint;
Assert.IsNotNull(vertex2);
if (!graph.ContainsVertex(vertex2))
{
Debug.WriteLine(String.Format("Adding vertex {0} to the list", vertex2));
graph.AddVertex(vertex2);
}
else Debug.WriteLine(String.Format("Vertex {0} already present", vertex2));
// Compute weight
double weight = weightComputer(str);
Assert.Greater(weight, 0.0);
// Add edge for 1 => 2
IEdge<IGeometry> edge1 = new Edge<IGeometry>(vertex1, vertex2);
Assert.IsNotNull(edge1);
graph.AddEdge(edge1);
consts.Add(edge1, weight);
// Add edge for 2 => 1
IEdge<IGeometry> edge2 = new Edge<IGeometry>(vertex2, vertex1);
Assert.IsNotNull(edge2);
graph.AddEdge(edge2);
consts.Add(edge2, weight);
}
// Perform DijkstraShortestPathAlgorithm
DijkstraShortestPathAlgorithm<IGeometry, IEdge<IGeometry>> dijkstra =
new DijkstraShortestPathAlgorithm<IGeometry, IEdge<IGeometry>>(graph, consts);
// attach a distance observer to give us the shortest path distances
VertexDistanceRecorderObserver<IGeometry, IEdge<IGeometry>> distObserver =
new VertexDistanceRecorderObserver<IGeometry, IEdge<IGeometry>>();
distObserver.Attach(dijkstra);
// Attach a Vertex Predecessor Recorder Observer to give us the paths
VertexPredecessorRecorderObserver<IGeometry, IEdge<IGeometry>> predecessorObserver =
new VertexPredecessorRecorderObserver<IGeometry, IEdge<IGeometry>>();
predecessorObserver.Attach(dijkstra);
// Run the algorithm
Debug.WriteLine(String.Format("Starting algorithm from root vertex {0}", start));
dijkstra.Compute(start);
foreach (KeyValuePair<IGeometry, int> kvp in distObserver.Distances)
Debug.WriteLine(String.Format("Distance from root to node {0} is {1}",
kvp.Key, kvp.Value));
foreach (KeyValuePair<IGeometry, IEdge<IGeometry>> kvp in predecessorObserver.VertexPredecessors)
Debug.WriteLine(String.Format(
"If you want to get to {0} you have to enter through the IN edge {1}", kvp.Key, kvp.Value));
Check(graph, consts, predecessorObserver);
// Detach the observers
distObserver.Detach(dijkstra);
predecessorObserver.Detach(dijkstra);
}
示例4: BuildGraphFromMinimalGraphShapefile
public void BuildGraphFromMinimalGraphShapefile()
{
string path = "minimalgraph.shp";
int count = 15;
Assert.IsTrue(File.Exists(path));
ShapefileReader reader = new ShapefileReader(path);
IGeometryCollection edges = reader.ReadAll();
Assert.IsNotNull(edges);
Assert.IsInstanceOfType(typeof(GeometryCollection), edges);
Assert.AreEqual(count, edges.NumGeometries);
ILineString startls = null;
// Build graph
Dictionary<IEdge<IGeometry>, double> consts = new Dictionary<IEdge<IGeometry>, double>(edges.NumGeometries);
AdjacencyGraph<IGeometry, IEdge<IGeometry>> graph = new AdjacencyGraph<IGeometry, IEdge<IGeometry>>(true);
foreach (IMultiLineString mlstr in edges.Geometries)
{
Assert.AreEqual(1, mlstr.NumGeometries);
ILineString str = (ILineString) mlstr.GetGeometryN(0);
if (startls == null)
startls = str;
// Add vertex 1
IGeometry vertex1 = str.StartPoint;
Assert.IsNotNull(vertex1);
if (!graph.ContainsVertex(vertex1))
{
Debug.WriteLine(String.Format("Adding vertex {0} to the list", vertex1));
graph.AddVertex(vertex1);
}
else Debug.WriteLine(String.Format("Vertex {0} already present", vertex1));
// Add vertex 2
IGeometry vertex2 = str.EndPoint;
Assert.IsNotNull(vertex2);
if (!graph.ContainsVertex(vertex2))
{
Debug.WriteLine(String.Format("Adding vertex {0} to the list", vertex2));
graph.AddVertex(vertex2);
}
else Debug.WriteLine(String.Format("Vertex {0} already present", vertex2));
// Compute weight
double weight = weightComputer(str);
Assert.Greater(weight, 0.0);
// Add edge 1 => 2
IEdge<IGeometry> edge1 = new Edge<IGeometry>(vertex1, vertex2);
Assert.IsNotNull(edge1);
graph.AddEdge(edge1);
consts.Add(edge1, weight);
// Add edge 2 => 1
IEdge<IGeometry> edge2 = new Edge<IGeometry>(vertex2, vertex1);
Assert.IsNotNull(edge2);
graph.AddEdge(edge2);
consts.Add(edge2, weight);
}
// Perform DijkstraShortestPathAlgorithm
DijkstraShortestPathAlgorithm<IGeometry, IEdge<IGeometry>> dijkstra =
new DijkstraShortestPathAlgorithm<IGeometry, IEdge<IGeometry>>(graph, consts);
// attach a distance observer to give us the shortest path distances
VertexDistanceRecorderObserver<IGeometry, IEdge<IGeometry>> distObserver =
new VertexDistanceRecorderObserver<IGeometry, IEdge<IGeometry>>();
distObserver.Attach(dijkstra);
// Attach a Vertex Predecessor Recorder Observer to give us the paths
VertexPredecessorRecorderObserver<IGeometry, IEdge<IGeometry>> predecessorObserver =
new VertexPredecessorRecorderObserver<IGeometry, IEdge<IGeometry>>();
predecessorObserver.Attach(dijkstra);
// Run the algorithm
Assert.IsNotNull(startls);
IGeometry startPoint = startls.StartPoint;
Debug.WriteLine(String.Format("Starting algorithm from root vertex {0}", startPoint));
dijkstra.Compute(startPoint);
foreach (KeyValuePair<IGeometry, int> kvp in distObserver.Distances)
Debug.WriteLine(String.Format("Distance from root to node {0} is {1}",
kvp.Key, kvp.Value));
foreach (KeyValuePair<IGeometry, IEdge<IGeometry>> kvp in predecessorObserver.VertexPredecessors)
Debug.WriteLine(String.Format(
"If you want to get to {0} you have to enter through the IN edge {1}", kvp.Key, kvp.Value));
Check(graph, consts, predecessorObserver);
// Detach the observers
distObserver.Detach(dijkstra);
predecessorObserver.Detach(dijkstra);
}
示例5: ShortestPhrase
/// <summary>
/// Time complexity n + logn?
/// http://bigocheatsheet.com/
///
/// Used a directed graph acyclic
/// http://en.wikipedia.org/wiki/Directed_acyclic_graph
///
/// The use topological sorting to determine order
/// https://quickgraph.codeplex.com/wikipage?title=Topological%20Sort
/// http://en.wikipedia.org/wiki/Topological_sorting#Algorithms
/// </summary>
/// <param name="logins"></param>
/// <returns></returns>
public static int ShortestPhrase(string[] logins)
{
var graph = new AdjacencyGraph<int, SEdge<int>>();
foreach (var item in logins)
{
for (int i = 0; i < item.Length; i++)
{
var number = Convert.ToInt32(item.Substring(i, 1));
if (!graph.ContainsVertex(number))
{
graph.AddVertex(number);
}
if (i + 1 == item.Length)
break;
var next = Convert.ToInt32(item.Substring(i + 1, 1));
if (!graph.ContainsEdge(number, next))
{
graph.AddEdge(new SEdge<int>(number, next));
}
}
}
var shortestPath = graph.TopologicalSort(); // O(log(n))
var builder = new StringBuilder();
shortestPath.ForEach(item => builder.Append(item));
return Convert.ToInt32(builder.ToString());
}
示例6: GenerateGraphML
public static void GenerateGraphML(string fileName)
{
var graph = new AdjacencyGraph<XOVertex, XOEdge>();
var relationshipsSubset = _relationships.Values
//.Where(e => e.Source.ModuleId == "57$61" && e.Target.ModuleId == "57$61")
.Where(e => (e.Source.ClassSpec == "Audited" || e.Source.ClassSpec == "Metadata") && (e.Target.ClassSpec == "Audited" || e.Target.ClassSpec == "Metadata"))
.ToArray();
foreach (var r in relationshipsSubset)
{
if (!graph.ContainsVertex(r.Source))
graph.AddVertex(r.Source);
if (!graph.ContainsVertex(r.Target))
graph.AddVertex(r.Target);
}
graph.AddEdgeRange(relationshipsSubset);
int idx = 0;
foreach (var v in graph.Vertices)
{
foreach (var super in v.Superclasses.Select(s => _classes[s]).Where(s => graph.ContainsVertex(s)))
{
string id = string.Concat("inheritance_", idx++);
graph.AddEdge(new XOEdge(id, v, super)
{
Weight = BuildEdgeWeight(v, super),
EdgeType = BuildEdgeInheritanceType(v, super),
Color = BuildEdgeInheritanceColor(v, super)
});
}
}
VertexIdentity<XOVertex> vi = v => v.Id;
EdgeIdentity<XOVertex, XOEdge> ei = e => e.Id;
using (XmlWriter xw = XmlWriter.Create(fileName))
{
graph.SerializeToGraphML<XOVertex, XOEdge, AdjacencyGraph<XOVertex, XOEdge>>(xw, vi, ei);
}
}
示例7: create_part_cycle_graph
public AdjacencyGraph<string, Edge<string>> create_part_cycle_graph(){
var g = new AdjacencyGraph<string, Edge<string>> ();
foreach (rule r in rules) {
b_rule b = r as b_rule;
if (b != null) {
string a1 = b.reactants.a.ToString ();
string a2 = b.reactants.b.ToString ();
string b1 = b.products.a.ToString ();
string b2 = b.products.b.ToString ();
if (!g.ContainsVertex (a1)) {
g.AddVertex (a1);
// Console.WriteLine (a1);
}
if (!g.ContainsVertex (a2)) {
g.AddVertex (a2);
// Console.WriteLine (a2);
}
if (!g.ContainsVertex (b1)) {
g.AddVertex (b1);
// Console.WriteLine (b1);
}
if (!g.ContainsVertex (b2)) {
g.AddVertex (b2);
// Console.WriteLine (b2);
}
if (!g.ContainsEdge (a1, b1)) {
Edge<string> e = new Edge<string> (a1, b1);
g.AddEdge (e);
// Console.WriteLine(a1+"->"+b1);
}
if (!g.ContainsEdge (a2, b2)) {
Edge<string> f = new Edge<string> (a2, b2);
g.AddEdge (f);
// Console.WriteLine(a2+"->"+b2);
}
}
}
return g;
}
示例8: PrepareAlgorithm
/// <summary>
///
/// </summary>
/// <param name="computer">
/// A function that computes the weight
/// of any <see cref="ILineString">edge</see> of the graph
/// </param>
/// <returns></returns>
public DijkstraShortestPathAlgorithm<IPoint, IEdge<IPoint>> PrepareAlgorithm(ComputeWeightDelegate computer)
{
if (strings.Count < 2)
throw new TopologyException("you must specify two or more geometries to build a graph");
IMultiLineString edges = BuildEdges();
Dictionary<IEdge<IPoint>, double> consts = new Dictionary<IEdge<IPoint>, double>(edges.NumGeometries);
AdjacencyGraph<IPoint, IEdge<IPoint>> graph = new AdjacencyGraph<IPoint, IEdge<IPoint>>(true);
foreach (ILineString str in edges.Geometries)
{
IPoint vertex1 = str.StartPoint;
Assert.IsTrue(vertex1 != null);
if (!graph.ContainsVertex(vertex1))
graph.AddVertex(vertex1);
IPoint vertex2 = str.EndPoint;
Assert.IsTrue(vertex2 != null);
if (!graph.ContainsVertex(vertex2))
graph.AddVertex(vertex2);
double weight = computer(str);
Edge<IPoint> edge = new Edge<IPoint>(vertex1, vertex2);
Assert.IsTrue(edge != null);
graph.AddEdge(edge);
consts.Add(edge, weight);
}
// Use Dijkstra
return new DijkstraShortestPathAlgorithm<IPoint, IEdge<IPoint>>(graph, consts);
}
示例9: BuildTargetGraph
protected internal AdjacencyGraph<ProjectTargetInstance, Edge<ProjectTargetInstance>> BuildTargetGraph(Project project)
{
AdjacencyGraph<ProjectTargetInstance, Edge<ProjectTargetInstance>> graph =
new AdjacencyGraph<ProjectTargetInstance, Edge<ProjectTargetInstance>>();
foreach (string key in project.Targets.Keys) {
var target = project.Targets[key];
if (!graph.ContainsVertex(target)) {
graph.AddVertex(target);
}
// TODO: DependsOnTargets needs to be evalueated
string depTargetsString = target.DependsOnTargets != null ? target.DependsOnTargets : string.Empty;
List<string> dependentTargets = target.GetDependsOnTargetsAsList(project).ToList();
string depTargetsStringEvaluated = project.ExpandString(depTargetsString);
dependentTargets.ToList().ForEach(depTarget => {
var dt = project.Targets[depTarget];
if (dt != null) {
if (!graph.ContainsVertex(dt)) {
graph.AddVertex(dt);
}
Edge<ProjectTargetInstance> e = new Edge<ProjectTargetInstance>(target, dt);
graph.AddEdge(e);
}
});
}
return graph;
}