/// <summary> /// Creates a new processor target. /// </summary> /// <param name="dynamicGraph">The graph that will be filled.</param> /// <param name="interpreter">The interpreter to generate the edge data.</param> /// <param name="edgeComparer"></param> /// <param name="tagsIndex"></param> /// <param name="idTransformations"></param> /// <param name="box"></param> protected DynamicGraphOsmStreamWriter( IDynamicGraphRouterDataSource <TEdgeData> dynamicGraph, IOsmRoutingInterpreter interpreter, IDynamicGraphEdgeComparer <TEdgeData> edgeComparer, ITagsCollectionIndex tagsIndex, IDictionary <long, uint> idTransformations, GeoCoordinateBox box) { _dynamicGraph = dynamicGraph; _interpreter = interpreter; _edgeComparer = edgeComparer; _box = box; _tagsIndex = tagsIndex; _idTransformations = idTransformations; _preIndexMode = true; _preIndex = new HashSet <long>(); _usedTwiceOrMore = new HashSet <long>(); _dataCache = new OsmDataCacheMemory(); }
/// <summary> /// Creates a new pre-processor. /// </summary> /// <param name="target"></param> /// <param name="calculator"></param> /// <param name="witnessCalculator"></param> public CHPreProcessor(IDynamicGraphRouterDataSource<CHEdgeData> target, INodeWeightCalculator calculator, INodeWitnessCalculator witnessCalculator) { _comparer = null; _target = target; _calculator = calculator; _witnessCalculator = witnessCalculator; _queue = new BinairyHeap<uint>(target.VertexCount + (uint)System.Math.Max(target.VertexCount * 0.1, 5)); _lowestPriorities = new float[target.VertexCount + (uint)System.Math.Max(target.VertexCount * 0.1, 5)]; for(int idx = 0; idx < _lowestPriorities.Length; idx++) { // uncontracted = priority != float.MinValue. _lowestPriorities[idx] = float.MaxValue; } }
/// <summary> /// Creates a new processor target. /// </summary> /// <param name="dynamicGraph">The graph that will be filled.</param> /// <param name="interpreter">The interpreter to generate the edge data.</param> /// <param name="edgeComparer"></param> /// <param name="tagsIndex"></param> /// <param name="idTransformations"></param> protected DynamicGraphOsmStreamWriter(IDynamicGraphRouterDataSource <TEdgeData> dynamicGraph, IOsmRoutingInterpreter interpreter, IDynamicGraphEdgeComparer <TEdgeData> edgeComparer, ITagsCollectionIndex tagsIndex, IDictionary <long, uint> idTransformations) : this(dynamicGraph, interpreter, edgeComparer, tagsIndex, idTransformations, null) { }
/// <summary> /// Adds a new edge. /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <param name="data"></param> /// <param name="coordinates"></param> /// <param name="comparer"></param> public void AddEdge(uint from, uint to, TEdgeData data, GeoCoordinateSimple[] coordinates, IDynamicGraphEdgeComparer <TEdgeData> comparer) { _graph.AddEdge(from, to, data, coordinates, comparer); }
/// <summary> /// Adds an edge with the associated data. /// </summary> /// <param name="vertex1"></param> /// <param name="vertex2"></param> /// <param name="data"></param> /// <param name="coordinates"></param> /// <param name="comparer">Comparator to compare edges and replace obsolete ones.</param> public void AddEdge(uint vertex1, uint vertex2, TEdgeData data, GeoCoordinateSimple[] coordinates, IDynamicGraphEdgeComparer <TEdgeData> comparer) { // if (!data.Forward) { throw new ArgumentOutOfRangeException("data", "Edge data has to be forward."); } if (vertex1 == vertex2) { throw new ArgumentException("Given vertices must be different."); } if (_nextVertexId <= vertex1) { throw new ArgumentOutOfRangeException("vertex1", "vertex1 is not part of this graph."); } if (_nextVertexId <= vertex2) { throw new ArgumentOutOfRangeException("vertex2", "vertex2 is not part of this graph."); } var edgeId = _vertices[vertex1]; if (_vertices[vertex1] != NO_EDGE) { // check for an existing edge first. // check if the arc exists already. edgeId = _vertices[vertex1]; uint nextEdgeSlot = 0; while (edgeId != NO_EDGE) { // keep looping. uint otherVertexId = 0; uint previousEdgeId = edgeId; bool forward = true; if (_edges[edgeId + NODEA] == vertex1) { otherVertexId = _edges[edgeId + NODEB]; nextEdgeSlot = edgeId + NEXTNODEA; edgeId = _edges[edgeId + NEXTNODEA]; } else { otherVertexId = _edges[edgeId + NODEA]; nextEdgeSlot = edgeId + NEXTNODEB; edgeId = _edges[edgeId + NEXTNODEB]; forward = false; } if (otherVertexId == vertex2) { // this is the edge we need. if (!forward) { data = (TEdgeData)data.Reverse(); } if (comparer != null) { // there is a comparer. var existingData = _edgeData[previousEdgeId / 4]; if (comparer.Overlaps(data, existingData)) { // an arc was found that represents the same directional information. _edgeData[previousEdgeId / 4] = data; _edgeShapes[previousEdgeId / 4] = coordinates; } return; } _edgeData[previousEdgeId / 4] = data; _edgeShapes[previousEdgeId / 4] = coordinates; return; } } // create a new edge. edgeId = _nextEdgeId; if (_nextEdgeId + NEXTNODEB >= _edges.Length) { // there is a need to increase edges array. this.IncreaseEdgeSize(); } _edges[_nextEdgeId + NODEA] = vertex1; _edges[_nextEdgeId + NODEB] = vertex2; _edges[_nextEdgeId + NEXTNODEA] = NO_EDGE; _edges[_nextEdgeId + NEXTNODEB] = NO_EDGE; _nextEdgeId = _nextEdgeId + EDGE_SIZE; // append the new edge to the from list. _edges[nextEdgeSlot] = edgeId; // set data. _edgeData[edgeId / 4] = data; _edgeShapes[edgeId / 4] = coordinates; } else { // create a new edge and set. edgeId = _nextEdgeId; _vertices[vertex1] = _nextEdgeId; if (_nextEdgeId + NEXTNODEB >= _edges.Length) { // there is a need to increase edges array. this.IncreaseEdgeSize(); } _edges[_nextEdgeId + NODEA] = vertex1; _edges[_nextEdgeId + NODEB] = vertex2; _edges[_nextEdgeId + NEXTNODEA] = NO_EDGE; _edges[_nextEdgeId + NEXTNODEB] = NO_EDGE; _nextEdgeId = _nextEdgeId + EDGE_SIZE; // set data. _edgeData[edgeId / 4] = data; _edgeShapes[edgeId / 4] = coordinates; } var toEdgeId = _vertices[vertex2]; if (toEdgeId != NO_EDGE) { // there are existing edges. uint nextEdgeSlot = 0; while (toEdgeId != NO_EDGE) { // keep looping. uint otherVertexId = 0; if (_edges[toEdgeId + NODEA] == vertex2) { otherVertexId = _edges[toEdgeId + NODEB]; nextEdgeSlot = toEdgeId + NEXTNODEA; toEdgeId = _edges[toEdgeId + NEXTNODEA]; } else { otherVertexId = _edges[toEdgeId + NODEA]; nextEdgeSlot = toEdgeId + NEXTNODEB; toEdgeId = _edges[toEdgeId + NEXTNODEB]; } } _edges[nextEdgeSlot] = edgeId; } else { // there are no existing edges point the vertex straight to it's first edge. _vertices[vertex2] = edgeId; } return; }
/// <summary> /// Adds a new arc. /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <param name="data"></param> /// <param name="comparer"></param> public void AddArc(uint from, uint to, TEdgeData data, IDynamicGraphEdgeComparer <TEdgeData> comparer) { _graph.AddArc(from, to, data, comparer); }
/// <summary> /// Creates a new processor target. /// </summary> /// <param name="dynamicGraph">The graph that will be filled.</param> /// <param name="interpreter">The interpreter to generate the edge data.</param> /// <param name="edgeComparer"></param> /// <param name="tagsIndex"></param> protected DynamicGraphOsmStreamWriter(IDynamicGraphRouterDataSource <TEdgeData> dynamicGraph, IOsmRoutingInterpreter interpreter, IDynamicGraphEdgeComparer <TEdgeData> edgeComparer, ITagsIndex tagsIndex) : this(dynamicGraph, interpreter, edgeComparer, tagsIndex, new Dictionary <long, uint>()) { }
/// <summary> /// Creates a new processor target. /// </summary> /// <param name="dynamicGraph">The graph that will be filled.</param> /// <param name="interpreter">The interpreter to generate the edge data.</param> /// <param name="edgeComparer"></param> protected DynamicGraphOsmStreamWriter(IDynamicGraph <TEdgeData> dynamicGraph, IRoutingInterpreter interpreter, IDynamicGraphEdgeComparer <TEdgeData> edgeComparer) : this(dynamicGraph, interpreter, edgeComparer, new SimpleTagsIndex(), new Dictionary <long, uint>()) { }
/// <summary> /// Creates a new processor target. /// </summary> /// <param name="dynamicGraph">The graph that will be filled.</param> /// <param name="interpreter">The interpreter to generate the edge data.</param> /// <param name="edgeComparer"></param> protected DynamicGraphOsmStreamWriter(IDynamicGraphRouterDataSource <TEdgeData> dynamicGraph, IOsmRoutingInterpreter interpreter, IDynamicGraphEdgeComparer <TEdgeData> edgeComparer) : this(dynamicGraph, interpreter, edgeComparer, new TagsTableCollectionIndex(), new HugeDictionary <long, uint>()) { }
/// <summary> /// Creates a new processor target. /// </summary> /// <param name="dynamicGraph">The graph that will be filled.</param> /// <param name="interpreter">The interpreter to generate the edge data.</param> /// <param name="edgeComparer"></param> /// <param name="tagsIndex"></param> /// <param name="idTransformations"></param> /// <param name="collectIntermediates"></param> protected DynamicGraphOsmStreamWriter( IDynamicGraphRouterDataSource <TEdgeData> dynamicGraph, IOsmRoutingInterpreter interpreter, IDynamicGraphEdgeComparer <TEdgeData> edgeComparer, ITagsCollectionIndex tagsIndex, HugeDictionary <long, uint> idTransformations, bool collectIntermediates) { _dynamicGraph = dynamicGraph; _interpreter = interpreter; _edgeComparer = edgeComparer; _tagsIndex = tagsIndex; _idTransformations = idTransformations; _preIndexMode = true; _preIndex = new OsmSharp.Collections.LongIndex.LongIndex.LongIndex(); _relevantNodes = new OsmSharp.Collections.LongIndex.LongIndex.LongIndex(); _collectIntermediates = collectIntermediates; _dataCache = new OsmDataCacheMemory(); }