本文整理汇总了C#中Graph.GetEdges方法的典型用法代码示例。如果您正苦于以下问题:C# Graph.GetEdges方法的具体用法?C# Graph.GetEdges怎么用?C# Graph.GetEdges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph
的用法示例。
在下文中一共展示了Graph.GetEdges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSparseRemoval1
public void TestSparseRemoval1()
{
// use one edge definition everywhere.
var edge = new Edge();
edge.Forward = true;
edge.Tags = 1;
var graph = new Graph<Edge>();
uint vertex1 = graph.AddVertex(0, 0);
uint vertex2 = graph.AddVertex(1, 1);
uint vertex3 = graph.AddVertex(2, 2);
graph.AddEdge(vertex1, vertex2, edge, null);
graph.AddEdge(vertex2, vertex1, edge, null);
graph.AddEdge(vertex2, vertex3, edge, null);
graph.AddEdge(vertex3, vertex2, edge, null);
// execute pre-processor.
var preProcessor = new GraphSimplificationPreprocessor(graph);
preProcessor.Start();
// test resulting graph.
Assert.AreEqual(2, graph.VertexCount);
Assert.AreEqual(1, graph.GetEdges(1).ToKeyValuePairs().Length);
Assert.AreEqual(2, graph.GetEdges(1).ToKeyValuePairs()[0].Key);
Assert.AreEqual(1, graph.GetEdges(2).ToKeyValuePairs().Length);
Assert.AreEqual(1, graph.GetEdges(2).ToKeyValuePairs()[0].Key);
}
示例2: TestGraphAddEdge
public void TestGraphAddEdge()
{
var graph = new Graph<Edge>();
var vertex1 = graph.AddVertex(51, 1);
var vertex2 = graph.AddVertex(51, 2);
graph.AddEdge(vertex1, vertex2, new Edge()
{
Forward = true,
Tags = 0
}, null);
var edges = graph.GetEdges(vertex1).ToKeyValuePairs();
Assert.AreEqual(1, edges.Length);
Assert.AreEqual(0, edges[0].Value.Tags);
Assert.AreEqual(vertex2, edges[0].Key);
edges = graph.GetEdges(vertex2).ToKeyValuePairs();
Assert.AreEqual(1, edges.Length);
Assert.AreEqual(0, edges[0].Value.Tags);
Assert.AreEqual(vertex1, edges[0].Key);
Edge edge;
Assert.IsTrue(graph.GetEdge(vertex1, vertex2, out edge));
Assert.AreEqual(0, edge.Tags);
Assert.AreEqual(true, edge.Forward);
Assert.IsTrue(graph.GetEdge(vertex2, vertex1, out edge));
Assert.AreEqual(0, edge.Tags);
Assert.AreEqual(false, edge.Forward);
}
示例3: TestAddRemove1
public void TestAddRemove1()
{
using (var graph = new Graph<Edge>(new MemoryMappedStream(new MemoryStream()), 1000, Edge.MapFromDelegate, Edge.MapToDelegate, Edge.SizeUints))
{
uint tagsId = 10;
var vertex1 = graph.AddVertex(51, 1);
var vertex2 = graph.AddVertex(51, 2);
graph.AddEdge(vertex1, vertex2, new Edge()
{
Forward = true,
Tags = tagsId
}, null);
// test forward edge.
var edges = graph.GetEdges(vertex1).ToKeyValuePairs();
Assert.AreEqual(1, edges.Length);
Assert.AreEqual(tagsId, edges[0].Value.Tags);
Assert.AreEqual(vertex2, edges[0].Key);
Assert.AreEqual(true, edges[0].Value.Forward);
// remove edge again.
graph.RemoveEdge(vertex1, vertex2);
// check if the edge is gone.
edges = graph.GetEdges(vertex1).ToKeyValuePairs();
Assert.AreEqual(0, edges.Length);
}
}
示例4: TestArguments
public void TestArguments()
{
using (var graph = new Graph<Edge>(new MemoryMappedStream(new MemoryStream()), 1000,
Edge.MapFromDelegate, Edge.MapToDelegate, Edge.SizeUints))
{
uint vertex1 = graph.AddVertex(0, 0);
uint vertex2 = graph.AddVertex(0, 0);
uint vertex3 = 3;
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.AddEdge(vertex3, vertex1, new Edge(), null);
});
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.AddEdge(vertex1, vertex3, new Edge(), null);
});
Assert.Catch<ArgumentException>(() =>
{
graph.AddEdge(vertex1, vertex1, new Edge(), null);
});
Assert.Catch<ArgumentException>(() =>
{
graph.AddEdge(vertex1, vertex1, new Edge(), null);
});
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.ContainsEdges(vertex3, vertex1);
});
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.ContainsEdges(vertex1, vertex3);
});
Edge edge;
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.GetEdge(vertex3, vertex1, out edge);
});
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.GetEdge(vertex1, vertex3, out edge);
});
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.GetEdges(vertex3);
});
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.SetVertex(vertex3, 10, 10);
});
}
}
示例5: TestGraphArguments
public void TestGraphArguments()
{
// create graph with one vertex and start adding vertex2.
var graph = new Graph<Edge>();
uint vertex1 = graph.AddVertex(0, 0);
uint vertex2 = graph.AddVertex(0, 0);
uint vertex3 = 3;
Assert.Catch<ArgumentOutOfRangeException>(() => {
graph.AddEdge(vertex3, vertex1, new Edge(), null);
});
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.AddEdge(vertex1, vertex3, new Edge(), null);
});
Assert.Catch<ArgumentException>(() =>
{
graph.AddEdge(vertex1, vertex1, new Edge(), null);
});
Assert.Catch<ArgumentException>(() =>
{
graph.AddEdge(vertex1, vertex1, new Edge(), null);
});
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.ContainsEdges(vertex3, vertex1);
});
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.ContainsEdges(vertex1, vertex3);
});
Edge edge;
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.GetEdge(vertex3, vertex1, out edge);
});
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.GetEdge(vertex1, vertex3, out edge);
});
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.GetEdges(vertex3);
});
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.SetVertex(vertex3, 10, 10);
});
}
示例6: TestVertex
public void TestVertex()
{
using (var graph = new Graph<Edge>(new MemoryMappedStream(new MemoryStream()), 1000, Edge.MapFromDelegate, Edge.MapToDelegate, Edge.SizeUints))
{
var vertex = graph.AddVertex(51, 4);
float latitude, longitude;
graph.GetVertex(vertex, out latitude, out longitude);
Assert.AreEqual(51, latitude);
Assert.AreEqual(4, longitude);
graph.SetVertex(vertex, 52, 5);
graph.GetVertex(vertex, out latitude, out longitude);
Assert.AreEqual(52, latitude);
Assert.AreEqual(5, longitude);
var edges = graph.GetEdges(vertex).ToKeyValuePairs();
Assert.AreEqual(0, edges.Length);
Assert.IsFalse(graph.GetVertex(100, out latitude, out longitude));
}
}
示例7: TestCompressVertices
public void TestCompressVertices()
{
using (var graph = new Graph<Edge>(new MemoryMappedStream(new MemoryStream()), 1000,
Edge.MapFromDelegate, Edge.MapToDelegate, Edge.SizeUints))
{
var vertex1 = graph.AddVertex(51, 1);
var vertex2 = graph.AddVertex(51, 2);
var vertex3 = graph.AddVertex(51, 3);
var vertex4 = graph.AddVertex(51, 3);
graph.AddEdge(vertex1, vertex2, new Edge()
{
Forward = true,
Tags = 1
}, null);
graph.AddEdge(vertex2, vertex3, new Edge()
{
Forward = true,
Tags = 2
}, null);
graph.AddEdge(vertex3, vertex4, new Edge()
{
Forward = true,
Tags = 3
}, null);
graph.AddEdge(vertex4, vertex2, new Edge()
{
Forward = true,
Tags = 4
}, null);
// make vertex4 obsolete.
graph.RemoveEdges(vertex4);
graph.Compress();
Assert.AreEqual(3, graph.VertexCount);
Assert.AreEqual(graph.GetEdges(vertex1).ToKeyValuePairs().Length, 1);
Assert.AreEqual(graph.GetEdges(vertex2).ToKeyValuePairs().Length, 2);
Assert.AreEqual(graph.GetEdges(vertex3).ToKeyValuePairs().Length, 1);
}
}
示例8: TestCompressEdges
public void TestCompressEdges()
{
using (var graph = new Graph<Edge>(new MemoryMappedStream(new MemoryStream()), 1000,
Edge.MapFromDelegate, Edge.MapToDelegate, Edge.SizeUints))
{
var vertex1 = graph.AddVertex(51, 1);
var vertex2 = graph.AddVertex(51, 2);
var vertex3 = graph.AddVertex(51, 3);
var vertex4 = graph.AddVertex(51, 3);
graph.AddEdge(vertex1, vertex2, new Edge()
{
Forward = true,
Tags = 1
}, null);
graph.AddEdge(vertex2, vertex3, new Edge()
{
Forward = true,
Tags = 2
}, null);
graph.AddEdge(vertex3, vertex4, new Edge()
{
Forward = true,
Tags = 3
}, null);
graph.AddEdge(vertex4, vertex2, new Edge()
{
Forward = true,
Tags = 4
}, null);
graph.RemoveEdge(vertex2, vertex3);
graph.Compress();
Assert.IsFalse(graph.ContainsEdges(vertex2, vertex3));
Assert.IsFalse(graph.ContainsEdges(vertex3, vertex2));
Assert.AreEqual(graph.GetEdges(vertex1).ToKeyValuePairs().Length, 1);
Assert.AreEqual(graph.GetEdges(vertex2).ToKeyValuePairs().Length, 2);
Assert.AreEqual(graph.GetEdges(vertex3).ToKeyValuePairs().Length, 1);
Assert.AreEqual(graph.GetEdges(vertex4).ToKeyValuePairs().Length, 2);
}
using (var graph = new Graph<Edge>(new MemoryMappedStream(new MemoryStream()), 1000,
Edge.MapFromDelegate, Edge.MapToDelegate, Edge.SizeUints))
{
uint vertex1 = graph.AddVertex(51, 1);
uint vertex2 = graph.AddVertex(51, 2);
uint vertex3 = graph.AddVertex(51, 3);
uint vertex4 = graph.AddVertex(51, 3);
graph.AddEdge(vertex1, vertex2, new Edge()
{
Forward = true,
Tags = 1
}, null);
graph.AddEdge(vertex2, vertex3, new Edge()
{
Forward = true,
Tags = 2
}, null);
graph.AddEdge(vertex3, vertex4, new Edge()
{
Forward = true,
Tags = 3
}, null);
graph.AddEdge(vertex4, vertex2, new Edge()
{
Forward = true,
Tags = 4
}, null);
graph.RemoveEdge(vertex3, vertex4);
graph.Compress();
Assert.IsFalse(graph.ContainsEdges(vertex3, vertex4));
Assert.IsFalse(graph.ContainsEdges(vertex4, vertex3));
Assert.AreEqual(graph.GetEdges(vertex1).ToKeyValuePairs().Length, 1);
Assert.AreEqual(graph.GetEdges(vertex2).ToKeyValuePairs().Length, 3);
Assert.AreEqual(graph.GetEdges(vertex3).ToKeyValuePairs().Length, 1);
Assert.AreEqual(graph.GetEdges(vertex4).ToKeyValuePairs().Length, 1);
Edge edge;
Assert.IsTrue(graph.GetEdge(vertex1, vertex2, out edge));
Assert.AreEqual(1, edge.Tags);
Assert.IsTrue(graph.GetEdge(vertex2, vertex3, out edge));
Assert.AreEqual(2, edge.Tags);
Assert.IsTrue(graph.GetEdge(vertex4, vertex2, out edge));
Assert.AreEqual(4, edge.Tags);
}
}
示例9: SortHilbertTestDefaultStepsWithEdges
public void SortHilbertTestDefaultStepsWithEdges()
{
var n = GraphExtensions.DefaultHilbertSteps;
// build locations.
var locations = new List<Tuple<GeoCoordinate, uint>>();
locations.Add(new Tuple<GeoCoordinate, uint>(new GeoCoordinate(-90, -180), 1));
locations.Add(new Tuple<GeoCoordinate, uint>(new GeoCoordinate(-90, -60), 2));
locations.Add(new Tuple<GeoCoordinate, uint>(new GeoCoordinate(-90, 60), 3));
locations.Add(new Tuple<GeoCoordinate, uint>(new GeoCoordinate(-90, 180), 4));
locations.Add(new Tuple<GeoCoordinate, uint>(new GeoCoordinate(-30, -180), 5));
locations.Add(new Tuple<GeoCoordinate, uint>(new GeoCoordinate(-30, -60), 6));
locations.Add(new Tuple<GeoCoordinate, uint>(new GeoCoordinate(-30, 60), 7));
locations.Add(new Tuple<GeoCoordinate, uint>(new GeoCoordinate(-30, 180), 8));
locations.Add(new Tuple<GeoCoordinate, uint>(new GeoCoordinate(30, -180), 9));
locations.Add(new Tuple<GeoCoordinate, uint>(new GeoCoordinate(30, -60), 10));
locations.Add(new Tuple<GeoCoordinate, uint>(new GeoCoordinate(30, 60), 11));
locations.Add(new Tuple<GeoCoordinate, uint>(new GeoCoordinate(30, 180), 12));
locations.Add(new Tuple<GeoCoordinate, uint>(new GeoCoordinate(90, -180), 13));
locations.Add(new Tuple<GeoCoordinate, uint>(new GeoCoordinate(90, -60), 14));
locations.Add(new Tuple<GeoCoordinate, uint>(new GeoCoordinate(90, 60), 15));
locations.Add(new Tuple<GeoCoordinate, uint>(new GeoCoordinate(90, 180), 16));
// build graph.
var graph = new Graph<Edge>();
for (var idx = 0; idx < locations.Count; idx++)
{
graph.AddVertex((float)locations[idx].Item1.Latitude,
(float)locations[idx].Item1.Longitude);
}
// add edges.
graph.AddEdge(1, 2, new Edge() { Tags = 1 });
graph.AddEdge(2, 3, new Edge() { Tags = 2 });
graph.AddEdge(3, 4, new Edge() { Tags = 3 });
graph.AddEdge(4, 5, new Edge() { Tags = 4 });
graph.AddEdge(5, 6, new Edge() { Tags = 5 });
graph.AddEdge(6, 7, new Edge() { Tags = 6 });
graph.AddEdge(7, 8, new Edge() { Tags = 7 });
graph.AddEdge(8, 9, new Edge() { Tags = 8 });
graph.AddEdge(9, 10, new Edge() { Tags = 9 });
graph.AddEdge(10, 11, new Edge() { Tags = 10 });
graph.AddEdge(11, 12, new Edge() { Tags = 11 });
graph.AddEdge(12, 13, new Edge() { Tags = 12 });
graph.AddEdge(13, 14, new Edge() { Tags = 13 });
graph.AddEdge(14, 15, new Edge() { Tags = 14 });
// build a sorted version.
graph.SortHilbert(n);
// sort locations.
locations.Sort((x, y) =>
{
return HilbertCurve.HilbertDistance((float)x.Item1.Latitude, (float)x.Item1.Longitude, n).CompareTo(
HilbertCurve.HilbertDistance((float)y.Item1.Latitude, (float)y.Item1.Longitude, n));
});
// confirm sort.
float latitude, longitude;
var newToOld = new Dictionary<uint, uint>();
for (uint vertex = 1; vertex <= graph.VertexCount; vertex++)
{
graph.GetVertex(vertex, out latitude, out longitude);
Assert.AreEqual(latitude, locations[(int)(vertex - 1)].Item1.Latitude);
Assert.AreEqual(longitude, locations[(int)(vertex - 1)].Item1.Longitude);
newToOld.Add(vertex, locations[(int)(vertex - 1)].Item2);
}
for (uint vertex = 1; vertex <= graph.VertexCount; vertex++)
{
var edges = graph.GetEdges(vertex);
var originalVertex = newToOld[vertex];
foreach (var edge in edges)
{
var originalNeighbour = newToOld[edges.Neighbour];
Assert.IsTrue(originalVertex - 1 == originalNeighbour ||
originalVertex + 1 == originalNeighbour);
}
}
}
示例10: TestGraphAddingDuplicateEdge
public void TestGraphAddingDuplicateEdge()
{
var graph = new Graph<Edge>();
var vertex1 = graph.AddVertex(51, 1);
var vertex2 = graph.AddVertex(51, 2);
graph.AddEdge(vertex1, vertex2, new Edge()
{
Forward = true,
Tags = 1
}, null);
// should overwrite.
graph.AddEdge(vertex1, vertex2, new Edge()
{
Forward = true,
Tags = 2
}, null);
var edges = graph.GetEdges(vertex1, vertex2).ToKeyValuePairs();
Assert.AreEqual(1, edges.Length);
Assert.AreEqual(2, edges[0].Value.Tags);
// should overwrite again.
graph.AddEdge(vertex1, vertex2, new Edge()
{
Forward = true,
Tags = 1
}, null);
edges = graph.GetEdges(vertex1, vertex2).ToKeyValuePairs();
Assert.AreEqual(1, edges.Length);
Assert.AreEqual(1, edges[0].Value.Tags);
}
示例11: TestGraphCompressEdges
public void TestGraphCompressEdges()
{
var graph = new Graph<Edge>();
var vertex1 = graph.AddVertex(51, 1);
var vertex2 = graph.AddVertex(51, 2);
var vertex3 = graph.AddVertex(51, 3);
var vertex4 = graph.AddVertex(51, 3);
graph.AddEdge(vertex1, vertex2, new Edge()
{
Forward = true,
Tags = 1
}, null);
graph.AddEdge(vertex2, vertex3, new Edge()
{
Forward = true,
Tags = 2
}, null);
graph.AddEdge(vertex3, vertex4, new Edge()
{
Forward = true,
Tags = 3
}, null);
graph.AddEdge(vertex4, vertex2, new Edge()
{
Forward = true,
Tags = 4
}, null);
graph.RemoveEdge(vertex2, vertex3);
graph.Compress();
Assert.IsFalse(graph.ContainsEdges(vertex2, vertex3));
Assert.IsFalse(graph.ContainsEdges(vertex3, vertex2));
Assert.AreEqual(graph.GetEdges(vertex1).ToKeyValuePairs().Length, 1);
Assert.AreEqual(graph.GetEdges(vertex2).ToKeyValuePairs().Length, 2);
Assert.AreEqual(graph.GetEdges(vertex3).ToKeyValuePairs().Length, 1);
Assert.AreEqual(graph.GetEdges(vertex4).ToKeyValuePairs().Length, 2);
graph = new Graph<Edge>();
vertex1 = graph.AddVertex(51, 1);
vertex2 = graph.AddVertex(51, 2);
vertex3 = graph.AddVertex(51, 3);
vertex4 = graph.AddVertex(51, 3);
graph.AddEdge(vertex1, vertex2, new Edge()
{
Forward = true,
Tags = 1
}, null);
graph.AddEdge(vertex2, vertex3, new Edge()
{
Forward = true,
Tags = 2
}, null);
graph.AddEdge(vertex3, vertex4, new Edge()
{
Forward = true,
Tags = 3
}, null);
graph.AddEdge(vertex4, vertex2, new Edge()
{
Forward = true,
Tags = 4
}, null);
graph.RemoveEdge(vertex3, vertex4);
graph.Compress();
Assert.IsFalse(graph.ContainsEdges(vertex3, vertex4));
Assert.IsFalse(graph.ContainsEdges(vertex4, vertex3));
Assert.AreEqual(graph.GetEdges(vertex1).ToKeyValuePairs().Length, 1);
Assert.AreEqual(graph.GetEdges(vertex2).ToKeyValuePairs().Length, 3);
Assert.AreEqual(graph.GetEdges(vertex3).ToKeyValuePairs().Length, 1);
Assert.AreEqual(graph.GetEdges(vertex4).ToKeyValuePairs().Length, 1);
Edge edge;
Assert.IsTrue(graph.GetEdge(vertex1, vertex2, out edge));
Assert.AreEqual(1, edge.Tags);
Assert.IsTrue(graph.GetEdge(vertex2, vertex3, out edge));
Assert.AreEqual(2, edge.Tags);
Assert.IsTrue(graph.GetEdge(vertex4, vertex2, out edge));
Assert.AreEqual(4, edge.Tags);
}
示例12: TestGraphAddVertex10000
public void TestGraphAddVertex10000()
{
var graph = new Graph<Edge>();
int count = 10000;
while (count > 0)
{
var vertex = graph.AddVertex(51, 4);
float latitude, longitude;
graph.GetVertex(vertex, out latitude, out longitude);
Assert.AreEqual(51, latitude);
Assert.AreEqual(4, longitude);
var edges = graph.GetEdges(vertex).ToKeyValuePairs();
Assert.AreEqual(0, edges.Length);
count--;
}
Assert.AreEqual((uint)10000, graph.VertexCount);
}
示例13: TestGraphAddEdge1
public void TestGraphAddEdge1()
{
uint tagsId = 10;
var graph = new Graph<Edge>();
var vertex1 = graph.AddVertex(51, 1);
var vertex2 = graph.AddVertex(51, 2);
graph.AddEdge(vertex1, vertex2, new Edge()
{
Forward = true,
Tags = tagsId
}, null);
// test forward edge.
var edges = graph.GetEdges(vertex1).ToKeyValuePairs();
Assert.AreEqual(1, edges.Length);
Assert.AreEqual(tagsId, edges[0].Value.Tags);
Assert.AreEqual(vertex2, edges[0].Key);
Assert.AreEqual(true, edges[0].Value.Forward);
// test backward edge: backward edge is added automatically.
edges = graph.GetEdges(vertex2).ToKeyValuePairs();
Assert.AreEqual(1, edges.Length);
Assert.AreEqual(tagsId, edges[0].Value.Tags);
Assert.AreEqual(vertex1, edges[0].Key);
Assert.AreEqual(false, edges[0].Value.Forward);
// add a third vertex.
var vertex3 = graph.AddVertex(51, 2);
var edge = new Edge()
{
Forward = true,
Tags = tagsId
};
graph.AddEdge(vertex1, vertex3, edge, null);
// test forward edges.
edges = graph.GetEdges(vertex1).ToKeyValuePairs();
Assert.AreEqual(2, edges.Length);
Assert.AreEqual(tagsId, edges[0].Value.Tags);
Assert.AreEqual(vertex2, edges[0].Key);
Assert.AreEqual(true, edges[0].Value.Forward);
Assert.AreEqual(tagsId, edges[1].Value.Tags);
Assert.AreEqual(vertex3, edges[1].Key);
Assert.AreEqual(true, edges[1].Value.Forward);
// test backward edge: backward edge is added automatically.
edges = graph.GetEdges(vertex3).ToKeyValuePairs();
Assert.AreEqual(1, edges.Length);
Assert.AreEqual(tagsId, edges[0].Value.Tags);
Assert.AreEqual(vertex1, edges[0].Key);
Assert.AreEqual(false, edges[0].Value.Forward);
}
示例14: populateGraph
//Takes a graph, creates a new tab for it, and fills in the GUI components
//The vertices are created where each vertex is in verts
private void populateGraph(Graph g, List<GUIVertex> verts)
{
int n = g.GetVertices().Count;
makeNewGraphPanel(g);
updateCurrentTool(AppTool.AddVertexTool);
float angleAmount = 360f / n;
Vector2 center = new Vector2(256, 170);
for (int i = 0; i < g.GetVertices().Count; i++ )
{
Point addPoint = verts[i].Pos;
for (int j = 0; j < verts.Count; j++)
{
if (g.GetVertices()[i].Label.Equals(verts[j]))
{
addPoint = verts[j].Pos;
break;
}
}
CurrentGraphPanel.AddVertex(g.GetVertices()[i], addPoint);
}
foreach (Edge e in g.GetEdges())
{
int guiIndex1 = g.GetVertices().IndexOf(e.GetFromVertex());
int guiIndex2 = g.GetVertices().IndexOf(e.GetToVertex());
CurrentGraphPanel.AddEdge(CurrentGraphPanel.Vertices[guiIndex1], CurrentGraphPanel.Vertices[guiIndex2], e);
}
selectedItemPropertyGrid.SelectedObject = g;
}
示例15: TestGraphSwitchTwoVerticesOneEdge
public void TestGraphSwitchTwoVerticesOneEdge()
{
float latitude, longitude;
var graph = new Graph<Edge>();
var vertex1 = graph.AddVertex(1, 1);
var vertex2 = graph.AddVertex(2, 2);
graph.AddEdge(1, 2, new Edge()
{
Tags = 1,
Forward = true
});
graph.Switch(vertex1, vertex2);
graph.GetVertex(1, out latitude, out longitude);
Assert.AreEqual(2, latitude);
Assert.AreEqual(2, longitude);
graph.GetVertex(2, out latitude, out longitude);
Assert.AreEqual(1, latitude);
Assert.AreEqual(1, longitude);
var edges = graph.GetEdges(1);
Assert.AreEqual(1, edges.Count);
foreach (var edge in edges)
{
Assert.AreEqual(2, edge.Neighbour);
Assert.AreEqual(1, edge.EdgeData.Tags);
Assert.IsFalse(edge.EdgeData.Forward);
}
edges = graph.GetEdges(2);
Assert.AreEqual(1, edges.Count);
foreach (var edge in edges)
{
Assert.AreEqual(1, edge.Neighbour);
Assert.AreEqual(1, edge.EdgeData.Tags);
Assert.IsTrue(edge.EdgeData.Forward);
}
}