Ejemplo n.º 1
0
        public void UnsubcribeConnectorSingleInputManyOutput()
        {
            var board = new RelayBoard();

            var i1 = new RelayInputMock("I1");
            var o1 = new RelayOutputMock("O1");
            var o2 = new RelayOutputMock("O2");

            var c1 = board.Connect(i1, o1);

            c1.Subscribe(p => { });
            var c2 = board.Connect(i1, o2);

            c2.Subscribe(p => { });

            board.Initialize();
            Console.WriteLine(board.Report());

            o1.Check(false);
            o2.Check(false);

            i1.Notify();
            o1.Check(true);
            o2.Check(true);

            o1.Reset();
            o2.Reset();
            o1.Check(false);
            o2.Check(false);

            c2.Dispose();
            Console.WriteLine(board.Report());

            i1.Notify();
            o1.Check(true);
            o2.Check(false);

            board.Dispose();
        }
Ejemplo n.º 2
0
        public void Benchmark(int nbInputs, int nbOutputs, double percentOfObyI)
        {
            var random = new Random(42);

            var inputs = new RelayInputMock[nbInputs];

            for (var i = 0; i < inputs.Length; i++)
            {
                inputs[i] = new RelayInputMock("Feed" + (i + 1));
            }

            var outputs = new RelayOutputMock[nbOutputs];

            for (var i = 0; i < outputs.Length; i++)
            {
                outputs[i] = new RelayOutputMock("S" + (i + 1));
            }

            var manager = new RelayBoard();

            for (var i = 0; i < inputs.Length; i++)
            {
                var list = new List <string>();
                for (var j = 0; j < outputs.Length; j++)
                {
                    if (random.NextDouble() <= percentOfObyI)
                    {
                        manager.Connect(inputs[i], outputs[j]);
                        list.Add(outputs[j].Name);
                    }
                }
            }

            manager.Initialize();
            Console.WriteLine(manager.Report());

            var iterations     = 1500;
            var percentOfNotif = 0.77;

            var stack = new Stack <string>();

            var randoms = new double[iterations * inputs.Length];

            for (var i = 0; i < iterations; i++)
            {
                randoms[i] = random.NextDouble();
            }

            var jitterIterations = (int)(iterations * 0.1);

            for (int i = 0, k = 0; i < jitterIterations; i++)
            {
                for (var j = 0; j < inputs.Length; j++)
                {
                    if (randoms[k++] <= percentOfNotif)
                    {
                        inputs[j].Notify();
                        stack.Push(inputs[j].Name);
                    }
                }

                for (var j = 0; j < outputs.Length; j++)
                {
                    if (outputs[j].IsInvalidated)
                    {
                        outputs[j].Reset();
                    }
                }
            }

            var sw = Stopwatch.StartNew();

            for (int i = 0, k = 0; i < iterations; i++)
            {
                for (var j = 0; j < inputs.Length; j++)
                {
                    if (randoms[k++] <= percentOfNotif)
                    {
                        inputs[j].Notify();
                        stack.Push(inputs[j].Name);
                    }
                }

                for (var j = 0; j < outputs.Length; j++)
                {
                    if (outputs[j].IsInvalidated)
                    {
                        outputs[j].Reset();
                    }
                }
            }
            sw.Stop();
            Console.WriteLine("Elapsed: {0} ms", sw.Elapsed.TotalMilliseconds);
        }
Ejemplo n.º 3
0
        public void RandomSetup(int nbInputs, int nbOutputs, double percentOfObyI)
        {
            var random = new Random(42);

            var inputs = new RelayInputMock[nbInputs];

            for (var i = 0; i < inputs.Length; i++)
            {
                inputs[i] = new RelayInputMock("Feed" + (i + 1));
            }

            var outputs = new RelayOutputMock[nbOutputs];

            for (var i = 0; i < outputs.Length; i++)
            {
                outputs[i] = new RelayOutputMock("S" + (i + 1));
            }

            var dependencies = new Dictionary <string, List <string> >();
            var manager      = new RelayBoard();

            for (var i = 0; i < inputs.Length; i++)
            {
                var list = new List <string>();
                dependencies[inputs[i].Name] = list;
                for (var j = 0; j < outputs.Length; j++)
                {
                    if (random.NextDouble() <= percentOfObyI)
                    {
                        manager.Connect(inputs[i], outputs[j]);
                        list.Add(outputs[j].Name);
                    }
                }
            }

            manager.Initialize();
            Console.WriteLine(manager.Report());

            var now            = DateTime.Now;
            var iterations     = 150;
            var percentOfNotif = 0.77;
            var outByName      = outputs.ToDictionary(p => p.Name, p => p);

            var hash       = new HashSet <string>();
            var stack      = new Stack <string>();
            var timestamps = outputs.ToDictionary(p => p.Name, p => DateTime.MinValue);

            for (var i = 0; i < iterations; i++)
            {
                now = now.AddSeconds(i);
                for (var j = 0; j < inputs.Length; j++)
                {
                    if (random.NextDouble() <= percentOfNotif)
                    {
                        inputs[j].Notify();
                        stack.Push(inputs[j].Name);
                    }
                }

                while (stack.Count > 0)
                {
                    var deps = dependencies[stack.Pop()];
                    foreach (var dep in deps)
                    {
                        if (hash.Contains(dep))
                        {
                            continue;
                        }
                        outByName[dep].Check(true);
                        timestamps[dep] = now;
                        hash.Add(dep);
                    }
                }

                for (var j = 0; j < outputs.Length; j++)
                {
                    if (!hash.Contains(outputs[i].Name))
                    {
                        outputs[i].Check(false);
                    }
                    outputs[j].Reset();
                }

                hash.Clear();
            }
        }