Ejemplo n.º 1
0
        private void FillData(string fileName)
        {
            if (fileName == null)
            {
                fileName = "trending_today.in";
            }

            using (var sr = new StreamReader(fileName, Encoding.ASCII))
            {
                //
                var inputA = sr.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
                VideoCount    = inputA[0];
                EndpointCount = inputA[1];
                RequestCount  = inputA[2];
                CacheCount    = inputA[3];
                CacheCapacity = inputA[4];

                Endpoints = new Endpoint[EndpointCount];
                Requests  = new Request[RequestCount];
                Caches    = new CacheServer[CacheCount];

                for (int cacheId = 0; cacheId < CacheCount; cacheId++)
                {
                    Caches[cacheId] = new CacheServer {
                        id = cacheId
                    };
                }

                //
                inputA = sr.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();

                VideoSize = inputA;

                // Endpoints
                for (int endpointId = 0; endpointId < EndpointCount; endpointId++)
                {
                    var e = new Endpoint();

                    inputA     = sr.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
                    e.pingToDC = inputA[0];
                    e.id       = endpointId;
                    var linkCount = inputA[1];

                    for (int cs = 0; cs < linkCount; cs++)
                    {
                        inputA = sr.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();

                        e.caches.Add(new CacheLink(inputA[0], inputA[1]));

                        // Add link to cache and vice versa
                        Caches[inputA[0]].endpoints.Add(new CacheLink(endpointId, inputA[1]));
                    }

                    //
                    Endpoints[endpointId] = e;
                }

                // Requestes
                for (int requestId = 0; requestId < RequestCount; requestId++)
                {
                    inputA = sr.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();

                    //
                    var request = new Request(requestId, inputA[0], inputA[1], inputA[2]);
                    Requests[requestId] = request;
                }
            }
        }