public void ring1of1() { int err; List <H3Index> allKrings = new List <H3Index> { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; var newk1 = k1.ToList(); err = Algos.hexRanges(ref newk1, 6, 1, allKrings); Assert.True(err == 0, "No error on hexRanges"); for (int i = 0; i < 42; i++) { Assert.True(allKrings[i] != 0, "index is populated"); if (i % 7 == 0) { int index = i / 7; Assert.True(newk1[index] == allKrings[i], "The beginning of the segment is the correct hexagon"); } } }
public void polyfillExact() { GeoCoord somewhere = new GeoCoord(1, 2); H3Index origin = H3Index.geoToH3(ref somewhere, 9); GeoBoundary boundary = new GeoBoundary(); H3Index.h3ToGeoBoundary(origin, ref boundary); List <GeoCoord> verts = new GeoCoord [boundary.numVerts + 1].ToList(); for (int i = 0; i < boundary.numVerts; i++) { verts[i] = boundary.verts[i]; } verts[boundary.numVerts] = boundary.verts[0]; Geofence someGeofence = new Geofence(); someGeofence.numVerts = boundary.numVerts + 1; someGeofence.verts = verts.ToArray(); GeoPolygon someHexagon = new GeoPolygon(); someHexagon.Geofence = someGeofence; someHexagon.numHoles = 0; int numHexagons = Algos.maxPolyfillSize(ref someHexagon, 9); var hexagons = new ulong[numHexagons].Select(cell => new H3Index(cell)).ToList(); Algos.polyfill(someHexagon, 9, hexagons); int actualNumHexagons = countActualHexagons(hexagons, numHexagons); Assert.True(actualNumHexagons == 1, "got expected polyfill size (1)"); }
internal void RunSearch(Guid guid, Map graph) { _logger.LogInformation("Begin search with algorithm {name} (graph V={nodes}, E={edges})", DisplayNames[guid], graph.Vertices.Count(), graph.Edges.Count()); if (Algos.TryGetValue(guid, out var algo)) { var sw = Stopwatch.StartNew(); var robots = new List <Robot>(); for (var i = 0; i < graph.Starts.Count; i++) { robots.Add(algo.RobotFactory(graph.Starts[i], graph.Targets[i])); } _logger.LogInformation("Robots={robots}", robots.Count); algo.InitializeInternal(graph.Clone(), robots); var initTime = sw.ElapsedMilliseconds; _logger.LogInformation("{action} took {ms} ms", "init", initTime); sw.Restart(); algo.RunSearch(); sw.Stop(); _logger.LogInformation("{action} took {ms} ms", "search", sw.ElapsedMilliseconds); var result = new AlgoResult(graph, algo, initTime, sw.ElapsedMilliseconds); _eventAggregator.Publish(new SearchDoneEvent(result)); } else { throw new KeyNotFoundException($"Could not find algorithm with guid '{guid}'"); } }
public void kRing0() { GeoCoord sf = new GeoCoord(0.659966917655, 2 * 3.14159 - 2.1364398519396); H3Index sfHex0 = H3Index.geoToH3(ref sf, 0); var k1 = new List <H3Index> { 0, 0, 0, 0, 0, 0, 0 }; var k1Dist = new List <int> { 0, 0, 0, 0, 0, 0, 0 }; H3Index[] expectedK1 = { 0x8029fffffffffff, 0x801dfffffffffff, 0x8013fffffffffff, 0x8027fffffffffff, 0x8049fffffffffff, 0x8051fffffffffff, 0x8037fffffffffff }; Algos.kRingDistances(sfHex0, 1, ref k1, ref k1Dist); for (int i = 0; i < 7; i++) { Assert.True(k1[i] != 0, "index is populated"); int inList = 0; for (int j = 0; j < 7; j++) { if (k1[i] != expectedK1[j]) { continue; } Assert.True(k1Dist[i] == (k1[i] == sfHex0 ? 0 : 1), "distance is as expected"); inList++; } Assert.True(inList == 1, "index found in expected set"); } }
private static void h3Distance_kRing_assertions(H3Index h3) { int r = H3Index.H3_GET_RESOLUTION(h3); Assert.True(r <= 5, "resolution supported by test function (kRing)"); int maxK = MAX_DISTANCES[r]; int sz = Algos.maxKringSize(maxK); var neighbors = new H3Index[sz].ToList(); var distances = new int[sz].ToList(); Algos.kRingDistances(h3, maxK, ref neighbors, ref distances); for (int i = 0; i < sz; i++) { if (neighbors[i] == 0) { continue; } int calculatedDistance = LocalIJ.h3Distance(h3, neighbors[i]); // Don't consider indexes where h3Distance reports failure to // generate Assert.True(calculatedDistance == distances[i] || calculatedDistance == -1, "kRingDistances matches h3Distance"); } }
public static HexRangeDistancesResult HexRangeDistances(Code.H3Index origin, int k) { int maxSize = Algos.maxKringSize(k); var outHexes = MakeEmpty(maxSize); var distances = new int[maxSize].ToList(); var result = Algos.hexRangeDistances(origin, k, ref outHexes, ref distances); List <HexRangeMeasurement> combiner = new List <HexRangeMeasurement>(); for (int i = 0; i < maxSize; i++) { combiner.Add ( new HexRangeMeasurement { Index = new H3Index { Value = outHexes[i].value }, Distance = distances[i] } ); } return(new HexRangeDistancesResult { Result = result, Values = combiner.ToArray() }); }
public void getH3UnidirectionalEdgeAndFriends() { H3Index sf = H3Index.geoToH3(ref sfGeo, 9); List <H3Index> ring = new ulong[Algos.maxKringSize(1)].Select(cell => new H3Index(cell)).ToList(); Algos.hexRing(sf, 1, ref ring); H3Index sf2 = ring[0]; H3Index edge = H3UniEdge.getH3UnidirectionalEdge(sf, sf2); Assert.True(sf == H3UniEdge.getOriginH3IndexFromUnidirectionalEdge(edge), "can retrieve the origin from the edge"); Assert.True( sf2 == H3UniEdge.getDestinationH3IndexFromUnidirectionalEdge(edge), "can retrieve the destination from the edge"); var originDestination = new ulong[2].Select(cell => new H3Index(cell)).ToList(); H3UniEdge.getH3IndexesFromUnidirectionalEdge(edge, ref originDestination); Assert.True(originDestination[0] == sf, "got the origin first in the pair request"); Assert.True(originDestination[1] == sf2, "got the destination last in the pair request"); List <H3Index> largerRing = new ulong[Algos.maxKringSize(2)].Select(cell => new H3Index(cell)).ToList(); Algos.hexRing(sf, 2, ref largerRing); H3Index sf3 = largerRing[0]; H3Index notEdge = H3UniEdge.getH3UnidirectionalEdge(sf, sf3); Assert.True(notEdge == 0, "Non-neighbors can't have edges"); }
public void h3UnidirectionalEdgeIsValid() { H3Index sf = H3Index.geoToH3(ref sfGeo, 9); var ring = new ulong[Algos.maxKringSize(1)].Select(cell => new H3Index(cell)).ToList(); Algos.hexRing(sf, 1, ref ring); H3Index sf2 = ring[0]; H3Index edge = H3UniEdge.getH3UnidirectionalEdge(sf, sf2); Assert.True(H3UniEdge.h3UnidirectionalEdgeIsValid(edge) == 1, "edges validate correctly"); Assert.True(H3UniEdge.h3UnidirectionalEdgeIsValid(sf) == 0, "hexagons do not validate"); H3Index fakeEdge = sf; H3Index.H3_SET_MODE(ref fakeEdge, Constants.H3_UNIEDGE_MODE); Assert.True(H3UniEdge.h3UnidirectionalEdgeIsValid(fakeEdge) == 0, "edges without an edge specified don't work"); H3Index pentagon = 0x821c07fffffffff; H3Index goodPentagonalEdge = pentagon; H3Index.H3_SET_MODE(ref goodPentagonalEdge, Constants.H3_UNIEDGE_MODE); H3Index.H3_SET_RESERVED_BITS(ref goodPentagonalEdge, 2); Assert.True(H3UniEdge.h3UnidirectionalEdgeIsValid(goodPentagonalEdge) == 1, "pentagonal edge validates"); H3Index badPentagonalEdge = goodPentagonalEdge; H3Index.H3_SET_RESERVED_BITS(ref badPentagonalEdge, 1); Assert.True(H3UniEdge.h3UnidirectionalEdgeIsValid(badPentagonalEdge) == 0, "missing pentagonal edge does not validate"); }
public void ring1() { int err; List <H3Index> k1 = new List <H3Index> { 0, 0, 0, 0, 0, 0 }; List <H3Index> expectedK1 = new List <H3Index> { 0x89283080ddbffff, 0x89283080c37ffff, 0x89283080c27ffff, 0x89283080d53ffff, 0x89283080dcfffff, 0x89283080dc3ffff }; err = Algos.hexRing(sfHex, 1, ref k1); Assert.True(err == 0, "No error on hexRing"); for (int i = 0; i < 6; i++) { Assert.True(k1[i] != 0, "index is populated"); int inList = 0; for (int j = 0; j < 6; j++) { if (k1[i] == expectedK1[j]) { inList++; } } Assert.True(inList == 1, "index found in expected set"); } }
public static LinkedGeoPolygon H3SetToLinkedGeo(IEnumerable <Code.H3Index> h3Set) { var hexes = h3Set.ToList(); var polygon = new LinkedGeo.LinkedGeoPolygon(); Algos.h3SetToLinkedGeo(ref hexes, hexes.Count, ref polygon); return(new LinkedGeoPolygon(polygon)); }
[InlineData(new int[] { 36, 1, 25, 42, 20, 9, 7 })] // Arrange public void TestArraySearch1(int[] testArray) { // Act int expected = 4; int actual = Algos.SearchArray(25, testArray); // Assert Assert.True(expected == actual); }
public void kRing1_PolarPentagon_k3() { H3Index polar = 0; H3Index.setH3Index(ref polar, 1, 4, 0); var k2 = new H3Index[37].Select(c => (H3Index)0).ToList(); var k2Dist = new int[37].ToList(); var expectedK2 = new List <H3Index> { 0x81013ffffffffff, 0x811fbffffffffff, 0x81193ffffffffff, 0x81097ffffffffff, 0x81003ffffffffff, 0x81183ffffffffff, 0x8111bffffffffff, 0x81077ffffffffff, 0x811f7ffffffffff, 0x81067ffffffffff, 0x81093ffffffffff, 0x811e7ffffffffff, 0x81083ffffffffff, 0x81117ffffffffff, 0x8101bffffffffff, 0x81107ffffffffff, 0x81073ffffffffff, 0x811f3ffffffffff, 0x81063ffffffffff, 0x8108fffffffffff, 0x811e3ffffffffff, 0x8119bffffffffff, 0x81113ffffffffff, 0x81017ffffffffff, 0x81103ffffffffff, 0x8109bffffffffff, 0x81197ffffffffff, 0x81007ffffffffff, 0x8108bffffffffff, 0x81187ffffffffff, 0x8107bffffffffff, 0, 0, 0, 0, 0, 0 }; int[] expectedK2Dist = { 2, 3, 2, 1, 3, 3, 3, 2, 2, 3, 1, 3, 0, 2, 3, 3, 2, 2, 3, 1, 3, 3, 2, 2, 3, 1, 2, 3, 1, 3, 3, 0, 0, 0, 0, 0, 0 }; Algos.kRingDistances(polar, 3, ref k2, ref k2Dist); int k2present = 0; for (int i = 0; i < 37; i++) { if (k2[i] != 0) { k2present++; int inList = 0; for (int j = 0; j < 37; j++) { if (k2[i] == expectedK2[j]) { Assert.True ( k2Dist[i] == expectedK2Dist[j], "distance is as expected" ); inList++; } } Assert.True(inList == 1, "index found in expected set"); } } Assert.True(k2present == 31, "pentagon has 30 neighbors"); }
public void identityKRing() { List <H3Index> k0 = new List <H3Index> { 0 }; var err = Algos.hexRing(sfHex, 0, ref k0); Assert.True(err == 0, "No error on hexRing"); Assert.True(k0[0] == sfHex, "generated identity k-ring"); }
public void h3NeighborRotations_identity() { // This is undefined behavior, but it's helpful for it to make sense. H3Index origin = 0x811d7ffffffffffL; int rotations = 0; Assert.True( Algos.h3NeighborRotations(origin, Direction.CENTER_DIGIT, ref rotations) == origin, "Moving to self goes to self"); }
public void empty() { LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon(); List <H3Index> nullset = new List <H3Index>(); Algos.h3SetToLinkedGeo(ref nullset, 0, ref polygon); Assert.True(LinkedGeo.countLinkedLoops(ref polygon) == 0, "No loops added to polygon"); LinkedGeo.destroyLinkedPolygon(ref polygon); }
public void nestedDonut() { LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon(); // hollow 1-ring + hollow 3-ring around the same hex List <H3Index> set = new List <H3Index> { 0x89283082813ffff, 0x8928308281bffff, 0x8928308280bffff, 0x8928308280fffff, 0x89283082807ffff, 0x89283082817ffff, 0x8928308289bffff, 0x892830828d7ffff, 0x892830828c3ffff, 0x892830828cbffff, 0x89283082853ffff, 0x89283082843ffff, 0x8928308284fffff, 0x8928308287bffff, 0x89283082863ffff, 0x89283082867ffff, 0x8928308282bffff, 0x89283082823ffff, 0x89283082837ffff, 0x892830828afffff, 0x892830828a3ffff, 0x892830828b3ffff, 0x89283082887ffff, 0x89283082883ffff }; int numHexes = set.Count; Algos.h3SetToLinkedGeo(ref set, numHexes, ref polygon); // Note that the polygon order here is arbitrary, making this test // somewhat brittle, but it's difficult to assert correctness otherwise Assert.True(LinkedGeo.countLinkedPolygons(ref polygon) == 2, "Polygon count correct"); Assert.True(LinkedGeo.countLinkedLoops(ref polygon) == 2, "Loop count on first polygon correct"); // Brittleness comes from hashing into buckets, so let's cover both bases. if (LinkedGeo.countLinkedCoords(ref polygon.first) == 42) { Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first) == 42, "Got expected big outer loop"); Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first.next) == 30, "Got expected big inner loop"); Assert.True(LinkedGeo.countLinkedLoops(ref polygon.next) == 2, "Loop count on second polygon correct"); Assert.True(LinkedGeo.countLinkedCoords(ref polygon.next.first) == 18, "Got expected outer loop"); Assert.True(LinkedGeo.countLinkedCoords(ref polygon.next.first.next) == 6, "Got expected inner loop"); } else { Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first) == 18, "Got expected big outer loop"); Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first.next) == 6, "Got expected big inner loop"); Assert.True(LinkedGeo.countLinkedLoops(ref polygon.next) == 2, "Loop count on second polygon correct"); Assert.True(LinkedGeo.countLinkedCoords(ref polygon.next.first) == 42, "Got expected outer loop"); Assert.True(LinkedGeo.countLinkedCoords(ref polygon.next.first.next) == 30, "Got expected inner loop"); } LinkedGeo.destroyLinkedPolygon(ref polygon); }
public static H3Index[] Kring(Code.H3Index origin, int k) { int maxSize = Algos.maxKringSize(k); var outHexes = MakeEmpty(maxSize); Algos.kRing(origin, k, ref outHexes); return(outHexes.Select(v => new H3Index { Value = v.value }).ToArray()); }
public void TestArraySort() { // Arrange int[] testArray = new int[] { 36, 1, 25, 42, 20, 9, 7 }; // Act int[] expected = new int[] { 1, 7, 9, 20, 25, 36, 42 }; int[] actual = Algos.SortArray(testArray); // Assert Assert.Equal(expected, actual); }
public void kRing1_Pentagon_k4() { H3Index pent = 0; H3Index.setH3Index(ref pent, 1, 14, 0); var k2 = new H3Index[61].Select(c => (H3Index)0).ToList(); var k2Dist = new int[61].ToList(); var expectedK2 = new List <H3Index> { 0x811d7ffffffffff, 0x810c7ffffffffff, 0x81227ffffffffff, 0x81293ffffffffff, 0x81133ffffffffff, 0x8136bffffffffff, 0x81167ffffffffff, 0x811d3ffffffffff, 0x810c3ffffffffff, 0x81223ffffffffff, 0x81477ffffffffff, 0x8128fffffffffff, 0x81367ffffffffff, 0x8112fffffffffff, 0x811cfffffffffff, 0x8123bffffffffff, 0x810dbffffffffff, 0x8112bffffffffff, 0x81473ffffffffff, 0x8128bffffffffff, 0x81363ffffffffff, 0x811cbffffffffff, 0x81237ffffffffff, 0x810d7ffffffffff, 0x81127ffffffffff, 0x8137bffffffffff, 0x81287ffffffffff, 0x8126bffffffffff, 0x81177ffffffffff, 0x810d3ffffffffff, 0x81233ffffffffff, 0x8150fffffffffff, 0x81123ffffffffff, 0x81377ffffffffff, 0x81283ffffffffff, 0x8102fffffffffff, 0x811c3ffffffffff, 0x810cfffffffffff, 0x8122fffffffffff, 0x8113bffffffffff, 0x81373ffffffffff, 0x8129bffffffffff, 0x8102bffffffffff, 0x811dbffffffffff, 0x810cbffffffffff, 0x8122bffffffffff, 0x81297ffffffffff, 0x81507ffffffffff, 0x8136fffffffffff, 0x8127bffffffffff, 0x81137ffffffffff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; Algos.kRingDistances(pent, 4, ref k2, ref k2Dist); int k2present = 0; for (int i = 0; i < 61; i++) { if (k2[i] != 0) { k2present++; int inList = 0; for (int j = 0; j < 61; j++) { if (k2[i] == expectedK2[j]) { inList++; } } Assert.True(inList == 1, "index found in expected set"); } } Assert.True(k2present == 51, "pentagon has 50 neighbors"); }
public void TestArraySearch() { // Arrange int[] testArray = new int[] { 36, 1, 25, 42, 20, 9, 7 }; // Act int expected = 4; int actual = Algos.SearchArray(25, testArray); // Assert Assert.Equal(expected, actual); }
public void empty() { VertexGraph graph = new VertexGraph(0, 0); int numHexes = 0; var set = makeSet(null, numHexes); Algos.h3SetToVertexGraph(ref set, numHexes, ref graph); Assert.True(graph.size == 0, "No edges added to graph"); VertexGraph.destroyVertexGraph(ref graph); }
public void TestFibonacci() { // Arrange int n = 3; // Act int expected = 2; int actual = Algos.Fibonacci(n); // Assert Assert.Equal(expected, actual); }
public void nearPentagonRing2() { int err; H3Index nearPentagon = 0x837405fffffffff; List <H3Index> kp2 = new List <H3Index> { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; err = Algos.hexRing(nearPentagon, 2, ref kp2); Assert.True(err != 0, "Should return an error when hitting a pentagon"); }
public static HexRangeResult HexRange(Code.H3Index origin, int k) { var temp = MakeEmpty(Algos.maxKringSize(k)); var result = Algos.hexRange(origin, k, ref temp); return(new HexRangeResult { Result = result, Indexes = temp.Select(t => new Api.H3Index { Value = t.value }).ToArray() }); }
public void identityKRing() { int err; List <H3Index> k0 = new List <H3Index> { 0 }; err = Algos.hexRanges(ref sfHexPtr, 1, 0, k0); Assert.True(err == 0, "No error on hexRanges"); Assert.True(k0[0] == sfHex, "generated identity k-ring"); }
// Use this for initialization void Start() { Singleton.GetInstance().mgr = this;; alg = new Algos(); plr = new PlayerController(); enmy = new EnemyController(); plrI = plr; enmI = enmy; GenrateCivilians(10, 80, 80); // genrates non-repetable cordinates for civilians GenratePath(); // genrates random path IsInitialized = true; }
public void contiguous2distorted() { VertexGraph graph = new VertexGraph(0, 0); var hexes = new List <string> { "894cc5365afffff", "894cc536537ffff" }; int numHexes = hexes.Count; var set = makeSet(hexes, numHexes); Algos.h3SetToVertexGraph(ref set, numHexes, ref graph); Assert.True(graph.size == 12, "All edges except 2 shared added to graph"); VertexGraph.destroyVertexGraph(ref graph); }
public void contiguous3() { VertexGraph graph = new VertexGraph(0, 0); var hexes = new List <string> { "8928308288bffff", "892830828d7ffff", "8928308289bffff" }; int numHexes = hexes.Count; var set = makeSet(hexes, numHexes); Algos.h3SetToVertexGraph(ref set, numHexes, ref graph); Assert.True(graph.size == 3 * 4, "All edges except 6 shared added to graph"); VertexGraph.destroyVertexGraph(ref graph); }
public void nonContiguous2() { VertexGraph graph = new VertexGraph(0, 0); List <string> hexes = new List <string> { "8928308291bffff", "89283082943ffff" }; int numHexes = hexes.Count; var set = makeSet(hexes, numHexes); Algos.h3SetToVertexGraph(ref set, numHexes, ref graph); Assert.True(graph.size == 12, "All edges of two non-contiguous hexes added to graph"); VertexGraph.destroyVertexGraph(ref graph); }
public void onPentagon() { int err; H3Index nearPentagon = 0; H3Index.setH3Index(ref nearPentagon, 0, 4, 0); List <H3Index> kp2 = new List <H3Index> { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; err = Algos.hexRing(nearPentagon, 2, ref kp2); Assert.True(err != 0, "Should return an error when starting at a pentagon"); }