Exemplo n.º 1
0
        static void Test()
        {
            //Calculate x+y
            var summ = new Summator();
            var summ2 = new Summator();
            var summ3 = new Summator();
            var str = new Stringer();

            var one = new InPoint(new IntColor(1));
            var one2 = new OutPoint(new IntColor(1));
            var two = new InPoint(new IntColor(2));
            var three = new OutPoint(new IntColor(3));
            var four = new OutPoint(new IntColor(5));
            var mix1 = new MixNode();

            one.ConnectTo(summ);
            two.ConnectTo(summ);

            one2.ConnectTo(summ).ConnectTo(summ2);
            three.ConnectTo(summ2).ConnectTo(str);

            four.ConnectTo(summ2);
            summ.ConnectTo(summ3);
            summ2.ConnectTo(summ3);
            summ3.ConnectTo(str);
            new OutPoint(new IntColor(6)).ConnectTo(str);
            //str.ConnectTo(mix1);
            // new OutPoint(new StringColor("abba")).ConnectTo(mix1);/**/
            // graph.Add(new ColorableClass[] { one, two, one2, three });
            graph.Add(new ConnectionPoint[] { one, two, one2, three, four });
            graph.OnFinish += OnFinish;
            graph.StartAsync();
        }
Exemplo n.º 2
0
        static int Sum(int x, int y)
        {
            var xNode = new InPoint(new IntColor(x));
            var yNode = new InPoint(new IntColor(y));
            int res = 0;
            var summator = new Summator();

            //connect x and y to summato
            xNode.ConnectTo(summator);
            yNode.ConnectTo(summator);

            //both x and y will recieve the same result in this text, so add just one of them
            graph.Add(xNode);
            graph.OnFinish += delegate(GraphResult result)
                {
                    GraphPath path = result[xNode];
                    if (path != null)
                    {
                        var color = path.LastColor as IntColor;
                        if (color != null)
                            res = color.Value;
                        //sum is list of transitions of first value — result is the last one.

                    }

                };

            graph.Start();
            return res;
        }