Пример #1
0
        /// <summary>
        /// Play the given workload in a polling manner and store the results in the given file
        /// </summary>
        /// <param name="workload">The workload</param>
        /// <param name="employees">The amount of employees generated for the workload</param>
        /// <param name="path">The path for the results</param>
        /// <returns>The measurement results</returns>
        private static Results PlayWorkloadClassic(List <WorkloadAction> workload, int employees, string path)
        {
            var sb = new StringBuilder();

            watch.Restart();

            var employeesList = new List <Employee>(employees);

            sb.AppendLine("Initializing graph");

            Console.WriteLine("Running workload on classic interface");

            for (int i = 0; i < employees; i++)
            {
                workload[i].Perform(employeesList, sb);
            }
            watch.Stop();
            var initTime = watch.ElapsedMilliseconds;

            var first  = employeesList[0];
            var second = employeesList[1];

            sb.AppendFormat("Will query whether {0} and {1} are connected", first.Name, second.Name);
            sb.AppendLine();

            ScenarioGenerator.Evaluation = () =>
            {
                var analysis = new UnionFind <Employee>(e => e.Knows, employeesList);
                return(analysis.AreConnected(first, second).ToString());
            };

            watch.Restart();
            for (int i = employees; i < workload.Count; i++)
            {
                workload[i].Perform(employeesList, sb);
            }

            watch.Stop();
            var main = watch.ElapsedMilliseconds;

            File.WriteAllText(path, sb.ToString());

            Console.WriteLine("Completed. Polling took {0}ms", watch.ElapsedMilliseconds);

            //var memory = MemoryMeter.ComputeMemoryConsumption(pollQuery);

            return(new Results()
            {
                Initialization = initTime, MainWorkload = main
            });
        }
Пример #2
0
        public static IEnumerable <Tuple <TVertex, TVertex> > GetMST(UndirectedWeightedGraph <TVertex> graph)
        {
            if (graph == null)
            {
                throw new ArgumentNullException("graph", "Specify a non-null argument.");
            }

            if (graph.VertexCount == 0)
            {
                yield break;
            }

            if (ConnectedComponents <TVertex> .GetConnectedComponentsCount(graph) > 1)
            {
                throw new InvalidOperationException("Graph is not connected.");
            }

            PriorityQueue <Edge> queue = new PriorityQueue <Edge>();
            UnionFind <TVertex>  connectedComponents = new UnionFind <TVertex>();

            foreach (TVertex vertex in graph.GetVertices())
            {
                connectedComponents.Add(vertex);
                foreach (TVertex neighbour in graph.GetNeighbours(vertex))
                {
                    queue.Enqueue(new Edge(vertex, neighbour, graph.GetEdgeWeight(vertex, neighbour)));
                }
            }

            List <Tuple <TVertex, TVertex> > mst = new List <Tuple <TVertex, TVertex> >();

            while (!queue.IsEmpty())
            {
                Edge minCostEdge = queue.Dequeue();
                if (!connectedComponents.AreConnected(minCostEdge.Vertex1, minCostEdge.Vertex2))
                {
                    yield return(Tuple.Create(minCostEdge.Vertex1, minCostEdge.Vertex2));

                    connectedComponents.Union(minCostEdge.Vertex1, minCostEdge.Vertex2);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Play the given workload in a polling manner and store the results in the given file
        /// </summary>
        /// <param name="workload">The workload</param>
        /// <param name="employees">The amount of employees generated for the workload</param>
        /// <param name="path">The path for the results</param>
        /// <returns>The measurement results</returns>
        private static Results PlayWorkloadClassic(List<WorkloadAction> workload, int employees, string path)
        {
            var sb = new StringBuilder();
            watch.Restart();

            var employeesList = new List<Employee>(employees);

            sb.AppendLine("Initializing graph");

            Console.WriteLine("Running workload on classic interface");

            for (int i = 0; i < employees; i++)
            {
                workload[i].Perform(employeesList, sb);
            }
            watch.Stop();
            var initTime = watch.ElapsedMilliseconds;

            var first = employeesList[0];
            var second = employeesList[1];

            sb.AppendFormat("Will query whether {0} and {1} are connected", first.Name, second.Name);
            sb.AppendLine();

            ScenarioGenerator.Evaluation = () =>
            {
                var analysis = new UnionFind<Employee>(e => e.Knows, employeesList);
                return analysis.AreConnected(first, second).ToString();
            };

            watch.Restart();
            for (int i = employees; i < workload.Count; i++)
            {
                workload[i].Perform(employeesList, sb);
            }

            watch.Stop();
            var main = watch.ElapsedMilliseconds;

            File.WriteAllText(path, sb.ToString());

            Console.WriteLine("Completed. Polling took {0}ms", watch.ElapsedMilliseconds);

            //var memory = MemoryMeter.ComputeMemoryConsumption(pollQuery);

            return new Results() { Initialization = initTime, MainWorkload = main };
        }