本文整理汇总了C#中Graph.GetVertex方法的典型用法代码示例。如果您正苦于以下问题:C# Graph.GetVertex方法的具体用法?C# Graph.GetVertex怎么用?C# Graph.GetVertex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph
的用法示例。
在下文中一共展示了Graph.GetVertex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ComputeGraph
public static void ComputeGraph(IEnumerable<KeyValuePair<string, Table>> tables1,
IEnumerable<ForeignKeyConstraint> realforeignKeys,
IEnumerable<ForeignKeyConstraint> probableForeignKeys)
{
var g = new Graph<string>(false);
foreach (var tbl in tables1)
{
g.AddVertex(tbl.Key.ToLower());
}
foreach (var key in realforeignKeys)
{
g.AddEdge(g.GetVertex(key.ConstraintKeys.First().From.TableName.ToLower()),
g.GetVertex(key.ConstraintKeys.First().To.TableName.ToLower()), 1);
}
foreach (var key in probableForeignKeys)
{
var first = key.ConstraintKeys.First();
var vertex = g.GetVertex(first.From.TableName.ToLower());
var vertex1 = g.GetVertex(first.To.TableName.ToLower());
if (g.GetEdge(vertex, vertex1) == null)
g.AddEdge(vertex, vertex1, 2);
}
//v.Compute();
//var v = GraphAlgorithms.KruskalsAlgorithm(g);
}
示例2: Graph
private static Graph<string> Graph(IEnumerable<ForeignKeyConstraint> constraints, IEnumerable<Table> tables)
{
var g = new Graph<string> (false);
foreach (var tbl in tables) {
g.AddVertex (tbl.TableName.ToLower ());
}
foreach (var key in constraints) {
var @from = g.GetVertex (key.FromTableName ().ToLower ());
var to = g.GetVertex (key.ToTableName ().ToLower ());
Edge<string> edge;
if ((edge = g.GetEdge (@from, to)) == null)
edge = g.AddEdge (@from, to, 1);
edge.Tag = string.Join (", ", key.Columns.Select (c => c.From.ColumnName).ToArray ());
}
return g;
}
示例3: TestGraphSwitchTwoVertices
public void TestGraphSwitchTwoVertices()
{
// two vertices
var graph = new Graph<Edge>();
var vertex1 = graph.AddVertex(1, 1);
var vertex2 = graph.AddVertex(2, 2);
graph.Switch(vertex1, vertex2);
float latitude, longitude;
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);
}
示例4: 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);
}
}
示例5: GetVertexExample
public void GetVertexExample()
{
// Initialize a new graph instance
var graph = new Graph<int>(true);
// Add three vertices to the graph
var vertex1 = graph.AddVertex(1);
var vertex2 = graph.AddVertex(2);
// Retrieving a vertex with value 1 will produce vertex vertex1
Assert.AreEqual(graph.GetVertex(1), vertex1);
// Retrieving a vertex with value 2 will produce vertex vertex2
Assert.AreEqual(graph.GetVertex(2), vertex2);
// Retrieving a vertex with a value not present in the graph
// will produce a null result.
Assert.IsNull(graph.GetVertex(3));
}
示例6: TestGraphAddVertex
public void TestGraphAddVertex()
{
var graph = new Graph<Edge>();
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: TestGraphSerialize1
public void TestGraphSerialize1()
{
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);
// serialize.
using (var stream = new MemoryStream())
{
graph.Serialize(stream, Edge.SizeUints, Edge.MapFromDelegate, Edge.MapToDelegate);
// deserialize.
stream.Seek(0, SeekOrigin.Begin);
var graphDeserialized = Graph<Edge>.Deserialize(stream, Edge.SizeUints, Edge.MapFromDelegate, Edge.MapToDelegate, false);
// compare.
Assert.AreEqual(graph.VertexCount, graphDeserialized.VertexCount);
for (uint vertex = 1; vertex <= graph.VertexCount; vertex++)
{
float latitude1, longitude1, latitude2, longitude2;
if (graph.GetVertex(vertex, out latitude1, out longitude1) &&
graphDeserialized.GetVertex(vertex, out latitude2, out longitude2))
{
Assert.AreEqual(latitude1, latitude2, 0.000001);
Assert.AreEqual(longitude1, longitude2, 0.000001);
}
}
var edges = graphDeserialized.GetEdges(vertex1, vertex2).ToKeyValuePairs();
Assert.AreEqual(1, edges.Length);
Assert.AreEqual(1, edges[0].Value.Tags);
}
}
示例8: 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);
}
示例9: TestSparseRemoval1Routing
public void TestSparseRemoval1Routing()
{
// use one edge definition everywhere.
var tagsIndex = new TagsIndex();
var tags = new TagsCollection(new Tag("highway","residential"));
var edge = new Edge();
edge.Forward = true;
edge.Tags = tagsIndex.Add(tags);
var graph = new Graph<Edge>();
uint vertex1 = graph.AddVertex(51.267797f, 4.8013623f);
uint vertex2 = graph.AddVertex(51.267702f, 4.8013396f);
uint vertex3 = graph.AddVertex(51.267592f, 4.8013024f);
graph.AddEdge(vertex1, vertex2, edge, null);
graph.AddEdge(vertex2, vertex3, edge, null);
graph.AddEdge(vertex3, vertex2, edge, null);
// save vertex coordinates for later use.
float latitude, longitude;
graph.GetVertex(vertex1, out latitude, out longitude);
var vertex1Coordinate = new GeoCoordinate(latitude, longitude);
graph.GetVertex(vertex2, out latitude, out longitude);
var vertex2Coordinate = new GeoCoordinate(latitude, longitude);
graph.GetVertex(vertex3, out latitude, out longitude);
var vertex3Coordinate = new GeoCoordinate(latitude, longitude);
// execute pre-processor.
var preProcessor = new GraphSimplificationPreprocessor(graph);
preProcessor.Start();
// create router.
var source = new RouterDataSource<Edge>(
graph, tagsIndex);
var router = Router.CreateFrom(source, new OsmRoutingInterpreter());
// test some basic routing requests.
// 1 -> 3: 1 -> 2 -> 3.
var resolved1 = router.Resolve(Vehicle.Car, vertex1Coordinate);
var resolved3 = router.Resolve(Vehicle.Car, vertex3Coordinate);
var route = router.Calculate(Vehicle.Car, resolved1, resolved3);
// verify the simple route result.
Assert.IsNotNull(route);
Assert.AreEqual(3, route.Segments.Length);
Assert.AreEqual(vertex1Coordinate.Latitude, route.Segments[0].Latitude);
Assert.AreEqual(vertex1Coordinate.Longitude, route.Segments[0].Longitude);
Assert.AreEqual(vertex2Coordinate.Latitude, route.Segments[1].Latitude);
Assert.AreEqual(vertex2Coordinate.Longitude, route.Segments[1].Longitude);
Assert.AreEqual(vertex3Coordinate.Latitude, route.Segments[2].Latitude);
Assert.AreEqual(vertex3Coordinate.Longitude, route.Segments[2].Longitude);
// 1 -> 2: 1 -> 2.
router = Router.CreateFrom(source, new OsmRoutingInterpreter());
resolved1 = router.Resolve(Vehicle.Car, vertex1Coordinate);
var resolved2 = router.Resolve(Vehicle.Car, vertex2Coordinate);
route = router.Calculate(Vehicle.Car, resolved1, resolved2);
// verify the simple route result.
Assert.IsNotNull(route);
Assert.AreEqual(2, route.Segments.Length);
Assert.AreEqual(vertex1Coordinate.Latitude, route.Segments[0].Latitude);
Assert.AreEqual(vertex1Coordinate.Longitude, route.Segments[0].Longitude);
Assert.AreEqual(vertex2Coordinate.Latitude, route.Segments[1].Latitude);
Assert.AreEqual(vertex2Coordinate.Longitude, route.Segments[1].Longitude);
}
示例10: 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));
}
}
示例11: TestVertex10000
public void TestVertex10000()
{
using (var graph = new Graph<Edge>(new MemoryMappedStream(new MemoryStream()), 1000, Edge.MapFromDelegate, Edge.MapToDelegate, Edge.SizeUints))
{
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);
}
}
示例12: Create1Vertices
//.........这里部分代码省略.........
Graph gt = new Graph(session);
session.Persist(gt);
}
Graph g7 = new Graph(session);
Placement place = new Placement(dbNum, 15);
session.Persist(place, g7);
// SCHEMA
VertexType userType = g.NewVertexType("User");
VertexType locationType = g.NewVertexType("Location");
VertexType aVertexType = g.NewVertexType("A");
VertexType bVertexType = g.NewVertexType("B");
VertexType cVertexType = g.NewVertexType("C");
EdgeType uEdge = g.NewEdgeType("unrestricted", true);
Vertex aVertex = g.NewVertex(aVertexType);
Vertex bVertex = g.NewVertex(bVertexType);
Vertex cVertex = g.NewVertex(cVertexType);
Edge abEdge = (Edge)aVertex.AddEdge("unrestricted", bVertex);
Edge bcEdge = (Edge)aVertex.AddEdge("unrestricted", cVertex);
Dictionary<Vertex, HashSet<Edge>> traverse = aVertex.Traverse(uEdge, Direction.Out);
abEdge.Remove();
Dictionary<Vertex, HashSet<Edge>> traverse2 = aVertex.Traverse(uEdge, Direction.Out);
EdgeType friendEdgeType = g.NewEdgeType("Friend", true, userType, userType);
EdgeType userLocationEdgeType = g.NewEdgeType("UserLocation", true, userType, locationType);
// DATA
Random rand = new Random(5);
for (int i = 0; i < numberOfUserVertices / 100; i++)
{
int vId = rand.Next(numberOfUserVertices);
try
{
if (g.VertexIdSetPerType)
userType.GetVertex(vId);
else
g.GetVertex(vId);
try
{
userType.NewVertex(vId);
Assert.Fail();
}
catch (VertexAllreadyExistException)
{
}
}
catch (VertexDoesNotExistException)
{
userType.NewVertex(vId);
userType.GetVertex(vId);
}
}
for (int i = 0; i < numberOfUserVertices / 10000; i++)
{
int vId = rand.Next(numberOfUserVertices);
try
{
Vertex v = userType.GetVertex(vId);
v.SetProperty("test", 1);
}
catch (VertexDoesNotExistException)
{
}
}
for (int i = 0; i < numberOfUserVertices / 10000; i++)
{
示例13: SortHilbertTest7
public void SortHilbertTest7()
{
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.
Func<uint, uint, uint> buildTagsId = (v1, v2) => { return v1 + (v2 * 16); };
graph.AddEdge(1, 2, new Edge() { Tags = buildTagsId(1, 2) });
graph.AddEdge(2, 3, new Edge() { Tags = buildTagsId(2, 3) });
graph.AddEdge(3, 4, new Edge() { Tags = buildTagsId(3, 4) });
graph.AddEdge(4, 5, new Edge() { Tags = buildTagsId(4, 5) });
graph.AddEdge(5, 6, new Edge() { Tags = buildTagsId(5, 6) });
graph.AddEdge(6, 7, new Edge() { Tags = buildTagsId(6, 7) });
graph.AddEdge(7, 8, new Edge() { Tags = buildTagsId(7, 8) });
graph.AddEdge(8, 9, new Edge() { Tags = buildTagsId(8, 9) });
graph.AddEdge(9, 10, new Edge() { Tags = buildTagsId(9, 10) });
graph.AddEdge(10, 11, new Edge() { Tags = buildTagsId(10, 11) });
graph.AddEdge(11, 12, new Edge() { Tags = buildTagsId(11, 12) });
graph.AddEdge(12, 13, new Edge() { Tags = buildTagsId(12, 13) });
graph.AddEdge(13, 14, new Edge() { Tags = buildTagsId(13, 14) });
graph.AddEdge(14, 15, new Edge() { Tags = buildTagsId(14, 15) });
// add 10 random edges.
for (var i = 0; i < 10; i++)
{
var from = Convert.ToUInt32(OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(15) + 1);
var to = Convert.ToUInt32(OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(14) + 1);
if(from <= to)
{
to = to + 1;
}
graph.AddEdge(from, to, new Edge() { Tags = buildTagsId(from, to) });
}
// sort vertices in-place.
graph.SortHilbert();
graph.Compress();
// 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 convert = 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);
convert.Add(vertex, locations[(int)(vertex - 1)].Item2);
}
for (uint vertex = 1; vertex <= graph.VertexCount; vertex++)
{
var edges = graph.GetEdges(vertex);
var originalVertex = convert[vertex];
foreach (var edge in edges)
{
var originalNeighbour = convert[edges.Neighbour];
if (edge.EdgeData.Forward)
{ // edge is forward.
Assert.AreEqual(buildTagsId(originalVertex, originalNeighbour), edge.EdgeData.Tags);
}
else
{ // edge is backward.
Assert.AreEqual(buildTagsId(originalNeighbour, originalVertex), edge.EdgeData.Tags);
}
}
}
//.........这里部分代码省略.........
示例14: 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);
}
}
}
示例15: SortHilbertTestStepsDefault
public void SortHilbertTestStepsDefault()
{
var n = GraphExtensions.DefaultHilbertSteps;
// build locations.
var locations = new List<GeoCoordinate>();
locations.Add(new GeoCoordinate(-90, -180));
locations.Add(new GeoCoordinate(-90, -60));
locations.Add(new GeoCoordinate(-90, 60));
locations.Add(new GeoCoordinate(-90, 180));
locations.Add(new GeoCoordinate(-30, -180));
locations.Add(new GeoCoordinate(-30, -60));
locations.Add(new GeoCoordinate(-30, 60));
locations.Add(new GeoCoordinate(-30, 180));
locations.Add(new GeoCoordinate(30, -180));
locations.Add(new GeoCoordinate(30, -60));
locations.Add(new GeoCoordinate(30, 60));
locations.Add(new GeoCoordinate(30, 180));
locations.Add(new GeoCoordinate(90, -180));
locations.Add(new GeoCoordinate(90, -60));
locations.Add(new GeoCoordinate(90, 60));
locations.Add(new GeoCoordinate(90, 180));
// build graph.
var graph = new Graph<Edge>();
for (var idx = 0; idx < locations.Count; idx++)
{
graph.AddVertex((float)locations[idx].Latitude,
(float)locations[idx].Longitude);
}
// build a sorted version.
graph.SortHilbert(n);
// sort locations.
locations.Sort((x, y) =>
{
return HilbertCurve.HilbertDistance((float)x.Latitude, (float)x.Longitude, n).CompareTo(
HilbertCurve.HilbertDistance((float)y.Latitude, (float)y.Longitude, n));
});
// confirm sort.
for (uint vertex = 1; vertex <= graph.VertexCount; vertex++)
{
float latitude, longitude;
graph.GetVertex(vertex, out latitude, out longitude);
Assert.AreEqual(latitude, locations[(int)(vertex - 1)].Latitude);
Assert.AreEqual(longitude, locations[(int)(vertex - 1)].Longitude);
}
}