Esempio n. 1
0
        /// <summary>
        /// One simple algorithm
        /// </summary>
        /// <param name="inputObject"></param>
        /// <returns></returns>
        public OutputObject Execute(InputObject inputObject)
        {
            int minCell = 2 * inputObject.MinIngredient;

            // we want to find all rectangle whose area is between mincell and
            List <int[]> allRectangles = SlicingTools.GetAllRectangles(minCell, inputObject.MaxCell);

            // Execute algorithm
            return(SlicingAlgorithm.Execute(inputObject, allRectangles));
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            foreach (string file in inFiles)
            {
                Console.WriteLine(string.Format("Read file : {0}", file));

                InputObject  inputObject  = null;
                OutputObject outputObject = null;

                // Now we want to execute all known algorithm
                List <IAlgorithm> algorithms = new List <IAlgorithm>();
                algorithms.Add(new BasicAlgorithm());
                algorithms.Add(new SortAscendingAlgorithm());
                algorithms.Add(new SortDescendingAlgorithm());

                foreach (IAlgorithm algorithm in algorithms)
                {
                    string fileOutName = file.Split('\\').Last().Split('.').First() + ".out";
                    // Read file an read and put them inside c# object
                    using (var streamReader = new StreamReader(@file))
                    {
                        inputObject = new InputObject(streamReader);
                    }

                    Console.WriteLine(string.Format("Apply algorithm : {0} on this file", algorithm.GetName()));
                    outputObject = algorithm.Execute(inputObject);
                    Console.WriteLine(string.Format("{0} point with this algorithm", SlicingTools.GetNbPoint(outputObject)));

                    if (!Directory.Exists(outPath + algorithm.GetName()))
                    {
                        Directory.CreateDirectory(outPath + algorithm.GetName());
                    }
                    // Write file from c# object
                    using (var streamWriter = new StreamWriter(outPath + algorithm.GetName() + "\\" + fileOutName))
                    {
                        outputObject.Write(streamWriter);
                    }
                }
                Console.WriteLine();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// One possible algorithm to execute. It crosse pizza from top left to bottom right
        /// Result depend of the order of given rectangles
        /// </summary>
        /// <param name="inputObject"></param>
        /// <param name="rectangles"></param>
        /// <returns></returns>
        public static OutputObject Execute(InputObject inputObject, List <int[]> rectangles)
        {
            OutputObject result = new OutputObject();

            // now we cross pizza, we start at the left top
            for (int i = 0; i < inputObject.NbRow; i++)
            {
                for (int j = 0; j < inputObject.NbCol; j++)
                {
                    bool hasOneValidSlice = false;
                    foreach (int[] rectangle in rectangles)
                    {
                        if (SlicingTools.IsValidSlice(i, j, rectangle, inputObject) && !hasOneValidSlice)
                        {
                            hasOneValidSlice = true;
                            for (int x = i; x < i + rectangle[0]; x++)
                            {
                                for (int y = j; y < j + rectangle[1]; y++)
                                {
                                    inputObject.Pizza[x][y] = 'O';
                                }
                            }
                            result.NbSlices++;
                            int[] coordonne = { i, j, i + rectangle[0] - 1, j + rectangle[1] - 1 };
                            result.Slices.Add(coordonne);
                        }
                    }
                    if (!hasOneValidSlice)
                    {
                        inputObject.Pizza[i][j] = 'X';
                    }
                }
            }

            return(result);
        }