예제 #1
0
        public static RouterDb Deserialize(Stream stream, RouterDbProfile profile)
        {
            int num1 = stream.ReadByte();

            if (num1 != 1)
            {
                throw new Exception(string.Format("Cannot deserialize routing db: Invalid version #: {0}.", (object)num1));
            }
            byte[] numArray = new byte[16];
            stream.Read(numArray, 0, 16);
            Guid guid = new Guid(numArray);

            string[]           strArray           = stream.ReadWithSizeStringArray();
            TagsCollectionBase tagsCollectionBase = stream.ReadWithSizeTagsCollection();
            int                num2             = stream.ReadByte();
            AttributesIndex    attributesIndex1 = AttributesIndex.Deserialize((Stream) new LimitedStream(stream), true);
            AttributesIndex    attributesIndex2 = AttributesIndex.Deserialize((Stream) new LimitedStream(stream), true);
            RoutingNetwork     network          = RoutingNetwork.Deserialize(stream, profile == null ? (RoutingNetworkProfile)null : profile.RoutingNetworkProfile);
            AttributesIndex    profiles         = attributesIndex1;
            AttributesIndex    meta             = attributesIndex2;
            TagsCollectionBase dbMeta           = tagsCollectionBase;

            string[] supportedProfiles = strArray;
            RouterDb routerDb          = new RouterDb(guid, network, profiles, meta, dbMeta, supportedProfiles);

            for (int index1 = 0; index1 < num2; ++index1)
            {
                string            index2            = stream.ReadWithSizeString();
                DirectedMetaGraph directedMetaGraph = DirectedMetaGraph.Deserialize(stream, profile == null ? (DirectedMetaGraphProfile)null : profile.DirectedMetaGraphProfile);
                routerDb._contracted[index2] = directedMetaGraph;
            }
            return(routerDb);
        }
예제 #2
0
        /// <summary>
        /// Deserializes contraction data from the given stream.
        /// </summary>
        public static ContractedDb Deserialize(Stream stream, ContractedDbProfile profile)
        {
            // read version # first:
            // 1: means regular non-edge contracted data.
            // 2: means regular edge contracted data.

            var version = stream.ReadByte();

            if (version == 1)
            {
                return(new ContractedDb(DirectedMetaGraph.Deserialize(stream, profile == null ? null : profile.NodeBasedProfile), false));
            }
            else if (version == 2)
            {
                return(new ContractedDb(DirectedDynamicGraph.Deserialize(stream, profile == null ? null : profile.EdgeBasedProfile)));
            }
            else if (version == 3)
            {
                return(new ContractedDb(DirectedMetaGraph.Deserialize(stream, profile == null ? null : profile.NodeBasedProfile), true));
            }
            else
            {
                throw new Exception(string.Format("Cannot deserialize contracted graph: Invalid version #: {0}.", version));
            }
        }
예제 #3
0
 public void DeserializeAndAddContracted(Stream stream, DirectedMetaGraphProfile profile)
 {
     byte[] numArray = new byte[16];
     stream.Read(numArray, 0, 16);
     if (new Guid(numArray) != this.Guid)
     {
         throw new Exception("Cannot add this contracted graph, guid's do not match.");
     }
     this._contracted[stream.ReadWithSizeString()] = DirectedMetaGraph.Deserialize(stream, profile);
 }
예제 #4
0
        public void TestDeserialize()
        {
            var graph = new DirectedMetaGraph(1, 1, 10);

            graph.AddEdge(0, 1, 1, 100);

            // serialize.
            using (var stream = new System.IO.MemoryStream())
            {
                var size = graph.Serialize(stream);

                stream.Seek(0, System.IO.SeekOrigin.Begin);

                var deserializedGraph = DirectedMetaGraph.Deserialize(stream, DirectedMetaGraphProfile.Aggressive40);
                Assert.AreEqual(size, stream.Position);

                Assert.AreEqual(2, deserializedGraph.VertexCount);
                Assert.AreEqual(1, deserializedGraph.EdgeCount);

                // verify all edges.
                var edges = deserializedGraph.GetEdgeEnumerator(0);
                Assert.AreEqual(1, edges.Count());
                Assert.AreEqual(1, edges.First().Data[0]);
                Assert.AreEqual(1, edges.First().Neighbour);

                edges = deserializedGraph.GetEdgeEnumerator(1);
                Assert.AreEqual(0, edges.Count());
            }

            graph = new DirectedMetaGraph(1, 1, 10);
            graph.AddEdge(0, 1, 1, 100);
            graph.AddEdge(0, 2, 2, 200);
            graph.AddEdge(0, 3, 3, 300);
            graph.AddEdge(0, 4, 4, 400);
            graph.AddEdge(5, 1, 5, 500);
            graph.AddEdge(5, 2, 6, 600);
            graph.AddEdge(5, 3, 7, 700);
            graph.AddEdge(5, 4, 8, 800);

            // serialize.
            using (var stream = new System.IO.MemoryStream())
            {
                var size = graph.Serialize(stream);

                stream.Seek(0, System.IO.SeekOrigin.Begin);

                var deserializedGraph = DirectedMetaGraph.Deserialize(stream, DirectedMetaGraphProfile.Aggressive40);
                Assert.AreEqual(size, stream.Position);

                Assert.AreEqual(6, deserializedGraph.VertexCount);
                Assert.AreEqual(8, deserializedGraph.EdgeCount);
            }
        }