コード例 #1
0
 public void BPSet(Bit324 sdX)
 {
     for (int k = 0; k < sz; k++)
     {
         _BP[k] |= sdX._BP[k];
     }
 }
コード例 #2
0
 public Bit324(Bit324 P) : this()
 {
     for (int k = 0; k < sz; k++)
     {
         this._BP[k] = P._BP[k];
     }
 }
コード例 #3
0
        static public Bit324 operator-(Bit324 A, Bit324 B)
        {
            Bit324 C = new Bit324();

            for (int k = 0; k < sz; k++)
            {
                C._BP[k] = A._BP[k] & (B._BP[k] ^ 0xFFFFFFFF);
            }
            return(C);
        }
コード例 #4
0
        static public Bit324 operator|(Bit324 A, Bit324 B)
        {
            Bit324 C = new Bit324();

            for (int k = 0; k < sz; k++)
            {
                C._BP[k] = A._BP[k] | B._BP[k];
            }
            return(C);
        }
コード例 #5
0
 public bool IsHit(Bit324 sdk)
 {
     for (int k = 0; k < sz; k++)
     {
         if ((_BP[k] & sdk._BP[k]) > 0)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #6
0
 public uint CompareTo(Bit324 B)
 {
     for (int k = 0; k < sz; k++)
     {
         if (this._BP[k] == B._BP[k])
         {
             return(this._BP[k] - B._BP[k]);
         }
     }
     return(this._BP[sz - 1] - B._BP[sz - 1]);
 }
コード例 #7
0
        public override bool Equals(object obj)
        {
            Bit324 A = obj as Bit324;

            if (A == null)
            {
                return(false);
            }
            for (int k = 0; k < sz; k++)
            {
                if (A._BP[k] != _BP[k])
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #8
0
        public Bit324(UGLink UGL)
        {
            Bit324 B = new Bit324();

            if (UGL.rcBit81 is Bit81)
            {
                int no81 = UGL.rcBit81.no * 81;
                foreach (int k in UGL.rcBit81.IEGet_rc())
                {
                    B.BPSet(no81 + k);
                }
            }
            else
            {
                UCell uc = UGL.UC as UCell;
                foreach (var no in uc.FreeB.IEGet_BtoNo())
                {
                    B.BPSet(no * 81 + uc.rc);
                }
            }
        }
コード例 #9
0
 public Bit324 Copy()
 {
     Bit324 Scpy = new Bit324(); Scpy.BPSet(this); return(Scpy);
 }
コード例 #10
0
        public IEnumerable <UBasCov> IEGet_BaseSet(int sz, int rnk)
        {
            if (UGLLst == null)
            {
                yield break;
            }

            __checkCC = 0;

            List <UGLink> basUGLs   = new List <UGLink>();
            Bit981        HB981     = new Bit981();     //BaseSet bitPattern
            Bit324        usedLK    = new Bit324();     //usedLink(by serial number)
            List <int>    usedLKLst = new List <int>();

            Bit81Chk coverChk = new Bit81Chk(sz, rnk, basUGLs, usedLKLst, usedLKIgnrLst);

            var  cmbBas = new Combination(UGLLst.Count, sz);
            long rcbn36 = 0;

            int jkC = 0;
            int nxt = int.MaxValue;   //(skip function)

            while (cmbBas.Successor(nxt))
            {
                GeneralLogicGen.ChkBas1++;                       //*****

                jkC++;
                //*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==* sz=1
                if (sz == 1)
                {
                    UGLink UGL = UGLLst[cmbBas.Index[0]];
                    if (UGL.UC is UCell)
                    {
                        goto LNextSet;                   // if size=1, cell-type is invalid
                    }
                    // UGL.rcBit81 is Bit81
                    int blkB = (int)UGL.Get_rcbnFrame(2);
                    if (blkB.BitCount() > 1)
                    {
                        goto LNextSet;
                    }

                    int no = UGL.rcBit81.no, b = blkB.BitToNum();
                    var P = UGLLst.Find(U => U.Equal_no_block(no, b));
                    if (P == null)
                    {
                        goto LNextSet;
                    }
                    if ((P.rcBit81 - UGL.rcBit81).Count == 0)
                    {
                        goto LNextSet;
                    }

                    //there are numbers only within one block
                    HB981.Clear();    HB981.BPSet(UGL.rcBit81.no, UGL.rcBit81, tfbSet: false);
                    basUGLs.Clear();  basUGLs.Add(UGL);
                    GeneralLogicGen.ChkBas2++; //*****
                    goto LBSFound;             //possibility of solution
                }

                //*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==* sz>=2
                HB981.Clear();
                basUGLs.Clear();
                usedLKLst.Clear();
                coverChk.Clear();
                rcbn36 = 0;

                //1..4....8.9.1...5.....63.....13.5.79..3...8..76.2.94.....75.....1...6.4.8....4..2

                for (int k = 0; k < sz; k++)
                {
                    nxt = k;
                    UGLink UGL = UGLLst[cmbBas.Index[k]];
                    rcbn36 |= UGL.rcbnFrame2;

                    if (!Check_rcbnCondition(sz, rnk, k, rcbn36))
                    {
                        goto LNextSet;            //# Extremely efficient
                    }
                    if (UGL.rcBit81 is Bit81)     // ............ rcb ............
                    {
                        if (k > 0 && HB981.IsHit(UGL.rcBit81.no, UGL.rcBit81))
                        {
                            goto LNextSet;                                      //included in BaseSet
                        }
                        HB981.BPSet(UGL.rcBit81.no, UGL.rcBit81, tfbSet: true); //register to BaseSet
                        usedLKLst.Add(UGL.rcBit81.ID);                          //tfx<<4 | no
                        int no = UGL.rcBit81.no;
                        coverChk.noB |= 1 << no;                                //qq
                    }
                    else                                                        // ........... Cell ............
                    {
                        UCell UC = UGL.UC;
                        int   rc = UC.rc;
                        foreach (var n in UC.FreeB.IEGet_BtoNo(9))
                        {
                            if (k > 0 && HB981.IsHit(n, rc))
                            {
                                goto LNextSet;
                            }
                            HB981.BPSet(n, rc, tfbSet: true);
                        }
                        int IDrc = rc << 17 | 1 << 16;
                        usedLKLst.Add(IDrc);                         //tfx<<4 | no
                    }
                    basUGLs.Add(UGL);                                //qq
                }
                GeneralLogicGen.ChkBas2++;                           //*****

                bool niceB = coverChk.Check_BaseSetCondition(HB981); //########## check_rcB9 ##########
                if (!niceB)
                {
                    goto LNextSet;
                }

                //1..4....8.9.1...5.....63.....13.5.79..3...8..76.2.94.....75.....1...6.4.8....4..2
                if (sz >= 2)
                {
                    int noBP = HB981.nzBit;
                    int noCC = noBP.BitCount();
                    if (noCC >= 2)
                    {
                        List <int> IX = noBP.IEGet_BtoNo().ToList();

                        if (sz >= 2)
                        {
                            for (int k = 0; k < noCC; k++)
                            {
                                Bit81 A = new Bit81(), B = new Bit81();
                                int   no = IX[k];
                                foreach (var P in basUGLs)
                                {
                                    if (P.rcBit81 is Bit81)
                                    {
                                        if (P.rcBit81.no == no)
                                        {
                                            A |= P.rcBit81;
                                        }
                                        else
                                        {
                                            B |= P.rcBit81;
                                        }
                                    }
                                    else
                                    {
                                        int rc = P.UC.rc;
                                        foreach (var n in P.UC.FreeB.IEGet_BtoNo())
                                        {
                                            if (n == no)
                                            {
                                                A.BPSet(rc);
                                            }
                                            else
                                            {
                                                B.BPSet(rc);
                                            }
                                        }
                                    }
                                }

                                int nOL = (B & A).Count;
                                if (rnk == 0 && nOL < 2)
                                {
                                    goto LNextSet;
                                }
                                if (rnk > 0 && nOL < 1)
                                {
                                    goto LNextSet;
                                }
                                //    WriteLine("---------- no:{0} sz:{1} rnk:{2} nOL:{3} (A-B):{4} (B-A):{5}", no, sz,rnk, nOL, (A-B).Count, (B-A).Count );
                            }
                            //1..4....8.9.1...5.....63.....13.5.79..3...8..76.2.94.....75.....1...6.4.8....4..2
                        }
                    }
                }

                //---------------------------------------------------------------------------------------
LBSFound:
                if (SDK_Ctrl.UGPMan.stageNo == 12 && sz >= 3)// && rnk==1 ){
                {
                    WriteLine("\r sz:{0} rnk:{1} jkc:{2}", sz, rnk, jkC);
                    Check_rcbnCondition(sz, rnk, sz, rcbn36, printB: true);
                    basUGLs.ForEach(P => WriteLine(P.ToString("BaseSet")));
                }

                usedLK.Clear();
                basUGLs.ForEach(P => usedLK.BPSet(P.SrNum)); //IDrc: rc<<17 | 1<<16
                UBasCov UBC = new UBasCov(basUGLs, HB981, sz, usedLK);
                yield return(UBC);

LNextSet:
                continue;
            }
            yield break;
        }
コード例 #11
0
 public UBasCov(List <UGLink> basUGLs, Bit981 HB981, int sz, Bit324 usedLK)
 {
     this.basUGLs = basUGLs; this.HB981 = HB981; this.sz = sz; this.usedLK = usedLK;
 }
コード例 #12
0
        //1..4....8.9.1...5.....63.....13.5.79..3...8..76.2.94.....75.....1...6.4.8....4..2
        public IEnumerable <UBasCov> IEGet_CoverSet(UBasCov UBC, int rnk)
        {
            if (UGLLst == null)
            {
                yield break;
            }

            List <UGLink> basUGLs = UBC.basUGLs;
            Bit981        HB981   = UBC.HB981;
            Bit324        usedLK  = UBC.usedLK;
            int           nzBit   = HB981.nzBit;
            int           nzBitCC = nzBit.BitCount();
            int           sz      = UBC.sz;

            List <UGLink> UGLCovLst = new List <UGLink>();  // UGLCovLst:candidate link

            #region Create UGLCovLst
            Bit81 Bcmp = HB981.CompressToHitCells();
            foreach (var P in UGLLst.Where(q => !usedLK.IsHit(q.SrNum)))
            {
                if (P.rcBit81 is Bit81) //Row, column, block link
                {
                    if ((nzBit & (1 << P.rcBit81.no)) == 0)
                    {
                        continue;
                    }
                    int B = (HB981._BQ[P.rcBit81.no] & P.rcBit81).BitCount();
                    if (B == 0)
                    {
                        continue;
                    }

                    // if rank:0, the CoverSet has two or more common items
                    if (rnk == 0 && (HB981._BQ[P.rcBit81.no] & P.rcBit81).Count < 2)
                    {
                        continue;
                    }
                    UGLCovLst.Add(P);
                }
                else    //Cell
                {
                    if (nzBitCC <= 1)
                    {
                        continue;
                    }
                    if ((nzBit & P.UC.FreeB) == 0)
                    {
                        continue;
                    }
                    int B = nzBit & P.UC.FreeB;
                    if (B == 0)
                    {
                        continue;
                    }
                    int rc = P.UC.rc;

                    int kcc = 0, kccLim = (rnk == 0)? 2:1;
                    foreach (var no in B.IEGet_BtoNo())
                    {
                        if (!HB981._BQ[no].IsHit(rc))
                        {
                            continue;
                        }
                        if (++kcc >= kccLim)
                        {
                            UGLCovLst.Add(P); break;
                        }
                    }
                }
            }
            #endregion
            if (UGLCovLst.Count < sz + rnk)
            {
                yield break;
            }
            Bit981      HC981  = new Bit981();
            Bit981      HLapB  = new Bit981();
            Bit981      Can981 = new Bit981();
            Combination cmbCvr = new Combination(UGLCovLst.Count, sz + rnk);
            int         nxt    = int.MaxValue;
            while (cmbCvr.Successor(nxt))
            {
                ++GeneralLogicGen.ChkCov1;

                HC981.Clear();
                Array.ForEach(cmbCvr.Index, m => HC981 |= UGLCovLst[m].rcbn2);

                if (!(HB981 - HC981).IsZero())
                {
                    goto LNextSet;                              //BaseSet is covered?
                }
                Bit981 CsubB = HC981 - HB981;
                if (CsubB.IsZero())
                {
                    goto LNextSet;                              //excludable candidates is exist?
                }
                List <UGLink> covUGLs = new List <UGLink>();
                Array.ForEach(cmbCvr.Index, m => covUGLs.Add(UGLCovLst[m]));

                if (rnk == 0)
                {
                    Can981 = CsubB;
                }
                else    //if(rnk>0){
                {
                    bool SolFound = false;
                    foreach (int n in CsubB.nzBit.IEGet_BtoNo())
                    {
                        foreach (int rc in CsubB._BQ[n].IEGetRC())
                        {
                            int kc = covUGLs.Count(Q => Q.IsHit(n, rc));
                            if (kc == rnk + 1)
                            {
                                Can981.BPSet(n, rc);
                                SolFound = true;
                            }
                        }
                    }
                    if (!SolFound)
                    {
                        continue;
                    }
                }
                ++GeneralLogicGen.ChkCov2;                       //*****

                UBC.addCoverSet(covUGLs, HC981, Can981, rnk);
                yield return(UBC);

LNextSet:
                continue;
            }
            yield break;
        }