Beispiel #1
0
        public static void DVD(int startI, int startJ, int endI, int endJ)
        {
            PizzaCut maxProb = partition(startI, startJ, endI, endJ); // Get the best position to cut.

            if (maxProb == null)
            {
                return;
            }

            if (maxProb.horizontal)
            {
                DVD(startI, startJ, startI + maxProb.i, endJ);   // Call DVD for the upper slice
                DVD(startI + maxProb.i + 1, startJ, endI, endJ); // Call DVD for the lower slice
            }
            else
            {
                DVD(startI, startJ, endI, startJ + maxProb.i);   // Call DVD for the left slice.
                DVD(startI, startJ + maxProb.i + 1, endI, endJ); // Call DVD for the right slice.
            }
        }
Beispiel #2
0
        public static PizzaCut partition(int startI, int startJ, int endI, int endJ)
        {
            if (startI == endI && startJ == endJ)
            {
                return(null);
            }

            // Check if this slice satisfies the conditions.

            double[] pt = check(startI, startJ, endI, endJ);

            if (pt[1] == 1)
            { // If all conditions are satisfied take the whole slice as a slice.
                Console.WriteLine("SLICE: " + startI + " " + startJ + " " + endI + " " + endJ);
                outputList.Add(startI + " " + startJ + " " + endI + " " + endJ);

                score += Convert.ToInt32(pt[2]);
                slices++;

                return(null);
            }
            else if (pt[1] == 0)
            {
                return(null);
            }


            List <PizzaCut> list = new List <PizzaCut>(); // List that contains all possible cuts, vertical and horizontal.

            double prob;

            // Cut vertical.

            int over = endJ - startJ;

            for (int i = 0; i < over; i++)
            {
                double p1 = check(startI, startJ, endI, startJ + i)[0];   // Probability for the left slice.
                double p2 = check(startI, startJ + i + 1, endI, endJ)[0]; // Probability for the right slice.

                prob = p1 * p2;

                list.Add(new PizzaCut(i, false, prob)); // false indicates that this cut is vertical.
            }

            // Cut horizontal.

            over = endI - startI;

            for (int i = 0; i < over; i++)
            {
                double p1 = check(startI, startJ, startI + i, endJ)[0];   // Probability for the upper slice.
                double p2 = check(startI + i + 1, startJ, endI, endJ)[0]; // Probability for the lower slice.

                prob = p1 * p2;

                list.Add(new PizzaCut(i, true, prob)); // false indicates that this cut is horizontal.
            }

            // Search for the best probability and cut the pizza there.

            PizzaCut maxProb = list[0];

            for (int i = 1; i < list.Count; i++)
            {
                if (list[i].probability > maxProb.probability)
                {
                    maxProb = list[i];
                }
            }

            return(new PizzaCut(maxProb.i, maxProb.horizontal, maxProb.probability));
        }