Esempio n. 1
0
 /// <summary>
 /// Creates a huge coordinate index based on exisiting data.
 /// </summary>
 /// <param name="size">The size.</param>
 /// <param name="index">The index array.</param>
 /// <param name="coordinates">The coordinates array.</param>
 public HugeCoordinateCollectionIndex(long size,
                                      HugeArrayBase <ulong> index, HugeArrayBase <float> coordinates)
 {
     _nextIdx     = size;
     _index       = index;
     _coordinates = coordinates;
 }
Esempio n. 2
0
 /// <summary>
 /// Creates a new mapped huge array.
 /// </summary>
 /// <param name="baseArray">The base array.</param>
 /// <param name="elementSize">The size of one mapped structure when translate to the simpler structure.</param>
 /// <param name="mapTo">The map to implementation.</param>
 /// <param name="mapFrom">The map from implementation.</param>
 public MappedHugeArray(HugeArrayBase <T> baseArray, int elementSize, MapTo mapTo, MapFrom mapFrom)
 {
     _baseArray   = baseArray;
     _elementSize = elementSize;
     _mapTo       = mapTo;
     _mapFrom     = mapFrom;
 }
Esempio n. 3
0
        /// <summary>
        /// Initializes the reverse index.
        /// </summary>
        private void BuildReverse()
        {
            if (_file == null)
            { // just use in-memory data structures.
                _reverseDirectNeighbours     = new HugeArray <uint>(_graph.VertexCount + 1);
                _additionalReverseNeighbours = new Dictionary <uint, uint[]>();
            }
            else
            { // use memory-mapped data structures.
                _reverseDirectNeighbours     = new MemoryMappedHugeArrayUInt32(_file, _graph.VertexCount + 1);
                _additionalReverseNeighbours = new MemoryMappedHugeDictionary <uint, uint[]>(_file,
                                                                                             MemoryMappedDelegates.ReadFromUInt32, MemoryMappedDelegates.WriteToUInt32,
                                                                                             MemoryMappedDelegates.ReadFromUIntArray, MemoryMappedDelegates.WriteToUIntArray);
            }

            for (uint currentVertex = 1; currentVertex <= _graph.VertexCount; currentVertex++)
            {
                var edges = _graph.GetEdges(currentVertex);
                while (edges.MoveNext())
                {
                    uint neighbour = edges.Neighbour;
                    this.AddReverse(neighbour, currentVertex);
                }
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Creates a new huge coordinate collection.
 /// </summary>
 /// <param name="coordinates"></param>
 /// <param name="startIdx"></param>
 /// <param name="size"></param>
 /// <param name="reverse"></param>
 public HugeCoordinateCollection(HugeArrayBase <float> coordinates, long startIdx, long size, bool reverse)
 {
     _startIdx    = startIdx;
     _size        = size;
     _coordinates = coordinates;
     _reverse     = reverse;
 }
Esempio n. 5
0
        /// <summary>
        /// Sorts the graph based on the given transformations.
        /// </summary>
        public override void Sort(HugeArrayBase <uint> transformations)
        {
            // update edges.
            for (var i = 0; i < _nextEdgeId; i++)
            {
                _edges[i] = transformations[_edges[i]];
            }

            // sort vertices and coordinates.
            QuickSort.Sort((i) => transformations[i], (i, j) =>
            {
                var temp        = _coordinates[i];
                _coordinates[i] = _coordinates[j];
                _coordinates[j] = temp;

                var tempRef          = _vertices[i * 2];
                _vertices[i * 2]     = _vertices[j * 2];
                _vertices[j * 2]     = tempRef;
                tempRef              = _vertices[i * 2 + 1];
                _vertices[i * 2 + 1] = _vertices[j * 2 + 1];
                _vertices[j * 2 + 1] = tempRef;

                var trans          = transformations[i];
                transformations[i] = transformations[j];
                transformations[j] = trans;
            }, 1, _nextVertexId - 1);
        }
Esempio n. 6
0
 /// <summary>
 /// Disposes of all resources associated with this coordinate collection index.
 /// </summary>
 public void Dispose()
 {
     _index.Dispose();
     _index = null;
     _coordinates.Dispose();
     _coordinates = null;
 }
 /// <summary>
 /// Creates a huge coordinate index based on exisiting data.
 /// </summary>
 /// <param name="size">The size.</param>
 /// <param name="index">The index array.</param>
 /// <param name="coordinates">The coordinates array.</param>
 public HugeCoordinateCollectionIndex(long size, 
     HugeArrayBase<ulong> index, HugeArrayBase<float> coordinates)
 {
     _nextIdx = size;
     _index = index;
     _coordinates = coordinates;
 }
Esempio n. 8
0
        /// <summary>
        /// Sorts the vertices in the given graph based on a hilbert curve.
        /// </summary>
        /// <typeparam name="TEdgeData"></typeparam>
        public static void BuildHilbertRank <TEdgeData>(this GraphBase <TEdgeData> graph, int n,
                                                        HugeArrayBase <uint> ranks)
            where TEdgeData : struct, IGraphEdgeData
        {
            if (graph == null)
            {
                throw new ArgumentNullException("graph");
            }
            if (graph.VertexCount != ranks.Length - 1)
            {
                throw new ArgumentException("Graph and ranks array must have equal sizes.");
            }

            for (uint i = 0; i <= graph.VertexCount; i++)
            { // fill with default data.
                ranks[i] = i;
            }

            if (graph.VertexCount == 1)
            { // just return the rank for the one vertex.
                ranks[0] = 0;
                ranks[1] = 1;
            }

            // sort the complete graph and keep the transformations.
            QuickSort.Sort((i) => graph.HilbertDistance(n, ranks[i]), (i, j) =>
            {
                var temp = ranks[i];
                ranks[i] = ranks[j];
                ranks[j] = temp;
            }, 1, graph.VertexCount);
        }
Esempio n. 9
0
 /// <summary>
 /// Disposes of all resources associated with this index.
 /// </summary>
 public void Dispose()
 {
     if (_coordinates != null)
     {
         _coordinates.Dispose();
         _coordinates = null;
     }
 }
Esempio n. 10
0
        /// <summary>
        /// Creates a new huge coordinate index.
        /// </summary>
        /// <param name="coordinates"></param>
        private HugeCoordinateIndex(HugeArrayBase <float> coordinates)
        {
            _coordinates = coordinates;

            for (long idx = 0; idx < _coordinates.Length; idx++)
            {
                _coordinates[idx] = float.MaxValue;
            }
        }
        /// <summary>
        /// Creates a new huge coordinate index.
        /// </summary>
        /// <param name="size">The original size.</param>
        public HugeCoordinateCollectionIndex(long size)
        {
            _index = new HugeArray<ulong>(size);
            _coordinates = new HugeArray<float>(size * 2 * ESTIMATED_SIZE);

            for (long idx = 0; idx < _index.Length; idx++)
            {
                _index[idx] = 0;
            }

            for (long idx = 0; idx < _coordinates.Length; idx++)
            {
                _coordinates[idx] = float.MinValue;
            }
        }
Esempio n. 12
0
 /// <summary>
 /// Creates a graph using the existing data in the given arrays.
 /// </summary>
 /// <param name="coordinateArray"></param>
 /// <param name="vertexArray"></param>
 /// <param name="edgesArray"></param>
 /// <param name="edgeDataArray"></param>
 /// <param name="edgeShapeArray"></param>
 public DirectedGraph(
     HugeArrayBase <GeoCoordinateSimple> coordinateArray,
     HugeArrayBase <uint> vertexArray,
     HugeArrayBase <uint> edgesArray,
     HugeArrayBase <TEdgeData> edgeDataArray,
     HugeCoordinateCollectionIndex edgeShapeArray)
 {
     _vertices     = vertexArray;
     _coordinates  = coordinateArray;
     _edges        = edgesArray;
     _edgeData     = edgeDataArray;
     _edgeShapes   = edgeShapeArray;
     _nextVertexId = (uint)(_vertices.Length / VERTEX_SIZE);
     _nextEdgeId   = (uint)(edgesArray.Length / EDGE_SIZE);
 }
Esempio n. 13
0
        /// <summary>
        /// Creates a new huge coordinate index.
        /// </summary>
        /// <param name="size">The original size.</param>
        public HugeCoordinateCollectionIndex(long size)
        {
            _index       = new HugeArray <ulong>(size);
            _coordinates = new HugeArray <float>(size * 2 * ESTIMATED_SIZE);

            for (long idx = 0; idx < _index.Length; idx++)
            {
                _index[idx] = 0;
            }

            for (long idx = 0; idx < _coordinates.Length; idx++)
            {
                _coordinates[idx] = float.MinValue;
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Creates a new, memory mapped, huge coordinate index.
        /// </summary>
        /// <param name="file">The memory mapped file.</param>
        /// <param name="size">The original size.</param>
        public HugeCoordinateCollectionIndex(MemoryMappedFile file, long size)
        {
            _index       = new MemoryMappedHugeArrayUInt64(file, size);
            _coordinates = new MemoryMappedHugeArraySingle(file, size * 2 * ESTIMATED_SIZE);

            for (long idx = 0; idx < _index.Length; idx++)
            {
                _index[idx] = 0;
            }

            for (long idx = 0; idx < _coordinates.Length; idx++)
            {
                _coordinates[idx] = float.MinValue;
            }
        }
Esempio n. 15
0
 /// <summary>
 /// Creates a new in-memory graph.
 /// </summary>
 /// <param name="sizeEstimate"></param>
 /// <param name="coordinateArray"></param>
 /// <param name="vertexArray"></param>
 /// <param name="edgesArray"></param>
 /// <param name="edgeDataArray"></param>
 /// <param name="edgeShapeArray"></param>
 public DirectedGraph(long sizeEstimate, HugeArrayBase <GeoCoordinateSimple> coordinateArray,
                      HugeArrayBase <uint> vertexArray, HugeArrayBase <uint> edgesArray, HugeArrayBase <TEdgeData> edgeDataArray, HugeCoordinateCollectionIndex edgeShapeArray)
 {
     _nextVertexId = 1;
     _nextEdgeId   = 0;
     _vertices     = vertexArray;
     _vertices.Resize(sizeEstimate);
     _coordinates = coordinateArray;
     _coordinates.Resize(sizeEstimate);
     _edges = edgesArray;
     _edges.Resize(sizeEstimate * 3 * EDGE_SIZE);
     _edgeData = edgeDataArray;
     _edgeData.Resize(sizeEstimate * 3);
     _edgeShapes = edgeShapeArray;
     _edgeShapes.Resize(sizeEstimate * 3);
 }
 /// <summary>
 /// Creates a new coordinate collection.
 /// </summary>
 public HugeCoordinateCollection(HugeArrayBase<float> coordinates, long index, long size, bool reverse)
 {
     _pointer = index * 2;
     _count = size * 2;
     _coordinates = coordinates;
     _reverse = reverse;
 }
        /// <summary>
        /// Sorts the graph based on the given transformations.
        /// </summary>
        public override void Sort(HugeArrayBase <uint> transformations)
        {
            _reverseDirectNeighbours = null;

            _graph.Sort(transformations);
        }
        /// <summary>
        /// Creates a new, memory mapped, huge coordinate index.
        /// </summary>
        /// <param name="file">The memory mapped file.</param>
        /// <param name="size">The original size.</param>
        public HugeCoordinateCollectionIndex(MemoryMappedFile file, long size)
        {
            _index = new MemoryMappedHugeArrayUInt64(file, size);
            _coordinates = new MemoryMappedHugeArraySingle(file, size * 2 * ESTIMATED_SIZE);

            for (long idx = 0; idx < _index.Length; idx++)
            {
                _index[idx] = 0;
            }

            for (long idx = 0; idx < _coordinates.Length; idx++)
            {
                _coordinates[idx] = float.MinValue;
            }
        }
Esempio n. 19
0
 /// <summary>
 /// Creates a new huge coordinate collection.
 /// </summary>
 /// <param name="coordinates"></param>
 /// <param name="startIdx"></param>
 /// <param name="size"></param>
 public HugeCoordinateCollection(HugeArrayBase <float> coordinates, long startIdx, long size)
     : this(coordinates, startIdx, size, false)
 {
 }
 /// <summary>
 /// Disposes of all resources associated with this coordinate collection index.
 /// </summary>
 public void Dispose()
 {
     _index.Dispose();
     _index = null;
     _coordinates.Dispose();
     _coordinates = null;
 }
 /// <summary>
 /// Creates a new huge coordinate collection.
 /// </summary>
 /// <param name="coordinates"></param>
 /// <param name="startIdx"></param>
 /// <param name="size"></param>
 public HugeCoordinateCollection(HugeArrayBase<float> coordinates, long startIdx, long size)
     : this(coordinates, startIdx, size, false)
 {
 }
 /// <summary>
 /// Creates a new huge coordinate collection.
 /// </summary>
 /// <param name="coordinates"></param>
 /// <param name="startIdx"></param>
 /// <param name="size"></param>
 /// <param name="reverse"></param>
 public HugeCoordinateCollection(HugeArrayBase<float> coordinates, long startIdx, long size, bool reverse)
 {
     _startIdx = startIdx;
     _size = size;
     _coordinates = coordinates;
     _reverse = reverse;
 }
Esempio n. 23
0
 /// <summary>
 /// Disposes of all native resources associated with this object.
 /// </summary>
 public override void Dispose()
 {
     _baseArray.Dispose();
     _baseArray = null;
 }
Esempio n. 24
0
 /// <summary>
 /// Sorts the graph based on the given transformations.
 /// </summary>
 public abstract void Sort(HugeArrayBase <uint> transformations);
Esempio n. 25
0
 /// <summary>
 /// Sorts the vertices in the given graph based on a hilbert curve using the default step count.
 /// </summary>
 /// <typeparam name="TEdgeData"></typeparam>
 public static void BuildHilbertRank <TEdgeData>(this GraphBase <TEdgeData> graph,
                                                 HugeArrayBase <uint> ranks)
     where TEdgeData : struct, IGraphEdgeData
 {
     graph.BuildHilbertRank(GraphExtensions.DefaultHilbertSteps, ranks);
 }