예제 #1
0
파일: Game1.cs 프로젝트: nantelope/PCPSover
        //DominoScene dominoScene;

        public Game1()
        {
            graphics              = new GraphicsDeviceManager(this);
            this.IsMouseVisible   = true;
            Content.RootDirectory = "Content";
            //dominoScene = new DominoScene();

            Console.WriteLine("PCPSolver:\n Team Members:\n Chris Dillard\n John Futch");


            // SIMPLE SOLVABLE INSTANCE
            //
            //3 2
            //0 01 110
            //100 00 11
            //
            //

            PCPInstance instance = new PCPInstance();

            /*
             * Pair p = new Pair();
             * p.up= "0";
             * p.down = "100";
             *
             * Pair p2 = new Pair();
             * p2.up= "01";
             * p2.down = "00";
             *
             * Pair p3 = new Pair();
             * p3.up = "110";
             * p3.down = "11";
             *
             * instance.arrPair = new Pair[3] { p, p2, p3 };
             */


            Pair p = new Pair();

            p.up   = "100";
            p.down = "1";

            Pair p2 = new Pair();

            p2.up   = "0";
            p2.down = "100";

            Pair p3 = new Pair();

            p3.up   = "1";
            p3.down = "00";

            instance.arrPair = new Pair[3] {
                p, p2, p3
            };

            instance.Print();

            PCPSolver.SolvePCPInstance(instance, 1);
        }
예제 #2
0
파일: Mask.cs 프로젝트: nantelope/PCPSover
        static public int FindSideMask(PCPInstance instance, PCPInstance reverseInstance, int maskflag)
        {
            int    i, j, k, m, n, t;
            Pair   pair;
            int    ret;
            int    maxlen;
            String longstr, shortstr;
            int    pIntMask;
            int    up = maskflag % 2;

            switch (maskflag)
            {
            case 0: pIntMask = instance.downmask; break;

            case 1: pIntMask = instance.upmask; break;

            case 2: pIntMask = instance.turnover_downmask; break;

            case 3: pIntMask = instance.turnover_upmask; break;

            //default: assert(0);
            default:
                break;
            }

            for (i = 0; i < instance.size; i++)
            {
                pair = instance.arrPair[i];

                if (up == 1)        // up
                {
                    n        = pair.downlen;
                    t        = pair.uplen;
                    longstr  = pair.down;
                    shortstr = pair.up;
                }
                else         // down
                {
                    t        = pair.downlen;
                    n        = pair.uplen;
                    shortstr = pair.down;
                    longstr  = pair.up;
                }

                if (n > t)
                {
                    for (k = 0; k < n - t; k++)
                    {
                        j = n - 1 - k;
                        m = j - t + 1;

                        // they must be the multiple of gcd
                        if (m % instance.gcd != 0 || (n - 1 - j) % instance.gcd != 0)
                        {
                            continue;
                        }



                        if (shortstr == longstr.Substring(m, longstr.Length - m))
                        {
                            continue;
                        }
                        // the tail string in the bottom should possibly lead to the solution
                        if (j < n - 1)
                        {
                            maxlen = n - j - 1 + 10 * instance.offset;
                            Config config = new Config(maxlen);
                            config.ConfigAssign(longstr.Substring(j + 1), n - j - 1, Convert.ToInt32(!Convert.ToBoolean(up)));
                            config.depth = 1;


                            ret = PCPSolver.BeginSolveConfig(instance, config, maxlen, 100);

                            if (ret == -1)
                            {
                                continue;
                            }
                        }
                        else if (maskflag >= 2) // find turnover
                        {
                            continue;
                        }

                        // the head string should be generated, so we use the reverse PCP to parse it
                        maxlen = m + 10 * instance.offset;
                        Config config2 = new Config(maxlen);
                        int    index;


                        char[] str = new char[m];

                        for (index = 0; index < m; index++)
                        {
                            str[index] = longstr[m - index - 1];
                        }

                        String st = new String(str);

                        config2.ConfigAssign(st, m, Convert.ToInt32(!Convert.ToBoolean(up)));

                        config2.depth = 1;

                        ret = PCPSolver.BeginSolveConfig(reverseInstance, config2, maxlen, 100);

                        if (ret == -1)
                        {
                            continue;
                        }
                        else                 // no mask!
                        {
                            pIntMask = 0;
                            return(0);
                        }
                    }
                }
            }

            pIntMask = 1;

            return(1);
        }