예제 #1
0
        private bool GetMinRowCol_Rows(SkyscraperData d, out int row, out int col)
        {
            row = -1;
            col = -1;

            int currminbits = _n + 1;
            int setbits     = 0;

            for (int i = 0; i < _n; i++)
            {
                int setbitsinrow = d.CountBits(d.SetInRow[i]);
                for (int j = 0; j < d.Rows[i].Count; j++)
                {
                    int bits = d.CountBits(i, d.Rows[i][j]);
                    if ((bits < currminbits) ||
                        ((bits == currminbits) && (setbitsinrow < setbits))) //w wierszu najmniej ustawionych bitow
                    {
                        row         = i;
                        col         = d.Rows[i][j];
                        currminbits = bits;
                        setbits     = setbitsinrow;
                    }
                }
            }
            return(currminbits != _n + 1);
        }
예제 #2
0
        private bool GetMinRowCol_Default(SkyscraperData d, out int row, out int col)
        {
            row = -1;
            col = -1;

            int currminbits = _n + 1;
            int setbits     = 0;

            for (int i = 0; i < _n; i++)
            {
                if (d.SetInRow[i] != SkyscraperData.InitialValues[_n])
                {
                    int setbitsinrow = d.CountBits(d.SetInRow[i]);
                    for (int j = 0; j < _n; j++)
                    {
                        int bits = d.CountBits(i, j);
                        if (bits > 1)
                        {
                            if ((bits < currminbits) ||
                                ((bits == currminbits) && (setbitsinrow < setbits))) //w wierszu najmniej ustawionych bitow
                            {
                                row         = i;
                                col         = j;
                                currminbits = bits;
                                setbits     = d.SetInRow[i];
                            }
                        }
                    }
                }
            }
            return(currminbits != _n + 1);
        }
 private bool CheckDataUniqueElements(SkyscraperData d)
 {
     for (int i = 0; i < _n; i++)
     {
         int mask = 0, mask2 = 0;
         int cnt = 0, cnt2 = 0;
         for (int j = 0; j < _n; j++)
         {
             if (d.CountBits(i, j) == 1)
             {
                 mask ^= d.Data[i, j];
                 cnt++;
             }
             if (d.CountBits(j, i) == 1)
             {
                 mask2 ^= d.Data[j, i];
                 cnt2++;
             }
         }
         if ((d.CountBits(mask) != cnt) || (d.CountBits(mask2) != cnt2))
         {
             return(false);
         }
     }
     return(true);
 }
예제 #4
0
        private bool TrySetSingleElement(SkyscraperData d, int row, int col, int mask)
        {
            int v = (mask ^ -1) & (d.Data[row, col] & ((d.SetInRow[row] | d.SetInCol[col]) ^ -1));  //zostaja jedynki tam gdzie w masce sa 0, dodatkowo wylaczone juz ustawione bity

            if (d.CountBits(v) == 1)
            {
                d.SetSingleElementMask(row, col, v);
                if (!ReduceRowCol(d, row, col))
                {
                    return(false);
                }
                return(true);
            }
            return(false);
        }
예제 #5
0
 private bool TryReduceSingleElement(SkyscraperData d, int row, int col, int mask, out bool singleset)
 {
     singleset = false;
     //if (d.CountBits(row, col) > 1)
     {
         d.RemoveElementMask(row, col, mask);
         if (d.CountBits(row, col) == 1)
         {
             if (((d.Data[row, col] & d.SetInRow[row]) != 0) || ((d.Data[row, col] & d.SetInCol[col]) != 0))
             {
                 SkyscrapersCounters.ReduceRCDoublesCut++;
                 return(false);
             }
             d.SetSingleElementMask(row, col, d.Data[row, col]);
             if (!ReduceRowCol(d, row, col))
             {
                 return(false);
             }
             singleset = true;
         }
     }
     return(true);
 }
예제 #6
0
        public void ApplyConstraints(SkyscraperData d, int[] constraints)
        {
            //ograniczenia od lewej do prawej po N rzedow
            //po przejsciu N rzedow obrot tablicy w prawo i analiza kolejnych rzedow
            for (int i = constraints.Length - 1; i >= 0; i--)
            {
                if (constraints[i] > 0)
                {
                    int row = _n - 1 - i % _n;
                    if (constraints[i] == _n)
                    {
                        for (int k = 0; k < _n; k++)
                        {
                            d.Data[row, k] = SkyscraperData.Masks[k + 1];
                        }
                    }
                    else if (constraints[i] == 1)
                    {
                        d.Data[row, 0] = SkyscraperData.Masks[_n];
                    }
                    else
                    {
                        for (int el = _n; el > 1; el--)
                        {
                            for (int k = 0; k < constraints[i] - 1 - (_n - el); k++)
                            {
                                d.RemoveElement(row, k, el);
                            }
                        }
                    }
                }
                if (i % _n == 0)
                {
                    d.RotateRight();
                }
            }
            //po nalozeniu ograniczen wygenerowanie list indeksow pozycji nie jednobitowych
            for (int i = 0; i < _n; i++)
            {
                for (int j = 0; j < _n; j++)
                {
                    if (d.CountBits(i, j) > 1)
                    {
                        d.Rows[i].Add(j);
                        d.Cols[j].Add(i);
                    }
                }
            }

            //po nalozeniu ograniczen uwzglednienie wszystkich powstalych pozycji jednoelementowych (redukcja w wierszach i kolumnach)
            List <Tuple <int, int> > proc = new List <Tuple <int, int> >();

            for (int i = 0; i < _n; i++)
            {
                for (int j = 0; j < _n; j++)
                {
                    if (d.CountBits(i, j) == 1)
                    {
                        d.SetSingleElementMask(i, j, d.Data[i, j]);
                        proc.Add(new Tuple <int, int>(i, j));
                    }
                }
            }
            _dataReductor.ReduceData(d, proc);
        }