public RouterDbStreamTarget(RouterDb db, Vehicle[] vehicles, bool allCore = false, int minimumStages = 1, bool normalizeTags = true, IEnumerable <ITwoPassProcessor> processors = null) { this._db = db; this._vehicles = vehicles; this._allNodesAreCore = allCore; this._normalizeTags = normalizeTags; this._createNodeCoordinatesDictionary = (Func <NodeCoordinatesDictionary>)(() => new NodeCoordinatesDictionary()); this._stageCoordinates = this._createNodeCoordinatesDictionary(); this._allRoutingNodes = (ILongIndex) new OsmSharp.Collections.LongIndex.LongIndex.LongIndex(); this._anyStageNodes = (ILongIndex) new OsmSharp.Collections.LongIndex.LongIndex.LongIndex(); this._coreNodes = (ILongIndex) new OsmSharp.Collections.LongIndex.LongIndex.LongIndex(); this._coreNodeIdMap = new CoreNodeIdMap(); this._processedWays = (ILongIndex) new OsmSharp.Collections.LongIndex.LongIndex.LongIndex(); this._minimumStages = minimumStages; foreach (Vehicle vehicle in vehicles) { foreach (Profile profile in vehicle.GetProfiles()) { db.AddSupportedProfile(profile); } } if (processors == null) { processors = (IEnumerable <ITwoPassProcessor>) new List <ITwoPassProcessor>(); } this.Processors = new List <ITwoPassProcessor>(processors); this.InitializeDefaultProcessors(); }
protected override void DoRun() { this._queue = new BinaryHeap <uint>((uint)this._graph.VertexCount); this._contractedFlags = (ILongIndex) new OsmSharp.Collections.LongIndex.LongIndex.LongIndex(); this._missesQueue = new Queue <bool>(); this.RemoveWitnessedEdges(); this.CalculateQueue(); uint? nullable = this.SelectNext(); float num1 = 0.0f; int num2 = 0; long vertexCount = this._graph.VertexCount; while (nullable.HasValue) { this.Contract(nullable.Value); nullable = this.SelectNext(); float num3 = (float)(System.Math.Floor((double)num2 / (double)vertexCount * 10000.0) / 100.0); if ((double)num3 < 99.0) { num3 = (float)(System.Math.Floor((double)num2 / (double)vertexCount * 100.0) / 1.0); } if ((double)num3 != (double)num1) { num1 = num3; int num4 = 0; int num5 = 0; int num6 = 0; Dictionary <uint, int> dictionary = new Dictionary <uint, int>(); for (uint vertex = 0; (long)vertex < this._graph.VertexCount; ++vertex) { if (!this._contractedFlags.Contains((long)vertex)) { dictionary.Clear(); DirectedMetaGraph.EdgeEnumerator edgeEnumerator = this._graph.GetEdgeEnumerator(vertex); if (edgeEnumerator != null) { int count = edgeEnumerator.Count; num4 = count + num4; if (num6 < count) { num6 = count; } } ++num5; } } double num7 = (double)num4 / (double)num5; Log.TraceEvent("HierarchyBuilder", TraceEventType.Information, "Preprocessing... {0}% [{1}/{2}] {3}q #{4} max {5}", (object)num3, (object)num2, (object)vertexCount, (object)this._queue.Count, (object)num7, (object)num6); } ++num2; } }
/// <summary> /// Closes this target. /// </summary> public override void Close() { _coordinates.Clear(); _dataCache.Clear(); _idTransformations.Clear(); if (_nodesToCache != null) { _nodesToCache.Clear(); } if (_waysToCache != null) { _waysToCache.Clear(); } _preIndex = null; _relevantNodes = null; _tagsIndex = null; }
public override void AddNode(Node node) { if (this._firstPass) { this._nodeCount = this._nodeCount + 1L; double num1 = node.Latitude.Value; if (num1 < this._minLatitude) { this._minLatitude = num1; } if (num1 > this._maxLatitude) { this._maxLatitude = num1; } double num2 = node.Longitude.Value; if (num2 < this._minLongitude) { this._minLongitude = num2; } if (num2 > this._maxLongitude) { this._maxLongitude = num2; } if (this.Processors == null) { return; } foreach (ITwoPassProcessor processor in this.Processors) { processor.FirstPass(node); } } else { if (this.Processors != null) { foreach (ITwoPassProcessor processor in this.Processors) { processor.SecondPass(node); } } long?id1; if (!this._stages[this._stage].Contains(node.Longitude.Value, node.Latitude.Value)) { ILongIndex anyStageNodes = this._anyStageNodes; id1 = ((OsmGeo)node).Id; long number = id1.Value; if (!anyStageNodes.Contains(number)) { return; } } ILongIndex allRoutingNodes = this._allRoutingNodes; id1 = ((OsmGeo)node).Id; long number1 = id1.Value; if (!allRoutingNodes.Contains(number1)) { return; } NodeCoordinatesDictionary stageCoordinates = this._stageCoordinates; id1 = ((OsmGeo)node).Id; long id2 = id1.Value; // ISSUE: variable of a boxed type GeoCoordinateSimple local = new GeoCoordinateSimple() { Latitude = (float)node.Latitude.Value, Longitude = (float)node.Longitude.Value }; stageCoordinates.Add(id2, (ICoordinate)local); } }
public float Calculate(ILongIndex contractedFlags, uint vertex) { int num1 = 0; int num2 = 0; List <Edge> edgeList = new List <Edge>((IEnumerable <Edge>) this._graph.Graph.GetEdgeEnumerator(vertex)); int index1 = 0; while (index1 < edgeList.Count) { DirectedMetaGraph.EdgeEnumerator edgeEnumerator = this._graph.GetEdgeEnumerator(edgeList[index1].Neighbour); edgeEnumerator.Reset(); while (edgeEnumerator.MoveNext()) { if ((int)edgeEnumerator.Neighbour == (int)vertex) { ++num1; } } if (contractedFlags.Contains((long)edgeList[index1].Neighbour)) { edgeEnumerator.MoveTo(vertex); edgeEnumerator.Reset(); while (edgeEnumerator.MoveNext()) { if ((int)edgeEnumerator.Neighbour == (int)edgeList[index1].Neighbour) { ++num1; } } edgeList.RemoveAt(index1); } else { ++index1; } } for (int capacity = 1; capacity < edgeList.Count; ++capacity) { Edge edge1 = edgeList[capacity]; float weight1; bool? direction1; ContractedEdgeDataSerializer.Deserialize(edge1.Data[0], out weight1, out direction1); bool flag1 = !direction1.HasValue || direction1.Value; bool flag2 = !direction1.HasValue || !direction1.Value; bool[] forwardWitness = new bool[capacity]; bool[] backwardWitness = new bool[capacity]; List <uint> targets = new List <uint>(capacity); List <float> weights = new List <float>(capacity); for (int index2 = 0; index2 < capacity; ++index2) { Edge edge2 = edgeList[index2]; float weight2; bool? direction2; ContractedEdgeDataSerializer.Deserialize(edge2.Data[0], out weight2, out direction2); bool flag3 = !direction2.HasValue || direction2.Value; bool flag4 = !direction2.HasValue || !direction2.Value; forwardWitness[index2] = !(flag2 & flag3); backwardWitness[index2] = !(flag1 & flag4); targets.Add(edge2.Neighbour); weights.Add(weight1 + weight2); } this._witnessCalculator.Calculate(this._graph.Graph, edge1.Neighbour, targets, weights, ref forwardWitness, ref backwardWitness, vertex); for (int index2 = 0; index2 < capacity; ++index2) { Edge edge2 = edgeList[index2]; int removed = 0; int added = 0; if (!forwardWitness[index2] && !backwardWitness[index2]) { this._graph.TryAddOrUpdateEdge(edge1.Neighbour, edge2.Neighbour, weights[index2], new bool?(), vertex, out added, out removed); int num3 = num2 + added; int num4 = num1 + removed; this._graph.TryAddOrUpdateEdge(edge2.Neighbour, edge1.Neighbour, weights[index2], new bool?(), vertex, out added, out removed); num2 = num3 + added; num1 = num4 + removed; } else if (!forwardWitness[index2]) { this._graph.TryAddOrUpdateEdge(edge1.Neighbour, edge2.Neighbour, weights[index2], new bool?(true), vertex, out added, out removed); int num3 = num2 + added; int num4 = num1 + removed; this._graph.TryAddOrUpdateEdge(edge2.Neighbour, edge1.Neighbour, weights[index2], new bool?(false), vertex, out added, out removed); num2 = num3 + added; num1 = num4 + removed; } else if (!backwardWitness[index2]) { this._graph.TryAddOrUpdateEdge(edge1.Neighbour, edge2.Neighbour, weights[index2], new bool?(false), vertex, out added, out removed); int num3 = num2 + added; int num4 = num1 + removed; this._graph.TryAddOrUpdateEdge(edge2.Neighbour, edge1.Neighbour, weights[index2], new bool?(true), vertex, out added, out removed); num2 = num3 + added; num1 = num4 + removed; } } } int num5 = 0; this._contractionCount.TryGetValue(vertex, out num5); int num6 = 0; this._depth.TryGetValue((long)vertex, out num6); return((float)(this.DifferenceFactor * (num2 - num1) + this.DepthFactor * num6 + this.ContractedFactor * num5)); }