Пример #1
0
        public OutputFile Solve(InputFile inputFile, CancellationToken cancellationToken)
        {
            var sw = Stopwatch.StartNew();

            _writeLog($"*** Begin solving input file {inputFile}");
            var outputFile = inputFile.GetOutputFile();
            int lineCount = 0, minIngridients = 0, maxCellsPerSlice = 0;
            var dataLines = new List <string>();

            foreach (var inputLine in inputFile.ReadStrings())
            {
                if (lineCount == 0)
                {
                    var parameters = inputLine.Split(' ');
                    var rows       = int.Parse(parameters[0]);
                    var columns    = int.Parse(parameters[1]);
                    minIngridients   = int.Parse(parameters[2]);
                    maxCellsPerSlice = int.Parse(parameters[3]);

                    _pizza = new Pizza(rows, columns);
                    InitPizza();
                    _writeLog(
                        $"Pizza creted, rows: {rows}, columns:{columns}, min ingridients: {minIngridients}, max cells per slice: {maxCellsPerSlice}");
                }
                else
                {
                    dataLines.Add(inputLine);
                }
                lineCount++;
            }

            _pizza.Fill(dataLines);
            _writeLog($"Pizza filled, total lines: {dataLines.Count}");

            var solution = Cut(minIngridients, maxCellsPerSlice, cancellationToken).ToArray();

            outputFile.AppendLineNumbers(solution.Length);
            foreach (var slice in solution)
            {
                outputFile.AppendLineNumbers(slice.R0, slice.C0, slice.R1, slice.C1);
            }

            _writeLog($"** Completed in {sw.ElapsedMilliseconds} ms.");
            _writeLog($"Output written to {outputFile}");
            return(outputFile);
        }
Пример #2
0
        public OutputFile Solve(InputFile inputFile, CancellationToken cancellationToken)
        {
            var outputFile = inputFile.GetOutputFile();
            int c          = 0;
            var model      = new InputModel();
            var numberRide = 0;

            foreach (var value in inputFile.ReadStrings())
            {
                var input = InputParser.Map6(value);
                if (c == 0)
                {
                    model.Rows     = input.Item1;
                    model.Columns  = input.Item2;
                    model.Vechiles = input.Item3;
                    model.Riders   = input.Item4;
                    model.Bonus    = input.Item5;
                    model.Steps    = input.Item6;
                }
                else
                {
                    model.Rides.Add(new Ride()
                    {
                        OrdinalNumber = numberRide++,
                        StartPosition = new Point(input.Item2, input.Item1),
                        FinalPosition = new Point(input.Item4, input.Item3),
                        EarliestStart = input.Item5,
                        LatestFinish  = input.Item6
                    });
                }
                c++;
            }

            var machines = new List <Vehicle>();

            for (var i = 0; i < model.Vechiles; i++)
            {
                machines.Add(new Vehicle());
            }

            throw new NotImplementedException();
        }
Пример #3
0
        public OutputFile Solve(InputFile inputFile, CancellationToken cancellationToken)
        {
            var outputFile = inputFile.GetOutputFile();
            int c          = 0;
            var model      = new InputFileModel();
            var numberRide = 0;

            foreach (var value in inputFile.ReadStrings())
            {
                var input = InputParser.Map6(value);
                if (c == 0)
                {
                    model.Rows     = input.Item1;
                    model.Columns  = input.Item2;
                    model.Vechiles = input.Item3;
                    model.Riders   = input.Item4;
                    model.Bonus    = input.Item5;
                    model.Steps    = input.Item6;
                }
                else
                {
                    model.Rides.Add(new Ride()
                    {
                        Number = numberRide++,
                        start  = new Point()
                        {
                            x = input.Item2, y = input.Item1
                        },
                        stop = new Point()
                        {
                            x = input.Item4, y = input.Item3
                        },
                        earlistStart = input.Item5,
                        latestFinish = input.Item6
                    });
                }
                c++;
            }

            var machines = new List <Machine>();

            for (var i = 0; i < model.Vechiles; i++)
            {
                machines.Add(new Machine()
                {
                    currentPos = new Point(0, 0), CurrentRide = null, IsBusy = false
                });
            }

            var context = new Context()
            {
                Machines   = machines,
                Model      = model,
                OutputFile = outputFile
            };

            StartSolve(context);

            for (var i = 0; i < context.Machines.Count; i++)
            {
                var        contextMachine = context.Machines[i];
                List <int> outputNumbers  = new List <int>();
                outputNumbers.Add(contextMachine.CompletedRides.Count);
                outputNumbers.AddRange(contextMachine.CompletedRides.Select(x => x.Number));
                outputFile.AppendLineNumbers(outputNumbers.ToArray());
            }

            return(outputFile);
        }