コード例 #1
0
        private SkyscraperNxNDataLists ReduceLists(SkyscraperNxNDataLists dataLists, out SkyscraperData_Perms data)
        {
            data = null;
            PerformListReduction(dataLists);
            int shortest;

            if (!CheckListsAndFindShortest(dataLists, out shortest))
            {
                return(null);
            }
            if (shortest == -1)
            {
                TryPopulateResultsData(dataLists, out data);
                return(dataLists);
            }
            for (int i = 0; i < dataLists.Lists[shortest].Idx.Count; i++)
            {
                SkyscraperNxNDataLists next = new SkyscraperNxNDataLists(dataLists);
                next.Lists[shortest].Idx = new List <int>()
                {
                    dataLists.Lists[shortest].Idx[i]
                };
                ReduceListsSingleItemOnList(next, shortest);
                SkyscraperNxNDataLists nextres = ReduceLists(next, out data);
                if ((nextres != null) && TryPopulateResultsData(nextres, out data))
                {
                    return(nextres);
                }
            }
            return(null);
        }
コード例 #2
0
        private bool TryPopulateResultsData(SkyscraperNxNDataLists dataLists, out SkyscraperData_Perms data)
        {
            data = null;
            SkyscraperData_Perms tdata = new SkyscraperData_Perms(_n);

            if (PopulateResultsData(dataLists, tdata))
            {
                data = tdata;
                return(true);
            }
            return(false);
        }
コード例 #3
0
        private bool PopulateResultsData(SkyscraperNxNDataLists dataLists, SkyscraperData_Perms data)
        {
            //ustawienie elementow ze zredukowanych list
            for (int i = 0; i < dataLists.Lists.Length; i++)
            {
                if (dataLists.Lists[i] != null)
                {
                    for (int j = 0; j < _n; j++)
                    {
                        data.SetSingleElement(GetDataRowCol(i, j), dataLists.Lists[i].PrecalcData[dataLists.Lists[i].Idx[0]][j]);
                    }
                }
            }

            //lista nieustawionych elementow
            List <Tuple <int, int> > notSet = new List <Tuple <int, int> >();

            for (int row = 0; row < _n; row++)
            {
                for (int col = 0; col < _n; col++)
                {
                    if (data.Data[row, col] == 0)
                    {
                        notSet.Add(new Tuple <int, int>(row, col));
                    }
                }
            }

            //ustawienie brakujacych elementow
            while (notSet.Count > 0)
            {
                int savedcnt = notSet.Count;
                int p        = 0;
                while (p < notSet.Count)
                {
                    int x = (data.SetInRow[notSet[p].Item1] | data.SetInCol[notSet[p].Item2]) ^ SkyscraperData_Perms.InitialValues[_n];
                    if (data.CountBits(x) == 1)
                    {
                        data.SetSingleElementMask(notSet[p].Item1, notSet[p].Item2, x);
                        notSet.RemoveAt(p);
                    }
                    else
                    {
                        p++;
                    }
                }
                if ((notSet.Count > 0) && (savedcnt == notSet.Count))
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #4
0
 private int[][] ConvertToResultTable(SkyscraperData_Perms data)
 {
     int[][] res = new int[_n][];
     for (int i = 0; i < _n; i++)
     {
         res[i] = new int[_n];
         for (int j = 0; j < _n; j++)
         {
             res[i][j] = Array.IndexOf(SkyscraperData_Perms.Masks, data.Data[i, j]);
         }
     }
     return(res);
 }