Exemple #1
0
        public void Setup()
        {
            var costs = "" +
                        "3 3\n" +
                        "0 0 1\n" +
                        "0 1 2\n" +
                        "0 2 3\n" +
                        "1 0 4\n" +
                        "1 1 5\n" +
                        "1 2 6\n" +
                        "2 0 7\n" +
                        "2 1 8\n" +
                        "2 2 9\n";

            using (var ms = new MemoryStream())
                using (var costStream = new MemoryStream(Encoding.UTF8.GetBytes(costs)))
                {
                    var compiler = new ConnectionCostsCompiler(ms);
                    compiler.ReadCosts(costStream);
                    compiler.Compile();

                    ms.Seek(0, SeekOrigin.Begin);

                    var size       = ms.ReadInt32();
                    var costSize   = ms.ReadInt32();
                    var costValues = new short[costSize / sizeof(short)];
                    ms.ReadShortArray(costValues);
                    ConnectionCosts = new ConnectionCosts(size, costValues);
                }
        }
Exemple #2
0
        public void SetUp()
        {
            string costs = "" +
                           "3 3\n" +
                           "0 0 1\n" +
                           "0 1 2\n" +
                           "0 2 3\n" +
                           "1 0 4\n" +
                           "1 1 5\n" +
                           "1 2 6\n" +
                           "2 0 7\n" +
                           "2 1 8\n" +
                           "2 2 9\n";

            using (ConnectionCostsCompiler compiler = new ConnectionCostsCompiler())
                using (var outputStream = File.Create(costFile))
                {
                    var    bytes       = Encoding.UTF8.GetBytes(costs);
                    Stream inputStream = new MemoryStream(bytes);
                    compiler.ReadCosts(inputStream);
                    compiler.Compile(outputStream);
                }

            using (var readStream = File.OpenRead(costFile))
                using (var reader = new BinaryReader(readStream))
                {
                    int size        = reader.ReadRawInt32();
                    var costsBuffer = new MemoryStreamWrapper(ByteBufferIO.Read(readStream));
                    connectionCosts = new ConnectionCosts(size, costsBuffer);
                }
        }