public string __chainToStringGNLsub(List <GroupedLink> SolLst, ref string st3)
        {
            string po = $"[{SolLst[0].UGCellsA}]";

            foreach (var LK in SolLst)
            {
                string  ST_LinkNo = "";
                ALSLink ALK       = LK as ALSLink;
                if (ALK != null)
                {
                    ST_LinkNo = $"-#{(ALK.no+1)}ALS<{ALK.ALSbase.ToStringRC()}>#{(ALK.no2+1)}-";
                }
                else
                {
                    string mk = (LK.type == 1)? "=": "-";
                    ST_LinkNo = mk + (LK.no2 + 1) + mk;
                }
                po += $"{ST_LinkNo}[{LK.UGCellsB}]";
            }

            if (po.Contains("ALS") || po.Contains("[<"))
            {
                st3 = "Grouped ";
            }
            return(po);
        }
Exemplo n.º 2
0
        public string GrLKToString()
        {
            try{
                string P = "+", M = "-";
                if (type == 1)
                {
                    P = "-"; M = "+";
                }
                string st = "[";

#if DEBUG
                if (_IDsetB)
                {
                    st += "ID:" + ID + " ";
                }
#endif
                st += (type == 1? "S": "W") + " ";
                if (this is ALSLink)
                {
                    ALSLink A  = this as ALSLink;
                    string  po = "";
                    A.ALSbase.UCellLst.ForEach(p => { po += " r" + (p.r + 1) + "c" + ((p.c) + 1); });
                    st += "(ALS:" + po.ToString_SameHouseComp() + ") ";
                }
                st += UGCellsA.ToString() + "/" + P + (no + 1);
                st += " -> " + UGCellsB.ToString() + "/" + M + (no2 + 1) + "]";
                return(st);
            }
            catch (System.NullReferenceException ex) {
                WriteLine(ex.Message);
            }
            return("null Exception");
        }
        private string _ToGroupedRCSequenceString(Stack <GroupedLink> SolStack, ref string st3)
        {
            if (SolStack.Count == 0)
            {
                return("[rc]:-");
            }
            List <GroupedLink> SolLst = SolStack.ToList();

            SolLst.Reverse();

            string po = $"[{SolLst[0].UGCellsA}]";

            foreach (var LK in SolLst)
            {
                string  ST_LinkNo = "";
                ALSLink ALK       = LK as ALSLink;
                if (ALK != null)
                {
                    ST_LinkNo = $"-#{(ALK.no+1)}ALS<{ALK.ALSbase.ToStringRC()}>#{(ALK.no2+1)}-";
                }
                else
                {
                    string mk = (LK.type == 1)? "=": "-";
                    ST_LinkNo = mk + (LK.no2 + 1) + mk;
                }
                po += $"{ST_LinkNo}[{LK.UGCellsB}]";
            }

            if (po.Contains("ALS") || po.Contains("[<"))
            {
                st3 = "Grouped ";
            }
            return(po);
        }
Exemplo n.º 4
0
        public new int CompareTo(object obj)
        {
            ALSLink Q   = obj as ALSLink;
            int     ret = this.UGCellsA.CompareTo(Q.UGCellsA);

            if (ret != 0)
            {
                return(ret);
            }
            return(this.UGCellsB.CompareTo(Q.UGCellsB));
        }
Exemplo n.º 5
0
        public override bool Equals(object obj)
        {
            ALSLink Q = obj as ALSLink;

            if (Q == null)
            {
                return(true);
            }
//          if( this.tfx!=Q.tfx )  return false;
            if (!this.UGCellsA.Equals(Q.UGCellsA))
            {
                return(false);
            }
            if (!this.UGCellsB.Equals(Q.UGCellsB))
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 6
0
        private void _SetGroupedLink(UALS P, UGrCells GS, UGrCells GD, int tfx)
        {
            ALSLink ALSLK = new ALSLink(P, GS, GD, tfx);

            if (AlsInnerLink == null)
            {
                AlsInnerLink = new List <ALSLink>();
            }
            if (AlsInnerLink.Count > 0)
            {
                int ix = AlsInnerLink.FindIndex(Q => (Q.Equals(ALSLK)));
                if (ix >= 0)
                {
                    return;
                }
            }
            AlsInnerLink.Add(ALSLK);

            //WriteLine( $"ALSLink {GS.GCToString()} -> tfx:{tfx} {GD.GCToString()}" );
        }
        public string _chainToStringGNL(USuperLink GNL_Result, ref string st3)
        {
            string st = "";

            if (GNL_Result == null)
            {
                return(st);
            }

            GroupedLink GLKnxt = GNL_Result.resultGLK;
            //pSprLKsMan.Debug_ChainPrint(GLKnxt);
            var         SolLst = pSprLKsMan.Convert_ChainToList_GNL(GNL_Result);
            GroupedLink GLKorg = SolLst[0];

            {//===================== cells coloring ===========================
                foreach (var LK in SolLst)
                {
                    bool bALK = LK is ALSLink;
                    int  type = (LK is ALSLink)? S: LK.type;//ALSLink, in ALS, is S
                    foreach (var P1 in LK.UGCellsA.Select(p => pBDL[p.rc]))
                    {
                        //WriteLine($"---------- {P1}");
                        int noB = (1 << LK.no);
                        if (!bALK)
                        {
                            P1.SetCellBgColor(SolBkCr);
                        }
                        if (type == S)
                        {
                            P1.SetNoBColor(noB, AttCr2);
                        }
                        else
                        {
                            P1.SetNoBColor(noB, AttCr3);
                        }
                    }

                    if (type == W)
                    {
                        foreach (var P2 in LK.UGCellsB.Select(p => pBDL[p.rc]))
                        {
                            int noB2 = (1 << LK.no);
                            if (!bALK)
                            {
                                P2.SetCellBgColor(SolBkCr);
                            }
                            P2.SetNoBColor(noB2, AttCr);
                        }
                    }
                }

                int cx = 2;
                foreach (var LK in SolLst)      // ALS
                {
                    ALSLink ALK = LK as ALSLink;
                    if (ALK == null)
                    {
                        continue;
                    }
                    Color crG = _ColorsLst[cx++];
                    foreach (var P in ALK.ALSbase.B81.IEGet_rc().Select(rc => pBDL[rc]))
                    {
                        P.SetCellBgColor(crG);
                    }
                }
            }

            {//===================== result report ===========================
                st3 = "";
                int SolType = GNL_Result.contDiscontF;
                if (SolType == 1)
                {
                    st = "Nice Loop(Cont.)";             //<>continuous
                }
                else                                     //<>discontinuous
                {
                    int rc = GLKorg.UGCellsA[0].rc;
                    var P  = pBDL[rc];
                    st = "Nice Loop(Discont.) r" + (rc / 9 + 1) + "c" + (rc % 9 + 1);
                    int dcTyp = GLKorg.type * 10 + GLKnxt.type;
                    switch (dcTyp)
                    {
                    case 11: st += $" is {(GLKorg.no+1)}";     P.SetCellBgColor(SolBkCr2); break;

                    case 12: st += $" is not {(GLKnxt.no+1)}"; P.CancelB = 1 << GLKnxt.no; break;

                    case 21: st += $" is not {(GLKorg.no+1)}"; P.CancelB = 1 << GLKorg.no; break;

                    case 22: st += $" is not {(GLKorg.no+1)}"; P.CancelB = 1 << GLKorg.no; break;
                    }
                }

                string st2 = __chainToStringGNLsub(SolLst, ref st3);
                st         = st3 + st;
                Result     = st;
                ResultLong = st + "\r" + st2;
            }
            return(st);
        }
        private void _GroupedNL_SolResult(GroupedLink LK0, GroupedLink LKnxt, Stack <GroupedLink> SolStack, int SolType)
        {
            string st = "";

            List <GroupedLink> SolLst = SolStack.ToList();

            SolLst.Reverse();
            SolLst.Add(LK0);

            foreach (var LK in SolLst)
            {
                bool bALK = LK is ALSLink;
                int  type = (LK is ALSLink)? S: LK.type;//ALSLink, in ALS, is S
                foreach (var P1 in LK.UGCellsA.Select(p => pBDL[p.rc]))
                {
                    int noB = (1 << LK.no);
                    if (!bALK)
                    {
                        P1.SetCellBgColor(SolBkCr);
                    }
                    if (type == S)
                    {
                        P1.SetNoBColor(noB, AttCr);
                    }
                    else
                    {
                        P1.SetNoBColor(noB, AttCr3);
                    }
                }

                if (type == W)
                {
                    foreach (var P2 in LK.UGCellsB.Select(p => pBDL[p.rc]))
                    {
                        int noB2 = (1 << LK.no);
                        if (!bALK)
                        {
                            P2.SetCellBgColor(SolBkCr);
                        }
                        P2.SetNoBColor(noB2, AttCr);
                    }
                }
            }

            int cx = 2;

            foreach (var LK in SolLst)
            {
                ALSLink ALK = LK as ALSLink;
                if (ALK == null)
                {
                    continue;
                }
                Color crG = _ColorsLst[cx++];
                foreach (var P in ALK.ALSbase.B81.IEGet_rc().Select(rc => pBDL[rc]))
                {
                    P.SetCellBgColor(crG);
                }
            }

            string st3 = "";

            if (SolType == 1)
            {
                st = "Nice Loop(Cont.)";             //<>continuous
            }
            else                                     //<>discontinuous
            {
                int rc = LK0.UGCellsA[0].rc;
                var P  = pBDL[rc];
                st = "Nice Loop(Discont.) r" + (rc / 9 + 1) + "c" + (rc % 9 + 1);
                int dcTyp = LK0.type * 10 + LKnxt.type;
                switch (dcTyp)
                {
                case 11: st += $" is {(LK0.no+1)}";       P.SetCellBgColor(SolBkCr2); break;

                case 12: st += $" is not {(LKnxt.no+1)}"; P.CancelB = 1 << LKnxt.no; break;

                case 21: st += $" is not {(LK0.no+1)}";   P.CancelB = 1 << LK0.no; break;

                case 22: st += $" is not {(LK0.no+1)}";   P.CancelB = 1 << LK0.no; break;
                }
            }

            string st2 = _ToGroupedRCSequenceString(SolStack, ref st3);

            st         = st3 + st;
            Result     = st;
            ResultLong = st + "\r" + st2;
        }
Exemplo n.º 9
0
        public IEnumerable <GroupedLink> IEGet_SuperLink(GroupedLink GLKpre)
        {
            int  SWCtrl = GLKpre.type;
            bool ALSpre = GLKpre is ALSLink;

            if (GLKpre.UGCellsB.Count == 1)
            {
                UCell            U    = GLKpre.UGCellsB[0];
                List <UCellLink> Plst = CeLKMan.CeLK81[U.rc];
                if (Plst != null)
                {
                    foreach (var LK in Plst)
                    {
                        if (ALSpre && LK.type != W)
                        {
                            continue;
                        }
                        GroupedLink GLK = new GroupedLink(LK);
                        if (Check_SuperLinkSequence(GLKpre, GLK))
                        {
                            yield return(GLK);
                        }
                    }
                }
            }

            if (GNPXApp000.GMthdOption["GroupedCells"] == "1")
            {
                foreach (var GP in GLKMan.GrpCeLKLst)
                {
                    if (ALSpre && GP.type != W)
                    {
                        continue;
                    }
                    if (!GLKpre.UGCellsB.EqualsRC(GP.UGCellsA))
                    {
                        continue;
                    }
                    if (GLKpre.no2 != GP.no)
                    {
                        continue;
                    }
                    if (Check_SuperLinkSequence(GLKpre, GP))
                    {
                        yield return(GP);
                    }
                }
            }

            if (GNPXApp000.GMthdOption["ALS"] == "1" && ALSMan.AlsInnerLink != null)
            {
                if (GLKpre.type == W)
                {
                    foreach (var GP in ALSMan.AlsInnerLink.Where(p => (p.ALSbase.Level == 1)))
                    {
                        if (GLKpre.no2 != GP.no)
                        {
                            continue;
                        }
                        if (GLKpre.UGCellsB.Equals(GP.UGCellsA))
                        {
                            yield return(GP);
                        }
                    }
                }
            }

            if (ALSpre)
            {
                ALSLink ALK   = GLKpre as ALSLink;
                int     noB   = 1 << ALK.no2;
                Bit81   BPnoB = new Bit81(pBDL, noB);

                Bit81 BP = BPnoB & ALK.UGCellsB.B81;
                //      ALK.UGCellsB.ForEach(P=>{ if((P.FreeB&noB)>0) BP.BPSet(P.rc); });

                Bit81 UsedCs = GLKpre.UsedCs;
                for (int tfx = 0; tfx < 27; tfx++)
                {
                    Bit81 HS = BPnoB & pHouseCells[tfx];
                    if (!(BP - HS).IsZero())
                    {
                        continue;
                    }
                    if ((HS - BP).IsZero())
                    {
                        continue;
                    }

                    Bit81 NxtBP = HS - BP - UsedCs;
                    if (NxtBP.IsZero())
                    {
                        continue;
                    }

//C                        WriteLine("\n tfx:"+tfx );
//C                        WriteLine( "   BP:"+BP );
//C                        WriteLine( "   HS:"+HS );
//C                        WriteLine( "HS-BP:"+(HS-BP) );
//C                        WriteLine( "NxtBP:"+NxtBP );

                    List <UCell> NxtCs = NxtBP.ToList().ConvertAll(rc => pBDL[rc]);
                    for (int k = 1; k < (1 << NxtCs.Count); k++)
                    {
                        UGrCells NxtGrpdCs = new UGrCells(tfx, ALK.no2);
                        int      kb        = k;
                        for (int n = 0; n < NxtCs.Count; n++)
                        {
                            if ((kb & 1) > 0)
                            {
                                NxtGrpdCs.Add(new UGrCells(NxtCs[n], ALK.no2));
                            }
                            kb >>= 1;
                        }
                        GroupedLink GP = new GroupedLink(GLKpre.UGCellsB, NxtGrpdCs, tfx, W);
//C                        WriteLine( GP );
                        yield return(GP);
                    }
                }
            }
            yield break;
        }