/// <summary>
 /// Executes a test adding tags from a PBF file.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="index"></param>
 /// <param name="pbfFile"></param>
 public static void Test(string name, ITagsCollectionIndex index, string pbfFile)
 {
     FileInfo testFile = new FileInfo(string.Format(@".\TestFiles\{0}",pbfFile));
     Stream stream = testFile.OpenRead();
     PBFOsmStreamSource source = new PBFOsmStreamSource(stream);
     ITagCollectionIndexTests.TestAdd(name, index, source);
 }
 /// <summary>
 /// Creates a new target.
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="dynamicGraph"></param>
 /// <param name="interpreter"></param>
 /// <param name="tagsIndex"></param>
 /// <param name="vehicle"></param>
 public CHEdgeGraphFileStreamTarget(Stream stream, DynamicGraphRouterDataSource<CHEdgeData> dynamicGraph,
     IOsmRoutingInterpreter interpreter, ITagsCollectionIndex tagsIndex, Vehicle vehicle)
     : base(dynamicGraph, interpreter, tagsIndex, vehicle)
 {
     _graph = dynamicGraph;
     _graphStream = stream;
 }
        /// <summary>
        /// Executes the tests.
        /// </summary>
        public static void Test(string name, ITagsCollectionIndex index, int addCount, int accessCount)
        {
            // tests adding tag collection to the given index.
            ITagCollectionIndexTests.TestAdd(name,
                new TagsTableCollectionIndex(), addCount);

            // tests random access.
            ITagCollectionIndexTests.TestRandomAccess(name, index, accessCount);
        }
        /// <summary>
        /// Tests the given tags collection index.
        /// </summary>
        /// <param name="tagsCollectionIndex"></param>
        protected void TestTagsCollectionIndex(ITagsCollectionIndex tagsCollectionIndex)
        {
            List<KeyValuePair<uint, TagsCollectionBase>> addedTags = new List<KeyValuePair<uint, TagsCollectionBase>>();
            for (int i = 0; i < 100; i++)
            {
                TagsCollection tagsCollection = new TagsCollection();
                int tagCollectionSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(3) + 1;
                for (int idx = 0; idx < tagCollectionSize; idx++)
                {
                    int tagValue = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(3);
                    tagsCollection.Add(
                        string.Format("key_{0}", tagValue),
                        string.Format("value_{0}", tagValue));
                }
                int addCount = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(2) + 1;
                for (int idx = 0; idx < addCount; idx++)
                {
                    uint tagsId = tagsCollectionIndex.Add(tagsCollection);
                    addedTags.Add(new KeyValuePair<uint, TagsCollectionBase>(tagsId, tagsCollection));

                    TagsCollectionBase indexTags = tagsCollectionIndex.Get(tagsId);
                    Assert.AreEqual(tagsCollection.Count, indexTags.Count);
                    foreach (Tag tag in tagsCollection)
                    {
                        Assert.IsTrue(indexTags.ContainsKeyValue(tag.Key, tag.Value));
                    }
                }
            }

            // check the index.
            foreach (KeyValuePair<uint, TagsCollectionBase> pair in addedTags)
            {
                TagsCollectionBase indexTags = tagsCollectionIndex.Get(pair.Key);
                Assert.AreEqual(pair.Value.Count, indexTags.Count);
                foreach (Tag tag in pair.Value)
                {
                    Assert.IsTrue(indexTags.ContainsKeyValue(tag.Key, tag.Value));
                }
                foreach (Tag tag in indexTags)
                {
                    Assert.IsTrue(pair.Value.ContainsKeyValue(tag.Key, tag.Value));
                }
            }
        }
 /// <summary>
 /// Tests adding simple tags to the given index.
 /// </summary>
 /// <param name="index"></param>
 /// <param name="collectionCount"></param>
 public static void FillIndex(ITagsCollectionIndex index, int collectionCount)
 {
     for (int i = 0; i < collectionCount; i++)
     {
         TagsCollection tagsCollection = new TagsCollection();
         int tagCollectionSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(3) + 1;
         for (int idx = 0; idx < tagCollectionSize; idx++)
         {
             int tagValue = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(100);
             tagsCollection.Add(
                 string.Format("key_{0}", tagValue),
                 string.Format("value_{0}", tagValue));
         }
         int addCount = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(2) + 1;
         for (int idx = 0; idx < addCount; idx++)
         {
             uint tagsId = index.Add(tagsCollection);
         }
     }
 }
Example #6
0
 /// <summary>
 /// Creates a new OSM stream target.
 /// </summary>
 /// <param name="tagsIndex"></param>
 public OsmStreamTargetTags(ITagsCollectionIndex tagsIndex)
 {
     _tagsIndex = tagsIndex;
 }
Example #7
0
        /// <summary>
        /// Serializes all the tags in the given index. This serialization preserves the id's of each tag collection.
        /// </summary>
        /// <param name="stream">The target stream.</param>
        /// <param name="tagsIndex">The tags index to serialize.</param>
        public static void Serialize(Stream stream, ITagsCollectionIndex tagsIndex)
        {
            int begin = (int)stream.Position;

            // build a string index.
            ObjectTable<string> stringTable = new ObjectTable<string>(false);

            // convert tag collections to simpler objects.
            List<KeyValuePair<uint, List<KeyValuePair<uint, uint>>>> tagsIndexList = new List<KeyValuePair<uint,List<KeyValuePair<uint,uint>>>>();
            for (uint tagId = 0; tagId < tagsIndex.Max; tagId++)
            {
                TagsCollectionBase tagsCollection = tagsIndex.Get(tagId);
                if (tagsCollection != null)
                { // convert the tags collection to a list and add to the tag index.
                    List<KeyValuePair<uint, uint>> tagsList = new List<KeyValuePair<uint, uint>>();
                    foreach (Tag tag in tagsCollection)
                    {
                        uint keyId = stringTable.Add(tag.Key);
                        uint valueId = stringTable.Add(tag.Value);

                        tagsList.Add(new KeyValuePair<uint, uint>(
                            keyId, valueId));
                    }
                    tagsIndexList.Add(new KeyValuePair<uint, List<KeyValuePair<uint, uint>>>(tagId, tagsList));
                }
            }

            // do the serialization.
            TagIndexSerializer.Serialize(begin, stream, tagsIndexList, stringTable);

            // clear everything.
            tagsIndexList.Clear();
        }
        /// <summary>
        /// Tests adding simple tags to the given index.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="index"></param>
        /// <param name="collectionCount"></param>
        public static void TestAdd(string name, ITagsCollectionIndex index,
            int collectionCount)
        {
            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer(string.Format("{0}.Add", name));
            performanceInfo.Start();
            performanceInfo.Report("Adding {0} tag collections...", collectionCount);

            ITagCollectionIndexTests.FillIndex(index, collectionCount);

            performanceInfo.Stop();

            Console.Write("", index.Max);
        }
 /// <summary>
 /// Tests adding simple tags to the given index.
 /// </summary>
 /// <param name="index"></param>
 /// <param name="source"></param>
 public static void FillIndex(ITagsCollectionIndex index, OsmStreamSource source)
 {
     OsmStreamTargetTags tagsTarget = new OsmStreamTargetTags(index);
     tagsTarget.RegisterSource(source);
     tagsTarget.Pull();
 }
Example #10
0
        /// <summary>
        /// Calculates edge data.
        /// </summary>
        /// <param name="tagsIndex"></param>
        /// <param name="tags"></param>
        /// <param name="directionForward"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="edgeInterpreter"></param>
        /// <returns></returns>
        protected override LiveEdge CalculateEdgeData(IEdgeInterpreter edgeInterpreter, ITagsCollectionIndex tagsIndex,
                                                      TagsCollection tags, bool directionForward, GeoCoordinate from, GeoCoordinate to)
        {
            if (edgeInterpreter == null)
            {
                throw new ArgumentNullException("edgeInterpreter");
            }
            if (tagsIndex == null)
            {
                throw new ArgumentNullException("tagsIndex");
            }
            if (tags == null)
            {
                throw new ArgumentNullException("tags");
            }
            if (from == null)
            {
                throw new ArgumentNullException("from");
            }
            if (to == null)
            {
                throw new ArgumentNullException("to");
            }

            return(new LiveEdge()
            {
                Forward = directionForward,
                Tags = tagsIndex.Add(tags)
            });
        }
        /// <summary>
        /// Tests adding simple tags to the given index.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="index"></param>
        /// <param name="source"></param>
        public static void TestAdd(string name, ITagsCollectionIndex index,
            OsmStreamSource source)
        {
            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer(string.Format("{0}.Add", name));
            performanceInfo.Start();
            performanceInfo.Report("Adding tags from {0}...", source.ToString());

            ITagCollectionIndexTests.FillIndex(index, source);

            performanceInfo.Stop();

            Console.Write("", index.Max);
        }
        /// <summary>
        /// Serialize/deserialize index.
        /// </summary>
        /// <param name="index"></param>
        /// <param name="position"></param>
        /// <returns></returns>
        private ITagsCollectionIndexReadonly SerializeDeserializeLimitedStream(ITagsCollectionIndex index, int position)
        {
            MemoryStream memoryStream = new MemoryStream();
            memoryStream.Seek(position, SeekOrigin.Begin);

            LimitedStream stream = new LimitedStream(memoryStream);
            TagIndexSerializer.Serialize(stream, index);
            stream.Seek(0, SeekOrigin.Begin);

            return TagIndexSerializer.Deserialize(stream);
        }
        /// <summary>
        /// Serialize/deserialize index.
        /// </summary>
        /// <param name="index"></param>
        /// <param name="blockSize"></param>
        /// <param name="position"></param>
        /// <returns></returns>
        private ITagsCollectionIndexReadonly SerializeDeserializeBlock(ITagsCollectionIndex index, uint blockSize, int position)
        {
            MemoryStream stream = new MemoryStream();

            stream.Seek(position, SeekOrigin.Begin);
            TagIndexSerializer.SerializeBlocks(stream, index, blockSize);

            stream.Seek(position, SeekOrigin.Begin);
            return TagIndexSerializer.DeserializeBlocks(stream);
        }
        /// <summary>
        /// Serialize/deserialize index.
        /// </summary>
        /// <param name="index"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        private ITagsCollectionIndexReadonly SerializeDeserialize(ITagsCollectionIndex index, uint from, uint to)
        {
            MemoryStream stream = new MemoryStream();
            TagIndexSerializer.Serialize(stream, index, from, to);
            stream.Seek(0, SeekOrigin.Begin);

            return TagIndexSerializer.Deserialize(stream);
        }
Example #15
0
 /// <summary>
 /// Creates a new osm edge data processing target.
 /// </summary>
 /// <param name="dynamicGraph"></param>
 /// <param name="interpreter">Inteprets the OSM-data.</param>
 /// <param name="tagsIndex">Holds all the tags.</param>
 public LiveGraphOsmStreamTarget(IDynamicGraphRouterDataSource <LiveEdge> dynamicGraph,
                                 IOsmRoutingInterpreter interpreter, ITagsCollectionIndex tagsIndex)
     : this(dynamicGraph, interpreter, tagsIndex, new Dictionary <long, uint>())
 {
 }
 /// <summary>
 /// Creates a reference stream target.
 /// </summary>
 /// <param name="dynamicGraph"></param>
 /// <param name="interpreter"></param>
 /// <param name="tagsIndex"></param>
 /// <param name="vehicles"></param>
 public ReferenceGraphTarget(IDynamicGraphRouterDataSource<LiveEdge> dynamicGraph, IOsmRoutingInterpreter interpreter, ITagsCollectionIndex tagsIndex, IEnumerable<Vehicle> vehicles)
     : base(dynamicGraph, interpreter, tagsIndex, vehicles, false)
 {
 }
Example #17
0
 /// <summary>
 /// Creates a new osm edge data processing target.
 /// </summary>
 /// <param name="dynamicGraph"></param>
 /// <param name="interpreter"></param>
 /// <param name="tagsIndex"></param>
 /// <param name="box"></param>
 public LiveGraphOsmStreamTarget(IDynamicGraphRouterDataSource <LiveEdge> dynamicGraph,
                                 IOsmRoutingInterpreter interpreter, ITagsCollectionIndex tagsIndex, GeoCoordinateBox box, IEnumerable <Vehicle> vehicles)
     : this(dynamicGraph, interpreter, tagsIndex, new Dictionary <long, uint>(), box, vehicles)
 {
 }