Exemplo n.º 1
0
        public void SimpleCalculation()
        {
            const int NUM   = 100;
            const int TOTAL = (NUM + 1) * NUM / 2;

            var sum = new int[NUM];

            var list = new List <ITopologicalNode>(NUM);

            for (var i = 1; i <= NUM; i++)
            {
                var task = new DemoTask(i, n => sum[n - 1] = n);
                list.Add(task);
            }

            var provider = default(TopologicalTaskProvider);

            Assert.DoesNotThrow(() => provider = new TopologicalTaskProvider(list));

            var scheduler = SchedulerFactory.Create(provider);

            scheduler.Run();

            Assert.AreEqual(sum.Sum(), TOTAL);
        }
Exemplo n.º 2
0
        public void ComplexCalculation()
        {
            const int NUM   = 100;
            const int TOTAL = (NUM + 1) * NUM / 2;
            const int LINKS = 500;

            var sum = new int[NUM];

            var list = new List <ITopologicalNode>(NUM);

            for (var i = 1; i <= NUM; i++)
            {
                var task = new DemoTask(i, n =>
                {
                    Thread.Sleep(100);
                    sum[n - 1] = n;
                });
                list.Add(task);
            }

            var rnd = new Random();

            for (var i = 0; i < LINKS; i++)
            {
                var to   = rnd.Next(1, NUM);
                var from = rnd.Next(0, to - 1);

                if (list[to].Sources.Contains(list[from]))
                {
                    continue;
                }

                list[to].Sources.Add(list[from]);
            }

            Shuffle(list);

            var provider = default(TopologicalTaskProvider);

            Assert.DoesNotThrow(() => provider = new TopologicalTaskProvider(list));

            var scheduler = SchedulerFactory.Create(provider);

            scheduler.Run();

            Assert.AreEqual(sum.Sum(), TOTAL);
        }
Exemplo n.º 3
0
        public static void RunAsync()
        {
            if (_graph is null)
            {
                return;
            }

            var provider  = new TopologicalTaskProvider(_graph.Nodes);
            var scheduler = SchedulerFactory.Create(provider);

            Instances.ActiveCanvas.Document.DestroyAttributeCache();

            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            scheduler.Run();
            sw.Stop();
            System.Windows.Forms.MessageBox.Show(sw.ElapsedMilliseconds.ToString());

            Instances.ActiveCanvas.Invalidate();
        }