Пример #1
0
        static void CrossRefTree()
        {
            var t  = new DataTree();
            var t2 = new DataTree();
            var t3 = new DataTree();

            t.AddElement(new PNumber(1));
            t.AddElement(new PNumber(2));
            t.AddElement(new PNumber(3));
            t2.AddElement(new PNumber(2));
            t2.AddElement(new PNumber(4));
            t3.AddElement(new PNumber(12));
            t3.AddElement(new PNumber(24));

            DataTree.ConformTrees(new List <DataTree>()
            {
                t, t2, t3
            }, out List <DataTree> output, DataGroupingModes.Primary);


            foreach (var v in output)
            {
                Print(v);
            }
        }
Пример #2
0
        static void TestimNumriElementeve()
        {
            var t = new DataTree();

            t.AddElement(new PNumber(1));

            t.AddElement(new PNumber(2));

            t.AddElement(new PNumber(3));

            Console.WriteLine(t.DataDescription);

            var t2 = new DataTree();

            t2.AddElement(new PNumber(4));
            var temp = new DataTree();

            temp.AddElement(new PNumber(15));
            temp.AddElement(new PNumber(72));
            var temp2 = new PNumber(85);

            temp.AddElement(temp2);
            t2.AddElement(temp);

            t2.AddElement(new PNumber(5));
            t2.AddElement(new PNumber(6));
            t2.AddElement(new PNumber(7));
            t2.AddElement(new PNumber(8));
            t2.AddElement(new PNumber(9));
            Console.WriteLine(t2.DataDescription);
            Console.WriteLine("AfTER CONFORMING  \r\n");
            DataTree.ConformTrees(t, t2, NH_VI.GraphLogic.Operators.DataGroupingModes.CrossReference, out DataTree f1, out DataTree f2);

            Console.WriteLine(f1.DataDescription);
            Console.WriteLine(f2.DataDescription);
            Console.WriteLine("");
            Console.WriteLine("Nr: " + f2.NumberChildEndings());

            var a = f2.GetEmptyTree();

            Console.WriteLine(a.DataDescription);
        }
Пример #3
0
        protected virtual List <IData> GroupData(List <IData> dat)
        {
            if (!TreeOperator)
            {
                if (dat.Count > 1)
                {
                    var b = false;
                    foreach (var d in dat)
                    {
                        if (d is DataTree)
                        {
                            b = true;
                        }
                    }
                    if (b)
                    {
                        var cop = new List <IData>(dat);
                        //foreach (var c in cop)
                        //{
                        //    if (!(c is DataTree)) { var t =  c.Encapsulate(); c = t; }
                        //}
                        for (int i = 0; i < cop.Count; i++)
                        {
                            if (!(cop[i] is DataTree))
                            {
                                cop[i] = cop[i].Encapsulate();
                            }
                        }
                        DataTree.ConformTrees(cop.Cast <DataTree>().ToList(), out List <DataTree> conformedLists, GroupingMode, 0);
                        //DataTree.ConformTrees(cop[0] as DataTree, cop[1] as DataTree,GroupingMode, out DataTree f1, out DataTree f2, 0);
                        //var conformedLists = new List<DataTree>() { f1, f2 };
                        var skeleton = conformedLists[0].GetEmptyTree();

                        List <IEnumerator <IData> > enums = new List <IEnumerator <IData> >();

                        foreach (var v in conformedLists)
                        {
                            enums.Add(v.GetChildIterator().GetEnumerator());
                        }

                        bool test   = true;
                        var  retVal = new List <IData>();
                        for (int i = 0; i < NumberOfOutputs; i++)
                        {
                            retVal.Add(skeleton.Copy());
                        }
                        int counter   = 0;
                        int numchilds = conformedLists[0].NumberChildEndings();
                        for (int j = 0; j < numchilds; j++)
                        {
                            counter++;
                            var        calcList      = new List <IData>();
                            List <int> path          = new List <int>();
                            int        firstTimeOnly = 0;

                            foreach (var en in enums)
                            {
                                test = en.MoveNext();
                                var cur = en.Current;
                                if (firstTimeOnly == 0)
                                {
                                    path = cur.Path.ToList();
                                    firstTimeOnly++;
                                }
                                calcList.Add(en.Current);
                            }
                            var temp = OperateSimple(calcList);

                            int i = 0;
                            foreach (var op in temp)
                            {
                                var newPath = new List <int>(path);
                                path.RemoveAt(path.Count - 1);
                                var d = (retVal[i] as DataTree).GetByPath(path.ToArray());
                                op.AddTo(d as DataTree);
                                i++;
                            }
                        }

                        return(retVal);
                    }
                    else
                    {
                        return(OperateSimple(dat));
                    }
                    //DataTree.ConformTrees(dat.Cast(typeof(DataTree)), GroupingMode, out List<DataTree> tr, 0);
                }
                else
                {
                    return(OperateSimple(dat));
                }
            }
            else
            {
                return(OperateSimple(dat));
            }
        }