Ejemplo n.º 1
0
        private bool IsValidTangleOld(Tangle t)
        {
            int        t_hash     = t.Hash();
            List <int> firstSet   = new List <int>();
            int        indexFirst = this.GaussCode.IndexOf(t.Crosses[0]);

            firstSet.Add(this.GaussCode[indexFirst]);
            bool expandSx = true;
            bool expandDx = true;
            int  expand   = 1;
            int  index    = 0;

            while (expandSx || expandDx)
            {
                if (expandSx)
                {
                    index = Tools.Mod((indexFirst - expand), this.GaussCode.Count);
                    if (t.Crosses.Contains(Math.Abs(this.GaussCode[index])) && !firstSet.Contains(Math.Abs(this.GaussCode[index])))
                    {
                        firstSet.Add(this.GaussCode[index]);
                    }
                    else
                    {
                        expandSx = false;
                    }
                }
                if (expandDx)
                {
                    index = Tools.Mod((indexFirst + expand), this.GaussCode.Count);
                    if (t.Crosses.Contains(Math.Abs(this.GaussCode[index])) && !firstSet.Contains(Math.Abs(this.GaussCode[index])))
                    {
                        firstSet.Add(this.GaussCode[index]);
                    }
                    else
                    {
                        expandDx = false;
                    }
                }
                expand++;
            }

            Tangle firstT        = new Tangle(firstSet.ToArray());
            int    firstT_hash   = firstT.Hash();
            int    sizeSecondSet = t.nCrosses * 2 - firstSet.Count;

            int[] secondSet = new int[sizeSecondSet];
            for (int i = 0; i < this.GaussCode.Count; i++)
            {
                for (int j = 0; j < sizeSecondSet; j++)
                {
                    secondSet[j] = this.GaussCode[Tools.Mod(i + j, this.GaussCode.Count)];
                }

                Tangle secondT      = new Tangle(secondSet);
                int    secondT_hash = secondT.Hash();
                if (firstT != secondT && firstT_hash == secondT_hash)
                {
                    bool contain = true;
                    foreach (int n in secondSet)
                    {
                        contain &= t.Crosses.Contains(Math.Abs(n));
                    }

                    if (contain)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        private int[] getPositionsForReductionMove2()
        {
            int sign(int a)
            {
                if (a >= 0)
                {
                    return(1);
                }
                return(-1);
            }

            List <int[]> adj = new List <int[]>();

            List <int> temp = new List <int>();

            for (int i = 0; i < this.GaussCode.Count; i++)
            {
                temp = new List <int>();

                for (int j = i; j < this.GaussCode.Count; j++)
                {
                    if (sign(this.GaussCode[j]) == sign(this.GaussCode[j + 1]))
                    {
                        temp.Add(this.GaussCode[j]);
                        temp.Add(this.GaussCode[j + 1]);
                        int[] add = temp.Distinct().ToArray();
                        adj.Add(add);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            adj = adj.OrderByDescending(a => a.Length).ToList();

            foreach (int[] t in adj)
            {
                Tangle test       = new Tangle(t);
                int    firstIndex = this.GaussCode.IndexOf(-t[0]);
                int    tempFirst  = firstIndex;
                int[]  found      = new int[t.Length];
                bool   dx         = true;
                for (int i = 0; i < t.Length; i++)
                {
                    if (dx)
                    {
                        if (t.Contains(-this.GaussCode[firstIndex]))
                        {
                            found[i] = -this.GaussCode[firstIndex];
                            firstIndex++;
                        }
                        else
                        {
                            dx = false;
                            i--;
                        }
                    }
                    else
                    {
                        firstIndex = tempFirst - 1;
                        if (t.Contains(-this.GaussCode[firstIndex]))
                        {
                            found[i] = -this.GaussCode[firstIndex];
                            firstIndex--;
                        }
                    }
                }

                Tangle TFound = new Tangle(found);

                if (test.Hash() == TFound.Hash())
                {
                    return(t);
                }
            }

            return(null);
        }