public Bit981(UGLink UGL) : this() { Bit981 B = new Bit981(); if (UGL.rcBit81 is Bit81) { int no = UGL.rcBit81.no; B._BQ[no] = UGL.rcBit81; foreach (int rc in UGL.rcBit81.IEGet_rc()) { B._BQ[no].BPSet(rc); } if (!UGL.rcBit81.IsZero()) { nzBit |= (1 << no); } } else { UCell uc = UGL.UC as UCell; foreach (var n in uc.FreeB.IEGet_BtoNo()) { B._BQ[n].BPSet(uc.rc); nzBit |= (1 << n); } } }
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); } } }
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; }
public bool Check_BaseSetCondition(Bit981 HB981) //for sz>=2 { bool niceB = false, E = false; jkC++; #region There is a link between the link and the other link group for (int k = 0; k < sz; k++) { UGLink UGL = basUGLs[k]; Bit981 Bcum = new Bit981(); for (int m = 0; m < sz; m++) { if (m == k) { continue; } Bcum |= basUGLs[m].rcbn2; } if ((Bcum & UGL.rcbn_conn2).Count <= 0) { goto Lreturn; //false } } #endregion GeneralLogicGen.ChkBas3++; //***** #region Every element of the number(#no) has a link //それぞれのリンクは、その他のリンク群と連結する。 //リンクしないセルはrnk個数以下でなければならない。 //if(E) for(int n=0; n<9; n++ ) WriteLine(HB981.tfx27Lst[n].ToBitString(27)); Bit981 Q9 = HB981.Copy(); usedLKLst.ForEach(p => HB981.tfxReset(p & 0xF, p >> 4)); usedLKIgnrLst.ForEach(p => HB981.tfxReset(p & 0xF, p >> 4)); //if(E) for(int n=0; n<9; n++ ) WriteLine(HB981.tfx27Lst[n].ToBitString(27)); int QPP = 0; foreach (var no in noB.IEGet_BtoNo()) { Bit81 Q = Q9._BQ[no];//new Bit81(HB981._BQ[no]); //if(E) WriteLine( "HB981.tfxLst[no]: "+HB981.tfx27Lst[no].ToBitString(27) ); foreach (var tfx in HB981.tfx27Lst[no].IEGet_tfb()) { int bp = HB981.GetBitPattern_tfnx(no, tfx); if (bp <= 0) { continue; } int nc = bp.BitCount(); if (nc >= 2) { if (E) { WriteLine("Q: " + Q.ToString()); } foreach (var nx in bp.IEGet_BtoNo()) { int rc = tfx.Get_tfx_rc(nx); Q.BPReset(rc); } //if(E) WriteLine("Q: "+Q.ToString() ); } } QPP += Q.Count; } if (QPP <= rnk) { niceB = true; goto Lreturn; } #endregion GeneralLogicGen.ChkBas3++; //***** #region There is a possibility link between the patterns of numbers n1,n2 //数字間のリンクしないセルは、rnk*2以下でなければならない。 if (HB981.nzBit.BitCount() >= 2) { bool firstB = true; Bit81 Q = null; foreach (var n in HB981.nzBit.IEGet_BtoNo()) { if (firstB) { Q = HB981._BQ[n]; firstB = false; } else { Q |= HB981._BQ[n]; } } foreach (var rc in Q.IEGetRC()) { if (HB981.GetBitPattern_rcN(rc).BitCount() >= 2) //セルrcの数字間リンクがあるときは、Q9リセット { foreach (var no in noB.IEGet_BtoNo()) { Q9._BQ[no].BPReset(rc); } } } int Q9cc = Q9.BitCount(); if (Q9cc <= rnk) { niceB = true; goto Lreturn; } //直接リンクしないセルがrnk以下のときは、次のテストに進む if (Q9cc <= rnk * 2) { GeneralLogicGen.ChkBas1B++; //***** foreach (var n1 in Q9.nzBit.IEGet_BtoNo()) { foreach (var rc in Q9._BQ[n1].IEGetRC()) { foreach (var n2 in Q9.nzBit.IEGet_BtoNo().Where(nx => nx != n1)) { if ((Q9._BQ[n2] & p_connectedCells[rc]).BitCount() == 0) { continue; } //リンクしないセル間を繋ぐリンクがある(”可能性あり”で次のテストに進む GeneralLogicGen.ChkBas1A++; //***** niceB = true; goto Lreturn; } } } } } #endregion GeneralLogicGen.ChkBas4++; //***** Lreturn: return(niceB); }